Download OpenStreetMap POI data for Brighton & Hove#

This tutorial shows how you can download Points of Interest (POI) data for Brighton and Hove from OpenStreetMap.

import osmnx as ox
import geopandas as gpd
from shapely.geometry import box

Define the area of interest#

Let’s create a GeoDataFrame with Polygon that defines the area of interest for us. We will only collect data from this area.

# Data extent for Brighton
# minx, miny, maxx, maxy
bounds = (-0.49975, 50.73,  0.3469234, 50.98)

# Create a GeoDataFrame
gdf = gpd.GeoDataFrame(geometry=[box(*bounds)], crs="EPSG:4326")

# Plot to map
gdf.explore()
Make this Notebook Trusted to load map: File -> Trust Notebook

Extract information about restaurants#

# Download restaurants using Osmnx
tags = {"amenity": "restaurant"}
restaurants = ox.geometries_from_polygon(gdf.geometry.values[0], tags)

# Use centroid as geometry (we ignore the shape of the building)
restaurants["geometry"] = restaurants.centroid

# Plot to map
restaurants.explore()
/tmp/ipykernel_493210/3658294838.py:6: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  restaurants["geometry"] = restaurants.centroid
Make this Notebook Trusted to load map: File -> Trust Notebook

Extract information about schools#

# Download schools
tags = {"amenity": "school"}
schools = ox.geometries_from_polygon(gdf.geometry.values[0], tags)

# Use centroid as geometry (we ignore the shape of the building)
schools["geometry"] = schools.centroid

# Plot to map
schools.explore()
/tmp/ipykernel_493210/808073114.py:6: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  schools["geometry"] = schools.centroid
Make this Notebook Trusted to load map: File -> Trust Notebook

Extract information about healthcare facilities#

# Download schools
tags = {"amenity": ["clinic", "doctors", "hospital"]}
healthcare = ox.geometries_from_polygon(gdf.geometry.values[0], tags)

# Use centroid as geometry (we ignore the shape of the building)
healthcare["geometry"] = healthcare.centroid

# Plot to map
healthcare.explore()
/tmp/ipykernel_493210/1219259598.py:6: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation.

  healthcare["geometry"] = healthcare.centroid
Make this Notebook Trusted to load map: File -> Trust Notebook

Save data to disk#

Restaurants#

# GeoDataFrame has MultiLevel index - We only want to keep the second one and drop the first 
restaurants["id"] = restaurants.index.droplevel(level=0)

# Restaurants (store only specific columns)
restaurants[["id", "name", "geometry"]].to_file("data/Brighton/Brighton_restaurants.gpkg")

Schools#

# GeoDataFrame has MultiLevel index - We only want to keep the second one and drop the first 
schools["id"] = schools.index.droplevel(level=0)

# Restaurants (store only specific columns)
schools[["id", "name", "geometry"]].to_file("data/Brighton/Brighton_schools.gpkg")

Healthcare facilities#

# GeoDataFrame has MultiLevel index - We only want to keep the second one and drop the first 
healthcare["id"] = healthcare.index.droplevel(level=0)

# Restaurants (store only specific columns)
healthcare[["id", "name", "geometry"]].to_file("data/Brighton/Brighton_healthcare.gpkg")