Retrieving OpenStreetMap Data Using OSMNX, a Python Package.

Retrieving OpenStreetMap Data Using OSMNX, a Python Package.

Retrieving OpenStreetMap Data Using OSMNX, a Python Package. .A guide on how to access the OpenStreetMap database with Python using Google Colab.

If you want to retrieve Geospatial data from OpenStreetMap (OSM), you can download it, but that takes time and storage. Without leaving your development environment (Jupyter Notebooks), you can access and retrieve OpenStreetMap data. Imagine you are doing analysis and want to find out how many recreational facility or restaurants are in your interested area.

In this tutorial, we learn to retrieve OpenStreetMap data using OSMNX, a python package.

OSMnx is a Python package that lets you download spatial geometries and model, project, visualize, and analyze street networks and other spatial data from OpenStreetMap’s API

In the next three sections, we retrieve three different kinds of data from OpenStreetMap: Cafes as points of interest, buildings, and street networks. We also explore Geospatial data visualisation with Folium.


We first create a variable to hold our area of interest. Feel free to explore any other location you would like, but I use Liverpool city in this tutorial ( Note the larger your area, the longer the computation takes.)

place = “Liverpool, United Kingdom”
graph = ox.graph_from_place(place, network_type=’drive’)

With the above two lines of code, OSMnx allows us to retrieve the street networks of the city quickly. The result is a Networkx class, and we convert it to Geopandas to further process the data. Let us see how we can turn it to Geopandas Geodataframe. OSMnx comes with “graph_to_gdf” function which can easily do that:

nodes, streets = ox.graph_to_gdfs(graph)

Now, if we look at the data, it is converted to the familiar form of a pandas data frame with extra capability for Geographic data handling.

Retrieved streets

You can process the retrieved data with any tool of your choice (Pandas in our case) or visualize your data with any of the Python libraries. Let us say we want to get the bar chart of street types. The following process is just pure pandas functionality with seaborn data visualisation.

street_types = pd.DataFrame(edges["highway"].apply(pd.Series)[0].value_counts().reset_index())
street_types.columns = ["type", "count"]
fig, ax = plt.subplots(figsize=(12,10))
sns.barplot(y="type", x="count", data=street_types, ax=ax)

Here is the output bar chart plot for the data. Residential streets have the highest frequency in this dataset.

Bar chart — Street types

We can also use maps to visualise the street data by using any of your favourite Geospatial visualisation tool in Python. I use here Folium.

style = {‘color’: ‘#F7DC6F’, ‘weight’:’1'}
m = folium.Map([-2.914018, 53.366925],
tiles=”CartoDb dark_matter”)
folium.GeoJson(edges.sample(), style_function=lambda x: style).add_to(m)“edges.html”)

The output is this beautiful map of all streets in Liverpool. No need to download data, upload it and read it with Pandas.

Streets Visualized in Folium

In the next section, we retrieve all buildings available in OpenStreetMap data in Liverpool.

Building Footprints

To retrieve building footprints, we use “footprints_from_place” functionality from OSMnx. We need to pass the name of the place.

buildings = ox.footprints_from_place(place)

The building dataset has 27329 rows and 185 columns ( Note this might change as OSM users update any feature in this area). Let us see a subset of the buildings dataset we retrieved.

cols = [‘amenity’,’building’, ‘name’, ‘tourism’]

Building table

We can also map the buildings. Due to the larger dataset, Folium might not correctly display it in the notebook, but you can save it and open it in a browser.

