OSM Features Within a Distance of Point Using OSMnx Feature Module
Below are some approaches by which we can find OSM features within a distance of point using OSMnx feature module in Python:
Find the Park Details (under Leisure) From the Open Street Map
Here, we get the park details within 1000 m of a point. In the below code, ‘leisure’ is the main tag (key) and ‘park’ is the subtag (value). The code as follows:
import osmnx as ox
# latitude-longitude point
center_point = (33.299896, -111.831638)
# osm tag
tags = {"leisure": "park"}
# retrieve feature from point
gdf = ox.features_from_point(center_point, tags, dist=1000)
# list first 5 rows from geodataframe
gdf.head(5)
Output
Let’s list all the available feauters (columns) using geodataframe info() method.
gdf.info()
Output
<class 'geopandas.geodataframe.GeoDataFrame'>
MultiIndex: 15 entries, ('way', 493099632) to ('way', 1125075333)
Data columns (total 17 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 nodes 15 non-null object
1 leisure 15 non-null object
2 name 5 non-null object
3 operator 2 non-null object
4 operator:type 2 non-null object
5 operator:wikidata 2 non-null object
6 geometry 15 non-null geometry
7 addr:city 2 non-null object
8 addr:housenumber 2 non-null object
9 addr:postcode 2 non-null object
10 addr:state 2 non-null object
11 addr:street 2 non-null object
12 description 1 non-null object
13 source 2 non-null object
14 wikidata 2 non-null object
15 website 1 non-null object
16 gnis:feature_id 1 non-null object
dtypes: geometry(1), object(16)
memory usage: 2.9+ KB
Plotting the OSM Features Using plot_footprints() Method
In this step, we will plot the OSM features using plot_footprints() method by passing the geodataframe inside it.
fig, ax = ox.plot_footprints(gdf, figsize=(3, 3))
Output
We can plot it on a map by using the explore() method from geodataframe.
gdf.explore()
Output
Find the Leisure Details From the Open Street Map
Apart from ‘park’ there are many other subtags under ‘leisure’ key such as swimming_area, sports_center, garden etc. To get the entire features under leisure key, we just need to mention the tag as
tags = {“leisure”: True}
Let’s look at the below code:
import osmnx as ox
center_point = (33.299896, -111.831638)
tags = {"leisure": True}
# feature from point
gdf = ox.features_from_point(center_point, tags, dist=1000)
# display it on map
gdf.explore()
Output:
Get Multiple Map Features from Open Street Map
Let’s try multiple tags. We can try the below tag
tags = {‘historic’:True,
‘natural’:[‘grassland’,’tree_row’],
‘landuse’:’religious’}
In the below code, it lists the entire historic details since we set ‘historic’ tag as true; In case of ‘natural’ tag, OSMnx fetches details based on ‘grassland’ and ‘tree_row’ subtags. Similary the ‘religious’ subtag details from ‘landuse’ tag.
import osmnx as ox
# latitude-longitude point
center_point = (33.299896, -111.831638)
# osm tag
tags = {'historic': True,
'natural': ['grassland', 'tree_row'],
'landuse': 'religious'}
# retrieve features from point
gdf = ox.features_from_point(center_point, tags, dist=1000)
# display specific columns from geodataframe
gdf[['geometry', 'name', 'historic', 'landuse', 'religion', 'natural']]
Output:
Get OSM Features Within a Distance of a Point Using Python OSMnx Feature Module
In this article, we will see how we can get open street map features within a distance of a point (latitude-longitude) using the OSMnx feature module in Python.
Contact Us