Handle citygml-tools directory outputs and doc cjio paths
This commit is contained in:
@@ -41,8 +41,8 @@ def parse_args(argv: Iterable[str] | None = None) -> argparse.Namespace:
|
||||
)
|
||||
parser.add_argument(
|
||||
"--pattern",
|
||||
default="*.city.json",
|
||||
help="Glob pattern for input files (defaults to all .city.json files).",
|
||||
default="**/*.json",
|
||||
help="Glob pattern for input files (defaults to any .json under the input dir).",
|
||||
)
|
||||
return parser.parse_args(argv)
|
||||
|
||||
@@ -65,9 +65,26 @@ def base_name(path: Path) -> str:
|
||||
return name[: -len(".tri.city.json")]
|
||||
if name.endswith(".city.json"):
|
||||
return name[: -len(".city.json")]
|
||||
if name.endswith(".json"):
|
||||
return name[: -len(".json")]
|
||||
return path.stem
|
||||
|
||||
|
||||
def resolve_input_file(path: Path) -> Path | None:
|
||||
"""Handle both flat files and citygml-tools style output directories."""
|
||||
if path.is_file():
|
||||
return path
|
||||
if path.is_dir():
|
||||
# citygml-tools writes <name>.city.json/<name>.json
|
||||
candidate = path / f"{path.stem}.json"
|
||||
if candidate.is_file():
|
||||
return candidate
|
||||
matches = list(path.glob("*.json"))
|
||||
if len(matches) == 1:
|
||||
return matches[0]
|
||||
return None
|
||||
|
||||
|
||||
def allowed_semantic_indices(semantics: dict[str, Any], allowed_types: set[str]) -> set[int]:
|
||||
surfaces = semantics.get("surfaces") or []
|
||||
return {idx for idx, surface in enumerate(surfaces) if surface.get("type") in allowed_types}
|
||||
@@ -156,7 +173,12 @@ def filter_cityjson(cityjson: dict[str, Any], allowed_types: set[str]) -> dict[s
|
||||
|
||||
|
||||
def process_file(path: Path, targets: list[str], output_dir: Path) -> int:
|
||||
cityjson = read_json(path)
|
||||
resolved = resolve_input_file(path)
|
||||
if not resolved:
|
||||
print(f"[skip] cannot resolve CityJSON file for {path}", file=sys.stderr)
|
||||
return 0
|
||||
|
||||
cityjson = read_json(resolved)
|
||||
written = 0
|
||||
base = base_name(path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user