使用Python从OSM查询POIS

问题描述 投票:0回答:1

我想从OSM查询POIS并通过folium绘制结果。 我传递的标签有问题。 代码

# 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

但是有一个错误:

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**

这是帖子 https://medium.com/@jrballesteros/querying-pois-from-osm-using-python-41453922d713

我试过了

{"amenity":True, "building":'school'}
错误仍然存在

python-3.x folium osmnx
1个回答
0
投票

我猜测您正在使用哪个 OSMnx 版本(

1.9.x
?),因为您没有提供该信息。您将
tags
参数按位置传递给
bbox
参数。请参阅文档

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
© www.soinside.com 2019 - 2024. All rights reserved.