以下是将 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 文件的路径。

Python 将 Excel 转换为 GeoJSON 文件 - 代码示例

原文地址: https://www.cveoy.top/t/topic/ogbq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录