From 48d467b79997283cd2ca50ea50ba4a6f51860ae8 Mon Sep 17 00:00:00 2001 From: Taku Fukada Date: Sun, 7 Jan 2024 22:01:56 +0900 Subject: [PATCH] simplify crs --- nusamai-citygml/Cargo.toml | 1 + nusamai-citygml/src/geometry.rs | 23 ++++++++++------------- nusamai-projection/src/crs.rs | 7 +++++++ nusamai-projection/src/lib.rs | 1 + nusamai/src/sink/geojson/mod.rs | 3 ++- nusamai/src/transform/mod.rs | 6 ++++++ 6 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 nusamai-projection/src/crs.rs diff --git a/nusamai-citygml/Cargo.toml b/nusamai-citygml/Cargo.toml index dcd6d8c28..3623db1d7 100644 --- a/nusamai-citygml/Cargo.toml +++ b/nusamai-citygml/Cargo.toml @@ -12,6 +12,7 @@ chrono = { version = "0.4.31", features = ["serde"], default-features = false } indexmap = { version = "2.1", features = ["serde"] } macros = { path = "./macros" } nusamai-geometry = { path = "../nusamai-geometry", features = ["serde"]} +nusamai-projection = { path = "../nusamai-projection"} quick-xml = "0.31" serde = { version = "1.0", features = ["derive"], optional = true } serde_json = { version = "1.0.108", optional = true } diff --git a/nusamai-citygml/src/geometry.rs b/nusamai-citygml/src/geometry.rs index 8f6689922..d5fa568af 100644 --- a/nusamai-citygml/src/geometry.rs +++ b/nusamai-citygml/src/geometry.rs @@ -1,4 +1,5 @@ use nusamai_geometry::{MultiLineString, MultiPoint, MultiPolygon}; +use nusamai_projection::crs::*; #[derive(Debug, Clone, Copy)] pub enum GeometryParseType { @@ -35,28 +36,24 @@ pub struct GeometryRefEntry { pub type GeometryRef = Vec; -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -#[derive(Debug, Default)] -pub enum CRS { - #[default] - WGS84, - JGD2011, -} - -/// Geometries in a toplevel city object and its children. +/// Geometries in a city object and all its children. #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[derive(Debug, Default)] pub struct GeometryStore { - pub crs: CRS, + /// EPSG code of the Coordinate Reference System (CRS) + pub epsg: EPSGCode, + /// Shared vertex buffer for all geometries pub vertices: Vec<[f64; 3]>, + /// All polygons, referenced by `GeometryRef` pub multipolygon: MultiPolygon<'static, 1, u32>, + /// All line-strings of , referenced by `GeometryRef` pub multilinestring: MultiLineString<'static, 1, u32>, + /// All points, referenced by `GeometryRef` pub multipoint: MultiPoint<'static, 1, u32>, } -/// Store for collecting vertices and polygons from GML. #[derive(Default)] -pub struct GeometryCollector { +pub(crate) struct GeometryCollector { pub vertices: indexmap::IndexSet<[u64; 3]>, pub multipolygon: MultiPolygon<'static, 1, u32>, pub multilinestring: MultiLineString<'static, 1, u32>, @@ -94,7 +91,7 @@ impl GeometryCollector { ]); } GeometryStore { - crs: CRS::JGD2011, + epsg: EPSG_JGD2011_GEOGRAPHIC_3D, vertices, multipolygon: self.multipolygon, multilinestring: self.multilinestring, diff --git a/nusamai-projection/src/crs.rs b/nusamai-projection/src/crs.rs new file mode 100644 index 000000000..eb187c0a4 --- /dev/null +++ b/nusamai-projection/src/crs.rs @@ -0,0 +1,7 @@ +pub type EPSGCode = u16; + +pub const EPSG_WGS84_GEOGRAPHIC_2D: EPSGCode = 4326; +pub const EPSG_WGS84_GEOGRAPHIC_3D: EPSGCode = 4979; +pub const EPSG_WGS84_GEOCENTRIC: EPSGCode = 4978; +pub const EPSG_JGD2011_GEOGRAPHIC_2D: EPSGCode = 6668; +pub const EPSG_JGD2011_GEOGRAPHIC_3D: EPSGCode = 6697; diff --git a/nusamai-projection/src/lib.rs b/nusamai-projection/src/lib.rs index 95824ca11..186d2ed5b 100644 --- a/nusamai-projection/src/lib.rs +++ b/nusamai-projection/src/lib.rs @@ -1,4 +1,5 @@ pub mod cartesian; +pub mod crs; pub mod ellipsoid; pub mod error; pub mod etmerc; diff --git a/nusamai/src/sink/geojson/mod.rs b/nusamai/src/sink/geojson/mod.rs index 9d73080a2..4c161c718 100644 --- a/nusamai/src/sink/geojson/mod.rs +++ b/nusamai/src/sink/geojson/mod.rs @@ -183,6 +183,7 @@ mod tests { use super::*; use nusamai_citygml::{object::Feature, Value}; use nusamai_geometry::MultiPolygon; + use nusamai_projection::crs::EPSG_JGD2011_GEOGRAPHIC_3D; #[test] fn test_toplevel_cityobj_multipolygon() { @@ -195,7 +196,7 @@ mod tests { let mut mpoly = MultiPolygon::<'_, 1, u32>::new(); mpoly.add_exterior([[0], [1], [2], [3], [0]]); let geometries = nusamai_citygml::GeometryStore { - crs: nusamai_citygml::CRS::WGS84, + epsg: EPSG_JGD2011_GEOGRAPHIC_3D, vertices, multipolygon: mpoly, multilinestring: Default::default(), diff --git a/nusamai/src/transform/mod.rs b/nusamai/src/transform/mod.rs index 5552d6937..98966995f 100644 --- a/nusamai/src/transform/mod.rs +++ b/nusamai/src/transform/mod.rs @@ -1,4 +1,5 @@ use crate::pipeline::{Feedback, Parcel, Sender, TransformError, Transformer}; +use nusamai_projection::crs::*; use nusamai_projection::vshift::JGD2011ToWGS84; pub struct DummyTransformer { @@ -29,6 +30,11 @@ impl Transformer for DummyTransformer { (v[0], v[1], v[2]) = self.jgd2wgs.convert(lng, lat, height); }); + // Ensure that the original CRS is JGD2011 and the new CRS is WGS 84 + assert_eq!(parcel.cityobj.geometries.epsg, EPSG_JGD2011_GEOGRAPHIC_3D); + parcel.cityobj.geometries.epsg = EPSG_WGS84_GEOGRAPHIC_3D; + + // Send to the next stage if downstream.send(parcel).is_err() { feedback.cancel(); };