#!/usr/bin/env python """ Step 1: GeoJSON → SHP (arcpy) 从内置 data/ 目录读取 GeoJSON,转为 Shapefile """ import sys import json import os import arcpy arcpy.env.overwriteOutput = True def get_data_dir(): """返回内置 data/ 目录路径(相对脚本位置)""" script_dir = os.path.dirname(os.path.abspath(__file__)) return os.path.normpath(os.path.join(script_dir, "..", "data")) def main(): output_dir = os.environ.get("PARAM_OUTPUT_DIR", r"C:\temp\output\shp") if not os.path.isdir(output_dir): os.makedirs(output_dir) data_dir = get_data_dir() # 数据文件映射 geo_files = { "province": "yunnan.geojson", "kunming": "kunming.geojson", "dali": "dali.geojson", "baise": "baise.geojson", } converted = [] for name, filename in geo_files.items(): filepath = os.path.join(data_dir, filename) if not os.path.isfile(filepath): print json.dumps({"warn": u"内置数据文件不存在,跳过: " + filepath}) continue print json.dumps({"msg": u"读取内置数据: " + filename}) shp_path = os.path.join(output_dir, name + ".shp") arcpy.JSONToFeatures_conversion(filepath, shp_path) converted.append(name) print json.dumps({"msg": u"已转换: " + filename + u" → " + shp_path}) if not converted: print json.dumps({"error": u"未找到任何内置 GeoJSON 数据", "success": False}) sys.exit(1) result = { "success": True, "output_dir": output_dir, "converted": converted } print json.dumps(result) if __name__ == "__main__": main()