The structure of objects of classes defined in the sf package¶
The data used is available from the website of the Upsala Conflict Data Program as part of the zip file “ged191-RData.zip”.
unzip("ged191-RData.zip")
load("ged191.RData")
class(ged191)
[1] "sf" "data.frame"
# Number of observations
nrow(ged191)
[1] 152616
# Number of variables
ncol(ged191)
[1] 43
The following makes use of the sf package. You may need to install it from
CRAN using the code
install.packages("sf")
if you want to run this on your computer. (The
package is already installed on the notebook container, however.)
library(sf)
Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE
options(width=140)
# Using the adapted 'print()' method from the 'sf' package for an extract of the data.
print(ged191[c(7:8,42)])
Simple feature collection with 152616 features and 3 fieldsGeometry type: POINT
Dimension: XY
Bounding box: xmin: -117.3 ymin: -37.81361 xmax: 155.8967 ymax: 61.25old-style crs object detected; please recreate object with a recent sf::st_crs()
Geodetic CRS: WGS 84
First 10 features:
old-style crs object detected; please recreate object with a recent sf::st_crs()
old-style crs object detected; please recreate object with a recent sf::st_crs()
country_id region low geometry
1 432 Africa 31 POINT (-3.89474 14.94329)
2 490 Africa 100 POINT (30.77583 1.769722)
3 490 Africa 4 POINT (28.87694 -1.651944)
4 750 Asia 2 POINT (74.72549 34.37893)
5 750 Asia 12 POINT (74.16729 34.3726)
6 640 Middle East 13 POINT (40.08422 38.3827)
7 750 Asia 1 POINT (93 26)
8 490 Africa 70 POINT (29.08 -1.25)
9 520 Africa 11 POINT (45.36667 2.066667)
10 483 Africa 2 POINT (17.00055 21.35833)
# Examining the structure of an "sf" object with 'str()'
str(ged191)
Classes 'sf' and 'data.frame': 152616 obs. of 43 variables:
$ year : num 2013 2004 2007 2008 2008 ...
$ side_b : chr "MUJAO" "Civilians" "PARECO" "Kashmir insurgents" ...
$ active_year : num 1 1 0 1 1 1 0 1 1 1 ...
$ side_a : chr "Government of Mali" "FNI" "CNDP" "Government of India" ...
$ priogrid_gid : num 150833 132182 127138 179070 179069 ...
$ conflict_new_id : num 11347 583 4600 364 364 ...
$ country_id : num 432 490 490 750 750 640 750 490 520 483 ...
$ region : chr "Africa" "Africa" "Africa" "Asia" ...
$ source_article : chr "\"Agence France Presse,2013-01-12,French pilot killed in Mali helicopter raid: defence ministry\";\"Agence Fran"| __truncated__ "Reuters 2004-01-23\nS/2004/573" "http://www.monuc.org/News.aspx?newsId=16672" "SATP, 2008-3-5" ...
$ type_of_violence : num 1 3 2 1 1 1 3 1 1 1 ...
$ date_prec : num 2 2 2 2 2 2 1 2 2 2 ...
$ source_headline : chr "French pilot killed in Mali helicopter raid: defence ministry;Mali town counts dead after French strikes on Islamists;French gu "" "" "" ...
$ conflict_name : chr "Mali: Government" "FNI - Civilians" "CNDP - PARECO" "India: Kashmir" ...
$ dyad_name : chr "Government of Mali - MUJAO" "FNI - Civilians" "CNDP - PARECO" "Government of India - Kashmir insurgents" ...
$ event_clarity : num 1 1 1 1 1 1 1 1 1 1 ...
$ where_coordinates: chr "Konna town" "Gobu village" "Ngungu village" "Chithi Bandi village" ...
$ date_end : chr "2013/01/12" "2004/01/16" "2007/12/18" "2008/03/05" ...
$ side_b_new_id : num 1161 1 896 325 325 ...
$ dyad_new_id : num 12571 1050 5210 792 792 ...
$ high : num 50 200 4 2 12 30 1 80 11 72 ...
$ source_office : chr "Agence France Presse;Agence France Presse;Agence France Presse;Reuters News;Agence France Presse;Agence France "| __truncated__ "" "" "" ...
$ gwnob : chr NA NA NA NA ...
$ deaths_civilians : num 3 200 4 0 0 0 1 0 0 0 ...
$ best : num 31 200 4 2 12 13 1 80 11 2 ...
$ number_of_sources: num 7 -1 -1 -1 -1 -1 -1 8 -1 -1 ...
$ source_date : chr "2013-01-12;2013-01-28;2013-01-12;2013-01-12;2013-01-15;2013-01-12;2013-01-30" "" "" "" ...
$ longitude : num -3.89 30.78 28.88 74.73 74.17 ...
$ where_prec : num 1 1 2 1 3 3 4 1 1 1 ...
$ side_a_new_id : num 72 606 426 141 141 115 326 89 95 87 ...
$ id : num 67972 23385 24255 82612 82645 ...
$ source_original : chr "French Defence Minister Jean-Yves Le Drian; residents" "local official" "" "SATP" ...
$ adm_1 : chr "Mopti region" "Ituri province" "Nord Kivu province" "Jammu and Kashmir State" ...
$ gwnoa : chr "432" NA NA "750" ...
$ country : chr "Mali" "DR Congo (Zaire)" "DR Congo (Zaire)" "India" ...
$ adm_2 : chr "Mopti cercle" "Djugu territory" "Masisi territory" "Bandipore district" ...
$ latitude : num 14.94 1.77 -1.65 34.38 34.37 ...
$ geom_wkt : chr "POINT (-3.894740 14.943290)" "POINT (30.775833 1.769722)" "POINT (28.876944 -1.651944)" "POINT (74.725490 34.378934)" ...
$ date_start : chr "2013/01/11" "2004/01/14" "2007/12/13" "2008/03/04" ...
$ deaths_a : num 12 0 0 0 1 0 0 0 0 0 ...
$ deaths_b : num 16 0 0 2 11 13 0 0 0 2 ...
$ deaths_unknown : num 0 0 0 0 0 0 0 80 11 0 ...
$ low : num 31 100 4 2 12 13 1 70 11 2 ...
$ geometry :sfc_POINT of length 152616; first list element: 'XY' num -3.89 14.94
- attr(*, "sf_column")= chr "geometry"
# Obtaining the geometry contained in 'ged191'
gged191 <- st_geometry(ged191)
gged191
old-style crs object detected; please recreate object with a recent sf::st_crs()
POINT (-3.89474 14.94329)
POINT (30.77583 1.769722)
POINT (28.87694 -1.651944)
POINT (74.72549 34.37893)
POINT (74.16729 34.3726)
Geometry set for 152616 features
Geometry type: POINT
Dimension: XY
Bounding box: xmin: -117.3 ymin: -37.81361 xmax: 155.8967 ymax: 61.25
Geodetic CRS: WGS 84
First 5 geometries:
# Accessing an individual shape
gged191[[1]]
POINT (-3.89474 14.94329)
# The class of a shape object
class(gged191[[1]])
[1] "XY" "POINT" "sfg"
- R file: spatial-datastructures-sf.R
- Rmarkdown file: spatial-datastructures-sf.Rmd
- Jupyter notebook file: spatial-datastructures-sf.ipynb
- Interactive version of the Jupyter notebook (shuts down after 60s):
- Interactive version of the Jupyter notebook (sign in required):