Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Last active January 21, 2021 19:16
Show Gist options
  • Save hugoledoux/320fea3e92f330e5fc4c14e531a14f82 to your computer and use it in GitHub Desktop.
Save hugoledoux/320fea3e92f330e5fc4c14e531a14f82 to your computer and use it in GitHub Desktop.
fix wrong "lod" in CityJSON PDOK files
[package]
name = "fixcjpdok"
version = "0.1.0"
authors = ["Hugo Ledoux <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = "*"
serde_json = "*"
use std::fs::File;
use std::io::{BufReader, BufWriter};
use serde_json::{json, Result, Value};
fn convert() -> Result<()> {
let br = BufReader::new(BufReader::new(
File::open("/Users/hugo/data/cityjson/09cn2.volledig/09cn2.json").unwrap(),
));
let mut j: Value = serde_json::from_reader(br)?;
for (_key, co) in j["CityObjects"].as_object_mut().unwrap() {
for g in co["geometry"].as_array_mut().unwrap() {
g["lod"] = serde_json::to_value(json!(1)).unwrap().clone();
}
}
let f = BufWriter::new(File::create("/Users/hugo/temp/x.json").unwrap());
let _re = serde_json::to_writer(f, &j)?;
Ok(())
}
fn main() {
let _re = convert();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment