将Open Street Maps (OSM) ID列表转换为geojson,以便在folium上绘制,可以通过以下步骤完成:
import requests
import folium
def get_geometry(osm_id):
overpass_url = "https://overpass-api.de/api/interpreter"
overpass_query = f"""
[out:json];
(
node({osm_id});
way({osm_id});
relation({osm_id});
);
out geom;
"""
response = requests.get(overpass_url, params={'data': overpass_query})
data = response.json()
if 'elements' in data:
element = data['elements'][0]
return element['geometry']
else:
return None
def osm_ids_to_geojson(osm_ids):
features = []
for osm_id in osm_ids:
geometry = get_geometry(osm_id)
if geometry:
feature = {
'type': 'Feature',
'geometry': geometry,
'properties': {}
}
features.append(feature)
geojson = {
'type': 'FeatureCollection',
'features': features
}
return geojson
osm_ids = ['123', '456', '789'] # 替换为实际的OSM ID列表
geojson = osm_ids_to_geojson(osm_ids)
map = folium.Map(location=[51.505, -0.09], zoom_start=13)
folium.GeoJson(geojson).add_to(map)
map.save('map.html')
通过以上步骤,您可以将Open Street Maps (OSM) ID列表转换为geojson,并在folium上绘制地图。请注意,以上代码仅供参考,您可能需要根据实际情况进行适当的调整和错误处理。关于腾讯云的相关产品和产品介绍,您可以参考腾讯云官方文档或咨询腾讯云的技术支持人员。
领取专属 10元无门槛券
手把手带您无忧上云