要将ArcGIS JSON转换为GeoJSON,可以使用Python中的arcpy
库和json
库来实现。以下是一个示例代码:
import arcpy
import json
# 设置输入和输出路径
input_json = "path_to_input_json.json"
output_geojson = "path_to_output_geojson.geojson"
# 读取ArcGIS JSON文件
with open(input_json) as f:
arcgis_json = json.load(f)
# 创建一个空的GeoJSON特征集对象
geojson = {
"type": "FeatureCollection",
"features": []
}
# 遍历ArcGIS JSON中的每个要素
for feature in arcgis_json["features"]:
# 创建一个空的GeoJSON要素对象
geojson_feature = {
"type": "Feature",
"properties": feature["attributes"],
"geometry": feature["geometry"]
}
# 将要素添加到GeoJSON特征集中
geojson["features"].append(geojson_feature)
# 将GeoJSON写入输出文件
with open(output_geojson, "w") as f:
json.dump(geojson, f)
请注意,上述代码假设已安装了ArcGIS Desktop,并且可以使用arcpy
库。此外,需要将path_to_input_json.json
替换为实际的ArcGIS JSON文件路径,并将path_to_output_geojson.geojson
替换为希望保存GeoJSON的文件路径。