Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions c/sedona-proj/src/proj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ impl Proj {
Ok((xyzt_out.0, xyzt_out.1))
}

/// Transform XYZ coordinates
pub(crate) fn transform_xyz(
&mut self,
point: (f64, f64, f64),
) -> Result<(f64, f64, f64), SedonaProjError> {
// Filling extra dimensions with zeroes is what PostGIS does
let xyzt = (point.0, point.1, point.2, 0.0);
let xyzt_out = self.transform(xyzt)?;
Ok((xyzt_out.0, xyzt_out.1, xyzt_out.2))
}

/// Transform XYZT coordinates
pub(crate) fn transform(
&mut self,
Expand Down
12 changes: 12 additions & 0 deletions c/sedona-proj/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ impl CrsTransform for ProjTransform {
coord.1 = res.1;
Ok(())
}

fn transform_coord_3d(&self, coord: &mut (f64, f64, f64)) -> Result<(), SedonaGeometryError> {
let res = self.proj.borrow_mut().transform_xyz(*coord).map_err(|e| {
SedonaGeometryError::Invalid(format!(
"PROJ coordinate transformation failed with error: {e}"
))
})?;
coord.0 = res.0;
coord.1 = res.1;
coord.2 = res.2;
Ok(())
}
}

#[cfg(test)]
Expand Down
10 changes: 10 additions & 0 deletions python/sedonadb/tests/functions/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ def test_st_transform(eng):
)


@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
def test_st_transform_3d(eng):
eng = eng.create_or_skip()
eng.assert_query_result(
"SELECT ST_Transform(ST_GeomFromText('POINT Z (1 1 1)'), 'EPSG:4979', 'EPSG:4978')",
"POINT Z (6376201.805927448 111297.016517882 110568.792276973)",
wkt_precision=9,
)
Comment on lines 36 to 41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular transformation is a great test case and an interesting one because it is 2D -> 3D. Does 2D input (e.g., POINT (-64 45)) work? I believe you can query the number of axes of a CRS to handle this:

https://github.com/apache/sedona-db/blob/main/c/sedona-proj/src/proj_dyn_bindgen.rs#L127-L128

...although we can do that later because I think 3D->3D is what the current code is set up to handle.

Another good test would be 3D -> 2D (the inverse of this transform would be good) and 3D -> 3D like EPSG:4326+EPSG:5701 (lon/lat with Z in meters) to EPSG:4326+EPSG:8050 (lon/lat with Z in feet). You might have to get pyproj to render those to PROJJSON to get them to work in ST_Transform because our internal deserialize_crs() doesn't know how to parse compound CRSes yet.



@pytest.mark.parametrize("eng", [SedonaDB, PostGIS])
@pytest.mark.parametrize(
("geom", "srid", "expected_srid"),
Expand Down