Free data in R – OSM

We often use data from the OpenStreetMap project in our posts.

Where do we get them from? We get them via R libraries.

Today we will show you how to do that.

We download the osmdata package and install it:

We will download data for a specific area. We will create this area as a vector of geographic coordinates:

From the OSM project we can take all the data or select certain ones. We have to keep in mind that limiting the selection will speed up the download. All available layers can be found at We will choose our area of restaurants. We will do it with this line of code:

, where

opq is a query to OSM

add_osm_feature adds layers containing cuisine related objects key=’cuisine’ to the query.

osmdata_sf writes the results to the class sf

The results are layers with points and polygons:

Display the result on the map using leaflet:


We can also define an area by using the name of the area for which we want to retrieve data:

We retrieve the data, this time delimiting the restaurants that serve pizza, and store it in the class sp:

Display result:


In the next exercises, you can work with data selected for your region of residence, for example. Test the newly learned library.

Leave a Reply

Your email address will not be published.

Translate using Google Translate»
Social media & sharing icons powered by UltimatelySocial

Podoba Ci się nasza strona? Odwiedź nasz profil