fix: partition regional land use retrieval
GeoIntel CI / docs-smoke (push) Canceled after 0s
GeoIntel CI / contract-smoke (push) Canceled after 0s

This commit is contained in:
Codex
2026-07-14 22:25:58 +02:00
parent a5b4bbdf8f
commit c4392c17fd
8 changed files with 229 additions and 14 deletions
+16 -5
View File
@@ -50,7 +50,7 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()
def resolve_boundary(scope: GeographicScope, scope_output_root: Path) -> tuple[Path, Path]:
def resolve_boundary(scope: GeographicScope, scope_output_root: Path) -> tuple[Path, Path, Path]:
scope_dir = scope_output_root / scope.key
manifest_path = scope_dir / f"{scope.key.replace('-', '_')}_scope_manifest.json"
if not manifest_path.is_file():
@@ -65,12 +65,20 @@ def resolve_boundary(scope: GeographicScope, scope_output_root: Path) -> tuple[P
):
raise RuntimeError(f"Official scope manifest at {manifest_path} is incomplete or inconsistent")
boundary_path = scope_dir / str(manifest.get("boundary_filename") or "")
members_path = scope_dir / str(manifest.get("municipalities_filename") or "")
if not boundary_path.is_file():
raise RuntimeError(f"Official scope boundary referenced by {manifest_path} is missing")
return boundary_path, manifest_path
if not members_path.is_file():
raise RuntimeError(f"Official scope member boundaries referenced by {manifest_path} are missing")
return boundary_path, members_path, manifest_path
def build_operator_commands(args: argparse.Namespace, scope: GeographicScope, boundary_path: Path) -> list[tuple[str, list[str]]]:
def build_operator_commands(
args: argparse.Namespace,
scope: GeographicScope,
boundary_path: Path,
members_path: Path | None = None,
) -> list[tuple[str, list[str]]]:
scripts_dir = Path(__file__).resolve().parent
scope_output = args.output_root / scope.key
common_flags = ["--fetch-only"] if args.fetch_only else []
@@ -108,6 +116,7 @@ def build_operator_commands(args: argparse.Namespace, scope: GeographicScope, bo
)
)
if not args.skip_landuse:
partition_flags = ["--partition-boundaries-path", str(members_path)] if members_path else []
commands.append(
(
"forest",
@@ -132,6 +141,7 @@ def build_operator_commands(args: argparse.Namespace, scope: GeographicScope, bo
"forest",
"--boundary-path",
str(boundary_path),
*partition_flags,
"--output-dir",
str(scope_output / "landuse"),
"--request-timeout",
@@ -169,8 +179,8 @@ def main() -> int:
try:
if args.max_landuse_features <= 0:
raise ValueError("max-landuse-features must be greater than zero")
boundary_path, manifest_path = resolve_boundary(scope, args.scope_output_root)
commands = build_operator_commands(args, scope, boundary_path)
boundary_path, members_path, manifest_path = resolve_boundary(scope, args.scope_output_root)
commands = build_operator_commands(args, scope, boundary_path, members_path)
results = {label: run_operator(label, command) for label, command in commands}
except (OSError, RuntimeError, ValueError, KeyError) as exc:
print(json.dumps({"status": "error", "message": str(exc)}, ensure_ascii=False), file=sys.stderr)
@@ -185,6 +195,7 @@ def main() -> int:
"display_name": scope.display_name,
"member_count": len(scope.members),
"boundary_path": str(boundary_path),
"municipality_boundaries_path": str(members_path),
"scope_manifest_path": str(manifest_path),
"results": results,
},