style_buildings = {‘color’:’#6C3483 ‘, ‘fillColor’: ‘#6C3483 ‘, ‘weight’:’1', ‘fillOpacity’ : 1}
m = folium.Map([ 57.70958, 11.96687],
tiles=”Stamen Toner”)
folium.GeoJson(buildings[:1000], style_function=lambda x: style_buildings).add_to(m)

A subset of Building footprints in Liverpool.

Points of Interest (Cafes)

We can also access and retrieve some other point-based datasets from OpenStreetMap dataset. OSMnx has also ox.pois_from_place() Functionality where you can pass what variable you are interested in the amenity parameter. The list of available amenities is available from OpenStreetMap Wiki.

In this example, we retrieve the cafes in Liverpool.

cafe = ox.pois_from_place(place, amenities=[“cafe”])

Here is a subset of the cafe dataset, where we have a name, wheelchair availability and opening hours columns. Some of the columns have no data, though.

Finally, let us plot these cafes on a map.

cafe_points = cafe[cafe.geom_type == “Point”]
m = folium.Map([53.366925, -2.914018], zoom_start=10, tiles=”CartoDb dark_matter”)
locs = zip(cafe_points.geometry.y, cafe_points.geometry.x)
#folium.GeoJson(buildings, style_function=lambda x: style_buildings).add_to(m)
for location in locs:
color = “#F4F6F7”, radius=2).add_to(m)“cafes.html”)

Below is the map of all cafes available in OpenStreetMap database in Liverpool.

Cafes in Liverpool

Retrieving the OSM data can be incorporated with any other data analysis or visualisation project of yours. Experiment with any other place of your interest. Please also know that you can contribute OpenStreetMap data if you find your area of interest does not have enough data.


In this tutorial, we retrieved OpenStreetMap data using OSMnx and also processed it with Pandas and Geopandas. We also have seen how to visualise Geospatial data with Folium.

Guide to Python Programming Language

Guide to Python Programming Language

Guide to Python Programming Language

The course will lead you from beginning level to advance in Python Programming Language. You do not need any prior knowledge on Python or any programming language or even programming to join the course and become an expert on the topic.

The course is begin continuously developing by adding lectures regularly.

Please see the Promo and free sample video to get to know more.

Hope you will enjoy it.

Basic knowledge
An Enthusiast Mind
A Computer
Basic Knowledge To Use Computer
Internet Connection
What will you learn
Will Be Expert On Python Programming Language
Build Application On Python Programming Language

Python Programming Tutorials For Beginners

Python Programming Tutorials For Beginners

Python Programming Tutorials For Beginners

Hello and welcome to brand new series of wiredwiki. In this series i will teach you guys all you need to know about python. This series is designed for beginners but that doesn't means that i will not talk about the advanced stuff as well.

As you may all know by now that my approach of teaching is very simple and straightforward.In this series i will be talking about the all the things you need to know to jump start you python programming skills. This series is designed for noobs who are totally new to programming, so if you don't know any thing about

programming than this is the way to go guys Here is the links to all the videos that i will upload in this whole series.

In this video i will talk about all the basic introduction you need to know about python, which python version to choose, how to install python, how to get around with the interface, how to code your first program. Than we will talk about operators, expressions, numbers, strings, boo leans, lists, dictionaries, tuples and than inputs in python. With

Lots of exercises and more fun stuff, let's get started.

Download free Exercise files.


Who is the target audience?

First time Python programmers
Students and Teachers
IT pros who want to learn to code
Aspiring data scientists who want to add Python to their tool arsenal
Basic knowledge
Students should be comfortable working in the PC or Mac operating system
What will you learn
know basic programming concept and skill
build 6 text-based application using python
be able to learn other programming languages
be able to build sophisticated system using python in the future

To know more:

Learn Python Programming

Learn Python Programming

Learn Python Programming

Learn Python Programming

Learn Python Programming and increase your python programming skills with Coder Kovid.

Python is the highest growing programming language in this era. You can use Python to do everything like, web development, software development, cognitive development, machine learning, artificial intelligence, etc. You should learn python programming and increase your skills of programming.

In this course of learn python programming you don't need any prior programming knowledge. Every beginner can start with.

Basic knowledge
No prior knowledge needed to learn this course
What will you learn
Write Basic Syntax of Python Programming
Create Basic Real World Application
Program in a fluent manner
Get Familiar in Programming Environment