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.7.1, GDAL 2.4.0, PROJ 5.2.0


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 fields
geometry type:  POINT
dimension:      XY
bbox:           xmin: -117.3 ymin: -37.81361 xmax: 155.8967 ymax: 61.25
CRS:            EPSG:4326
First 10 features:
   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 Isl"| __truncated__ "" "" "" ...
 $ 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
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
bbox:           xmin: -117.3 ymin: -37.81361 xmax: 155.8967 ymax: 61.25
CRS:            EPSG:4326
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"

Downloadable R script and interactive version

Explanation

The link with the “jupyterhub” icon directs you to an interactive Jupyter1 notebook, which runs inside a Docker container2. There are two variants of the interative notebook. One shuts down after 60 seconds and does not require a sign it. The other requires sign in using your ORCID3 credentials, yet shuts down only after 24 hours. (There is no guarantee that such a container persists that long, it may be shut down earlier for maintenance purposes.) After shutdown all data within the container will be reset, i.e. all files created by the user will be deleted.4

Above you see a rendered version of the Jupyter notebook.5

1

For more information about Jupyter see http://jupyter.org. The Jupyter notebooks make use of the IRKernel package.

2

For more information about Docker see https://docs.docker.com/. The container images were created with repo2docker, while containers are run with docker spawner.

3

ORCID is a free service for the authentication of researchers. It also allows to showcase publications and contributions to the academic community such as peer review.. See https://info.orcid.org/what-is-orcid/ for more information.

4

The Jupyter notebooks come with NO WARRANTY whatsoever. They are provided for educational and illustrative purposes only. Do not use them for production work.

5

The notebook is rendered with the help of the nbsphinx extension.