Last active
May 27, 2025 12:33
-
-
Save hugoledoux/700e868a8363b164b8260de40b627915 to your computer and use it in GitHub Desktop.
CityJSONSeq ==> 1 file per CityObject (as https://github.com/3DGI/tyler expects)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import json | |
import os | |
import sys | |
def write_json_lines_to_files(output_dir): | |
os.makedirs(output_dir, exist_ok=True) | |
for i, line in enumerate(sys.stdin): | |
try: | |
j = json.loads(line) | |
if j["type"] == "CityJSON": | |
output_file = os.path.join(output_dir, "metadata.city.jsonl") | |
with open(output_file, "w") as out_file: | |
json.dump(j, out_file, separators=(",", ":")) | |
else: | |
theid = j["id"] | |
output_file = os.path.join(output_dir, f"{theid}.city.jsonl") | |
with open(output_file, "w") as out_file: | |
json.dump(j, out_file, separators=(",", ":")) | |
except json.JSONDecodeError as e: | |
print(f"Error decoding JSON on line {i + 1}: {e}") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser( | |
description="CityJSONSeq => Save one file per CityObject" | |
) | |
parser.add_argument( | |
"save_folder", type=str, help="Path of the folder to save the files" | |
) | |
args = parser.parse_args() | |
output_dir = args.save_folder | |
write_json_lines_to_files(output_dir) |
Author
hugoledoux
commented
May 27, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment