Last active
January 21, 2021 19:16
-
-
Save hugoledoux/320fea3e92f330e5fc4c14e531a14f82 to your computer and use it in GitHub Desktop.
fix wrong "lod" in CityJSON PDOK files
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
[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 = "*" |
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
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