fix: 测试数据打包进套件 data/,去掉外部输入参数
- 去掉 province/cities 参数,只保留 output_path - GeoJSON 数据放在 data/ 目录,脚本自动读取 - 版本升到 1.0.1 - MEMORY.md / TOOLS.md 补充 platform 发布参数说明 Ref: SuiteHub/agent-profiles#22
This commit is contained in:
@@ -1,60 +1,58 @@
|
||||
#!/usr/bin/env python
|
||||
"""
|
||||
Step 1: GeoJSON → SHP (arcpy)
|
||||
将省界和城市 GeoJSON 文件转换为 Shapefile
|
||||
使用 arcpy 的 JSON To Feature Class 工具
|
||||
从内置 data/ 目录读取 GeoJSON,转为 Shapefile
|
||||
"""
|
||||
import sys
|
||||
import json
|
||||
import os
|
||||
import arcpy
|
||||
|
||||
# 允许覆写输出
|
||||
arcpy.env.overwriteOutput = True
|
||||
|
||||
|
||||
def main():
|
||||
province_path = os.environ.get("PARAM_PROVINCE", "")
|
||||
cities_param = os.environ.get("PARAM_CITIES", "")
|
||||
output_dir = os.environ.get("PARAM_OUTPUT_DIR", r"C:\temp\output\shp")
|
||||
def get_data_dir():
|
||||
"""返回内置 data/ 目录路径(相对脚本位置)"""
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
return os.path.normpath(os.path.join(script_dir, "..", "data"))
|
||||
|
||||
if not province_path:
|
||||
print json.dumps({"error": "缺少 province 参数", "success": False})
|
||||
sys.exit(1)
|
||||
if not cities_param:
|
||||
print json.dumps({"error": "缺少 cities 参数", "success": False})
|
||||
sys.exit(1)
|
||||
|
||||
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)
|
||||
|
||||
# 转换省界
|
||||
print json.dumps({"msg": "转换省界: " + province_path})
|
||||
province_name = os.path.splitext(os.path.basename(province_path))[0]
|
||||
province_shp = os.path.join(output_dir, "province.shp")
|
||||
# GeoJSON → Feature Class → Shapefile
|
||||
arcpy.JSONToFeatures_conversion(province_path, province_shp)
|
||||
print json.dumps({"msg": "省界已转为 SHP: " + province_shp})
|
||||
data_dir = get_data_dir()
|
||||
|
||||
# 数据文件映射
|
||||
geo_files = {
|
||||
"province": "yunnan.geojson",
|
||||
"kunming": "kunming.geojson",
|
||||
"dali": "dali.geojson",
|
||||
"baise": "baise.geojson",
|
||||
}
|
||||
|
||||
# 转换每个城市
|
||||
city_files = [c.strip() for c in cities_param.split(",") if c.strip()]
|
||||
converted = []
|
||||
for cf in city_files:
|
||||
if not os.path.isfile(cf):
|
||||
print json.dumps({"warn": "文件不存在,跳过: " + cf})
|
||||
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": "转换城市: " + cf})
|
||||
base = os.path.splitext(os.path.basename(cf))[0]
|
||||
shp_path = os.path.join(output_dir, base + ".shp")
|
||||
arcpy.JSONToFeatures_conversion(cf, shp_path)
|
||||
converted.append(base)
|
||||
print json.dumps({"msg": "已转换: " + cf + " -> " + shp_path})
|
||||
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,
|
||||
"province_shp": province_shp,
|
||||
"city_count": len(converted),
|
||||
"cities": converted
|
||||
"output_dir": output_dir,
|
||||
"converted": converted
|
||||
}
|
||||
print json.dumps(result)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
name: 云南省界叠加分析(Windows 测试)
|
||||
description: 验证 GIS Actions 4.0 Windows 执行链路的测试套件。将示例 GeoJSON 转为 SHP → 叠加分析(arcpy)→ 输出 Excel
|
||||
version: 1.0.0
|
||||
description: 验证 GIS Actions 4.0 Windows 执行链路的测试套件。内置云南/昆明/大理/百色 GeoJSON 示例数据,开箱即用。
|
||||
version: 1.0.1
|
||||
author: SuiteForge
|
||||
platform: windows
|
||||
slug: test-yunnan-overlay-windows
|
||||
@@ -8,14 +8,6 @@ tags: [测试, 叠加分析, Windows, 云南省]
|
||||
category: 测试验证
|
||||
|
||||
params:
|
||||
province:
|
||||
type: string
|
||||
required: true
|
||||
desc: 省界 GeoJSON 文件路径
|
||||
cities:
|
||||
type: string
|
||||
required: true
|
||||
desc: 待分析城市 GeoJSON 文件路径,多个文件用逗号分隔
|
||||
output_path:
|
||||
type: string
|
||||
required: true
|
||||
@@ -27,8 +19,6 @@ steps:
|
||||
runtime: arcpy
|
||||
script_id: arcpy_convert
|
||||
params:
|
||||
province: $params.province
|
||||
cities: $params.cities
|
||||
output_dir: /tmp/output/shp
|
||||
|
||||
- id: overlay
|
||||
|
||||
Reference in New Issue
Block a user