OpenStreetMap - 从选定的国家/地区提取城市和行政边界

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

如何导出包含所选城市坐标的城市列表 国家,以及地区和其他行政边界的列表?

openstreetmap
1个回答
0
投票

您可以使用

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

© www.soinside.com 2019 - 2024. All rights reserved.