Querying POIS from OSM using Python

41 views Asked by At

I want to query POIS from OSM and plot the result by folium. There is a problem with the tags I am passing them. code

# The bounding box
north = 30.910093 
south = 25.00042 
east = -79.450636 
west = -85.855045

tags = {"amenity": 'school'}
mypois = ox.features.features_from_bbox(north, south, east, west, tags) # the table
print(len(mypois))
mypois.head(5)

# pick the fields of interest
mypois = mypois[["amenity", "name", "geometry"]]

# create a geodataframe in a specific CRS and save the result into a GeoJson file
gdf = geopandas.GeoDataFrame(mypois, crs="EPSG:4326")
gdf.set_geometry('geometry', crs={'init': 'epsg:4326'})
gdf.to_file('schools.geojson', driver='GeoJSON')

import folium

# create a map centered in specific lat lon, with a medium zoom and a map base
mymap = folium.Map([28.064443537329, -81.5057858485094],zoom_start=6.5,tiles='cartodbpositron')

# add latlon coordinates to the map
folium.LatLngPopup().add_to(mymap)

# add the previously saved GeoJson to the map
myGeoJson = 'schools.geojson'
folium.GeoJson(myGeoJson).add_to(mymap)

# save and display the map
mymap.save("FloridaSchools.html")

mymap

but there is a error :

file ~/.local/lib/python3.10/site-packages/osmnx/_overpass.py:247, in _create_overpass_query(polygon_coord_str, tags)
    245 err_msg = "tags must be a dict with values of bool, str, or list of str"
    246 if not isinstance(tags, dict):  # pragma: no cover
--> 247     raise TypeError(err_msg)
    249 tags_dict = {}
    250 for key, value in tags.items():

**TypeError: tags must be a dict with values of bool, str, or list of str**

this is the post https://medium.com/@jrballesteros/querying-pois-from-osm-using-python-41453922d713

I tried {"amenity":True, "building":'school'} the error persists

1

There are 1 answers

0
gboeing On

I'm guessing what OSMnx version you're using (1.9.x?) because you didn't provide that info. You are passing the tags argument to the bbox parameter positionally. See the docs.

import osmnx as ox
bbox = (26, 25.5, -79.5, -80)
tags = {"amenity": "school"}
gdf = ox.features.features_from_bbox(bbox=bbox, tags=tags)  # works fine