如何导出包含所选城市坐标的城市列表 国家,以及地区和其他行政边界的列表?
您可以使用
osmnx
模块来提取您想要的数据:
pip install osmnx
import osmnx as ox
# Specify the name of the country or city (e.g., "France" or "Paris, France")
place_name = "France" # Replace with your desired country or city name
# Fetch administrative boundaries and other places from OpenStreetMap
graph = ox.graph_from_place(place_name, network_type='all', which_result=1)
# Get a GeoDataFrame of all cities
cities = ox.geometries_from_place(place_name, tags={'place': ['city', 'town', 'village', 'hamlet']})
# Get a GeoDataFrame of administrative boundaries
admin_boundaries = ox.geometries_from_place(place_name, tags={'boundary': 'administrative'})
# Export the data to CSV files
cities.to_csv('cities.csv')
admin_boundaries.to_csv('admin_boundaries.csv')
输出将保存在
csv
文件中。
您可以从这里的
osmnx
文档中获得更多想法:https://osmnx.readthedocs.io/en/stable/index.html