-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,9 @@ members = [ | |
"nusamai-mvt", | ||
] | ||
resolver = "2" | ||
|
||
[profile.dev] | ||
opt-level = 1 | ||
|
||
[profile.dev.package."*"] | ||
opt-level = 2 |
This file contains 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
This file contains 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
This file contains 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
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use std::io::BufRead; | ||
|
||
use citygml::{CityGMLElement, CityGMLReader, ParseError, SubTreeReader}; | ||
use nusamai_plateau::models::CityObject; | ||
|
||
#[derive(Default, Debug)] | ||
struct Counter { | ||
city_objects: usize, | ||
appearances: usize, | ||
multipolygons: usize, | ||
} | ||
|
||
fn example_toplevel_dispatcher<R: BufRead>( | ||
st: &mut SubTreeReader<R>, | ||
) -> Result<Counter, ParseError> { | ||
let mut counter = Counter::default(); | ||
|
||
match st.parse_children(|st| match st.current_path() { | ||
b"core:cityObjectMember" => { | ||
let mut cityobj: CityObject = Default::default(); | ||
cityobj.parse(st)?; | ||
let geometries = st.collect_geometries(); | ||
counter.city_objects += 1; | ||
counter.multipolygons += geometries.multipolygons.len(); | ||
Ok(()) | ||
} | ||
b"gml:boundedBy" => { | ||
st.skip_current_element()?; | ||
Ok(()) | ||
} | ||
b"app:appearanceMember" => { | ||
st.skip_current_element()?; | ||
counter.appearances += 1; | ||
Ok(()) | ||
} | ||
other => Err(ParseError::SchemaViolation(format!( | ||
"Unrecognized element {}", | ||
String::from_utf8_lossy(other) | ||
))), | ||
}) { | ||
Ok(_) => Ok(counter), | ||
Err(e) => { | ||
println!("Err: {:?}", e); | ||
Err(e) | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn simple_read() { | ||
let reader = std::io::BufReader::new( | ||
zstd::stream::Decoder::new( | ||
std::fs::File::open("./tests/data/53393680_bldg_6697_lod4.2_op.gml.zst").unwrap(), | ||
) | ||
.unwrap(), | ||
); | ||
|
||
let mut xml_reader = quick_xml::NsReader::from_reader(reader); | ||
match CityGMLReader::new().start_root(&mut xml_reader) { | ||
Ok(mut st) => match example_toplevel_dispatcher(&mut st) { | ||
Ok(counter) => { | ||
assert_eq!(counter.city_objects, 1527); | ||
assert_eq!(counter.multipolygons, 196148); | ||
assert_eq!(counter.appearances, 1); | ||
} | ||
Err(e) => panic!("Err: {:?}", e), | ||
}, | ||
Err(e) => panic!("Err: {:?}", e), | ||
}; | ||
} |