Fastest Way to get City Data

Piotr Zakrzewski
plotwise
Published in
3 min readNov 26, 2021

--

At Plotwise we rely heavily on the Open Street Maps (OSM). We are interested in streets (ways in OSM parlance) as we are in the business of route planning. I asked myself a question: what kind of data is publicly available for the city I live in: The Hague, and how difficult would it be to query and visualize it?

It turns out OSM has a lot of data other than just streets, as an avid foodie I got particularly excited by locations of restaurants. If I were to plot where they all are (is it really just the center?) how much work would it be?

Open Street Maps is an amazing repository of freely accessible geography and urban information. The most accessible way to extract this data is the overpass API, which I am going to use for purpose of this post. If you need a more general into into OSM and the Overpass API head to this blog post. But in short the Overpass API is a simple interface to OSM that focuses on read-only access, as opposed to the main OSM API which also supports editing.

OSM has a notion of tags, they are used to enrich location with metadata. There are many tag keys that are in active use, in our case the one we are looking for is called “amenities” and the value that corresponds to eateries is “restaurants”. Have a look at the query I came up with to get all the restaurants OSM is aware of from the area of The Hague:

Above is about the simplest way to get this data without any wrapper lib, it requires getting acquainted with OSM query DSL however. Writing OSM queries is still fine for simple cases, there are however libs that make it easier for you and abstract away the unfamiliar DSL into a set easier to work with api calls. Probably the most widely used one is OSMnx, a Python library that wraps the overpass API calls in a pythonic interface. Lets see how the same query would look like when using this lib.

Simpler, and like promised: without involving the OSM query DSL.

This is how it looks like when visualized with brilliant Kepler.gl

From the visualization above I can’t quite tell if there are some unexpected clusters of restaurants yet. I will need to visualize it differently and overlay it with district boundaries. Other than that I am curious how comprehensive and up to date the OSM data on my area is? The total of 683 restaurant entries seems quite low, TripAdvisor lists more than 1000 entries! Good idea for a follow up blog post!

Conclusion

If you need GIS data, OSM is often a very good starting point, OSMnx in turn is the go-to library for accessing it, especially if you are already using python.

If you are interested in solving GIS, logistic and optimization challenges with tech have a look at our job openings.

--

--