Importing geographical data from OpenStreetMap

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.)

Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0

The file used here was extracted by hand from It is available from here.

Driver: OSM
Available layers:
        layer_name       geometry_type features fields
1           points               Point       NA     10
2            lines         Line String       NA      9
3 multilinestrings   Multi Line String       NA      4
4    multipolygons       Multi Polygon       NA     25
5  other_relations Geometry Collection       NA      4

stpauls_lines <- st_read("stpauls.osm",layer="lines")
Reading layer `lines' from data source `/home/elff/webdevel/sphinx/' using driver `OSM'
Simple feature collection with 130 features and 9 fields
geometry type:  LINESTRING
dimension:      XY
bbox:           xmin: -0.1004085 ymin: 51.51318 xmax: -0.0970669 ymax: 51.51434
CRS:            4326

stpauls_polygons <- st_read("stpauls.osm",layer="multipolygons")
Reading layer `multipolygons' from data source `/home/elff/webdevel/sphinx/' using driver `OSM'
Simple feature collection with 11 features and 25 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: -0.1048984 ymin: 51.50898 xmax: -0.0842498 ymax: 51.51706
CRS:            4326

# Plotting the polygons ...
# and adding the lines

Downloadable R script and interactive version


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


For more information about Jupyter see The Jupyter notebooks make use of the IRKernel package.


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


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 for more information.


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


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