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,
)


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