Properties of spatial objects¶
The following code makes use of two packages: - the sf package, which is available from https://cran.r-project.org/package=sf - the units package, which is available from https://cran.r-project.org/package=units To run the code of this notebook you can install the packages by install.packages(c("sf","units"))
. However, they are already installed in the container on which this example is run.
library(sf)
Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
The files “south-america-1990.RData” and “three-countries.RData” were created in a previous example.
load("south-america-1990.RData")
load("three-countries.RData")
st_area(Brazil)
8.472314e+12 [m^2]
in_km2 <- function(x) units::set_units(x,"km^2")
in_km2(st_area(Brazil))
8472314 [km^2]
in_km2(st_area(SthAmCountries))
Units: [km^2]
[1] 210585.6 144986.2 910860.6 2780991.8 1086612.6 8472314.3 744390.5
[8] 255309.8 398803.1 1290857.6 177861.7 1135173.0
structure(in_km2(st_area(SthAmCountries)),
names=as.character(SthAmCountries$CNTRY_NAME))
Units: [km^2]
Guyana Suriname Venezuela Argentina Bolivia Brazil Chile Ecuador
210585.6 144986.2 910860.6 2780991.8 1086612.6 8472314.3 744390.5 255309.8
Paraguay Peru Uruguay Colombia
398803.1 1290857.6 177861.7 1135173.0
st_distance(Brasilia,Bogota)
Units: [m]
[,1]
[1,] 3663768
st_distance(Chile,Bogota)
Units: [m]
[,1]
[1,] 2496612
# This takes a while, because R needs to figure out which points of the borders are the closest to one another
st_distance(Chile,Colombia)
Units: [m]
[,1]
[1,] 1468577
in_km <- function(x) units::set_units(x,"km")
in_km(st_distance(Brasilia,Bogota))
Units: [km]
[,1]
[1,] 3663.768
in_km(st_distance(ThreeCapitals))
Units: [km]
[,1] [,2] [,3]
[1,] 0.000 3014.942 3663.768
[2,] 3014.942 0.000 4232.052
[3,] 3663.768 4232.052 0.000
Downloadable R script and interactive version
- R Script: spatial-properties.R
- Interactive version (shuts down after 60s):
- Interactive version (sign in required):
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.