Skip to content

Commit

Permalink
simplify crs
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscorn committed Jan 7, 2024
1 parent ab05cf2 commit 48d467b
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions nusamai-citygml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
23 changes: 10 additions & 13 deletions nusamai-citygml/src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use nusamai_geometry::{MultiLineString, MultiPoint, MultiPolygon};
use nusamai_projection::crs::*;

#[derive(Debug, Clone, Copy)]
pub enum GeometryParseType {
Expand Down Expand Up @@ -35,28 +36,24 @@ pub struct GeometryRefEntry {

pub type GeometryRef = Vec<GeometryRefEntry>;

#[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>,
Expand Down Expand Up @@ -94,7 +91,7 @@ impl GeometryCollector {
]);
}
GeometryStore {
crs: CRS::JGD2011,
epsg: EPSG_JGD2011_GEOGRAPHIC_3D,
vertices,
multipolygon: self.multipolygon,
multilinestring: self.multilinestring,
Expand Down
7 changes: 7 additions & 0 deletions nusamai-projection/src/crs.rs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions nusamai-projection/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod cartesian;
pub mod crs;
pub mod ellipsoid;
pub mod error;
pub mod etmerc;
Expand Down
3 changes: 2 additions & 1 deletion nusamai/src/sink/geojson/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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(),
Expand Down
6 changes: 6 additions & 0 deletions nusamai/src/transform/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::pipeline::{Feedback, Parcel, Sender, TransformError, Transformer};
use nusamai_projection::crs::*;
use nusamai_projection::vshift::JGD2011ToWGS84;

pub struct DummyTransformer {
Expand Down Expand Up @@ -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();
};
Expand Down

0 comments on commit 48d467b

Please sign in to comment.