python将excel转为geojson文件输出代码
以下是将Excel转换为GeoJSON文件的Python代码:
import pandas as pd
import json
# 读取Excel文件
excel_file = pd.read_excel('path/to/excel/file.xlsx')
# 转换为GeoJSON格式
features = []
for index, row in excel_file.iterrows():
feature = {
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [row['Longitude'], row['Latitude']]
},
'properties': {
'name': row['Name'],
'description': row['Description']
}
}
features.append(feature)
geojson = {
'type': 'FeatureCollection',
'features': features
}
# 输出为GeoJSON文件
with open('path/to/geojson/file.geojson', 'w') as f:
json.dump(geojson, f)
其中,path/to/excel/file.xlsx是Excel文件的路径,Longitude和Latitude是Excel表格中的经度和纬度列名,Name和Description是Excel表格中的要素名称和描述列名,path/to/geojson/file.geojson是输出的GeoJSON文件的路径
原文地址: https://www.cveoy.top/t/topic/frHl 著作权归作者所有。请勿转载和采集!