james-willis commented on code in PR #1027:
URL: https://github.com/apache/sedona-db/pull/1027#discussion_r3601329486
##########
rust/sedona-geometry/src/transform.rs:
##########
@@ -415,6 +415,57 @@ where
Ok(())
}
+/// Visit each point of a Point/MultiPoint geometry as `Some((x, y))` — or
+/// `None` for an empty (sub-)point — optionally transforming each coordinate
+/// with `trans` before visiting.
+///
+/// Compared to [`transform`], which writes a transformed WKB copy, this hands
+/// the caller each coordinate directly, so point-sampling consumers can
+/// transform and consume in one pass with no intermediate geometry
+/// materialisation. Any other geometry type is an error.
+pub fn visit_point_coords<F>(
+ geom: impl GeometryTrait<T = f64>,
+ trans: Option<&dyn CrsTransform>,
+ mut visit: F,
+) -> Result<(), SedonaGeometryError>
+where
+ F: FnMut(Option<(f64, f64)>) -> Result<(), SedonaGeometryError>,
+{
+ fn visit_one<P, F>(
+ point: &P,
+ trans: Option<&dyn CrsTransform>,
+ visit: &mut F,
+ ) -> Result<(), SedonaGeometryError>
+ where
+ P: PointTrait<T = f64>,
+ F: FnMut(Option<(f64, f64)>) -> Result<(), SedonaGeometryError>,
+ {
+ match point.coord() {
+ Some(coord) => {
+ let mut xy = (coord.x(), coord.y());
+ if let Some(trans) = trans {
+ trans.transform_coord(&mut xy)?;
+ }
+ visit(Some(xy))
+ }
+ None => visit(None),
+ }
+ }
+
+ match geom.as_type() {
+ GeometryType::Point(point) => visit_one(point, trans, &mut visit),
+ GeometryType::MultiPoint(multi_point) => {
+ for point in multi_point.points() {
+ visit_one(&point, trans, &mut visit)?;
+ }
+ Ok(())
+ }
+ _ => Err(SedonaGeometryError::Invalid(
+ "expected a Point or MultiPoint geometry".to_string(),
+ )),
Review Comment:
Geometry Collection of points sounds reasonable but a GeomCollection of
multipoints or (especially) combo of points and multipoints sounds like the
return type would be challenging
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]