Files
gis-actions/suites/test-windows/scripts/arcpy_convert.py
T
SuiteForge 52858c151b fix: arcpy scripts 添加 encoding 声明 (#2)
根据 Mercator 用户交流平台话题 #2 的要求:
- arcpy_convert.py: 添加 # -*- coding: utf-8 -*-
- arcpy_overlay.py: 添加 # -*- coding: utf-8 -*-
- workflow.yaml: version 1.0.3 → 1.0.4

原因:arcpy 运行在 Python 2.7 环境,默认 ASCII 编码,
含中文注释/字符串的脚本需要显式声明 UTF-8 编码。
2026-07-22 21:28:10 +08:00

63 lines
1.7 KiB
Python

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
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()