Skip to content

Commit

Permalink
CityGMLを読むだけのテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Dec 5, 2023
1 parent 1c228b7 commit 6554ff7
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ members = [
"nusamai-mvt",
]
resolver = "2"

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 2
8 changes: 4 additions & 4 deletions nusamai-plateau/citygml/src/geometric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub type GeometryRef = Vec<GeometryRefEntry>;
#[derive(Debug, Default)]
pub struct Geometries {
pub vertices: Vec<[f64; 3]>,
pub polygons: MultiPolygon<'static, 1, u32>,
pub linestrings: MultiLineString<'static, 1, u32>,
pub multipolygons: MultiPolygon<'static, 1, u32>,
pub multilinestrings: MultiLineString<'static, 1, u32>,
}

/// Store for collecting vertices and polygons from GML.
Expand Down Expand Up @@ -81,8 +81,8 @@ impl GeometryCollector {
}
Geometries {
vertices,
polygons: self.multi_polygon.clone(),
linestrings: self.multi_linestring.clone(),
multipolygons: self.multi_polygon.clone(),
multilinestrings: self.multi_linestring.clone(),
}
}

Expand Down
8 changes: 4 additions & 4 deletions nusamai-plateau/citygml/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ impl<R: BufRead> SubTreeReader<'_, R> {
self.parse_composite_surface()?;
GeometryType::Surface
}
// (Bound(GML_NS), b"OrientableSurface") => ...
// (Bound(GML_NS), b"Polygon") => ...
// (Bound(GML_NS), b"TriangulatedSurface") => ...
// (Bound(GML_NS), b"Tin") => ...
(Bound(GML_NS), b"OrientableSurface") => todo!(),
(Bound(GML_NS), b"Polygon") => todo!(),
(Bound(GML_NS), b"TriangulatedSurface") => todo!(),
(Bound(GML_NS), b"Tin") => todo!(),

Check warning on line 321 in nusamai-plateau/citygml/src/parser.rs

View check run for this annotation

Codecov / codecov/patch

nusamai-plateau/citygml/src/parser.rs#L318-L321

Added lines #L318 - L321 were not covered by tests
_ => {
return Err(ParseError::SchemaViolation(format!(
"Unexpected element <{}>",
Expand Down
1 change: 1 addition & 0 deletions nusamai-plateau/examples/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fn main() {
println!("elapsed time parsing: {:?}", parsing_time);
total_parsing_time += parsing_time;
}

println!("total parsing time: {:?}", total_parsing_time);
}

Expand Down
Binary file not shown.
70 changes: 70 additions & 0 deletions nusamai-plateau/tests/test_simple.rs
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),
};
}

0 comments on commit 6554ff7

Please sign in to comment.