07a9c3f6dd
- 去掉 province/cities 参数,只保留 output_path - GeoJSON 数据放在 data/ 目录,脚本自动读取 - 版本升到 1.0.1 - MEMORY.md / TOOLS.md 补充 platform 发布参数说明 Ref: SuiteHub/agent-profiles#22
59 lines
1.6 KiB
Python
59 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Step 1: GeoJSON → SHP
|
|
从内置 data/ 目录读取 GeoJSON,转为 Shapefile
|
|
"""
|
|
import sys
|
|
import json
|
|
import os
|
|
import geopandas as gpd
|
|
|
|
|
|
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", "/tmp/output/shp")
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
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": f"内置数据文件不存在,跳过: {filepath}"}))
|
|
continue
|
|
print(json.dumps({"msg": f"读取内置数据: {filename}"}))
|
|
gdf = gpd.read_file(filepath)
|
|
shp_path = os.path.join(output_dir, f"{name}.shp")
|
|
gdf.to_file(shp_path, driver="ESRI Shapefile")
|
|
converted.append(name)
|
|
print(json.dumps({"msg": f"已转换: {filename} → {shp_path}", "count": len(gdf)}))
|
|
|
|
if not converted:
|
|
print(json.dumps({"error": "未找到任何内置 GeoJSON 数据", "success": False}))
|
|
sys.exit(1)
|
|
|
|
result = {
|
|
"success": True,
|
|
"output_dir": output_dir,
|
|
"converted": converted
|
|
}
|
|
print(json.dumps(result))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|