Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Last active May 27, 2025 12:33
Show Gist options
  • Save hugoledoux/700e868a8363b164b8260de40b627915 to your computer and use it in GitHub Desktop.
Save hugoledoux/700e868a8363b164b8260de40b627915 to your computer and use it in GitHub Desktop.
CityJSONSeq ==> 1 file per CityObject (as https://github.com/3DGI/tyler expects)
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)
@hugoledoux
Copy link
Author

cat myfile.city.json | cjseq cat | python cjseq2files.py ./out/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment