iGN5117 commented on code in PR #873:
URL: https://github.com/apache/sedona/pull/873#discussion_r1242549320
##########
python/sedona/sql/st_functions.py:
##########
@@ -120,6 +121,16 @@
_call_st_function = partial(call_sedona_function, "st_functions")
+@validate_argument_types
+def GeometryType(geometry: ColumnOrName):
+ """Return the type of the geometry as a string.
Review Comment:
Please add measured geometry explanation in the documentation
##########
docs/api/flink/Function.md:
##########
@@ -1,3 +1,25 @@
+## GeometryType
+
+Introduction: Returns the type of the geometry as a string. Eg: 'LINESTRING',
'POLYGON', 'MULTIPOINT', etc.
Review Comment:
Please add measured geometry explanation in the documentation along with
examples
##########
docs/api/sql/Function.md:
##########
@@ -1,3 +1,25 @@
+## GeometryType
+
Review Comment:
Please add measured geometry explanation in the documentation along with
examples
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -1078,6 +1078,34 @@ public void affine2DHybridGeomCollection() {
assertEquals(expectedPolygon2.toText(),
actualGeomCollection.getGeometryN(0).getGeometryN(1).getGeometryN(1).toText());
}
+ @Test
+ public void geometryTypeWithMeasured() {
+ String expected = "POINT";
+ String actual =
Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createPoint(new
Coordinate(10, 5)));
+ assertEquals(expected, actual);
+
+ // Create a point with measure value
+ CoordinateXYM coords = new CoordinateXYM(2, 3, 4);
+ Point measuredPoint = new GeometryFactory().createPoint(coords);
+ String expected2 = "POINTM";
+ String actual2 = Functions.geometryTypeWithMeasured(measuredPoint);
+ assertEquals(expected2, actual2);
+
+ // Create a linestring with measure value
+ CoordinateXYM[] coordsLineString = new CoordinateXYM[] {new
CoordinateXYM(1, 2, 3), new CoordinateXYM(4, 5, 6)};
+ LineString measuredLineString = new
GeometryFactory().createLineString(coordsLineString);
+ String expected3 = "LINESTRINGM";
Review Comment:
Please add test case testing geometry collections
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -1078,6 +1078,34 @@ public void affine2DHybridGeomCollection() {
assertEquals(expectedPolygon2.toText(),
actualGeomCollection.getGeometryN(0).getGeometryN(1).getGeometryN(1).toText());
}
+ @Test
+ public void geometryTypeWithMeasured() {
Review Comment:
There is already a static object GEOMETRY_FACTORY to create geometries,
there's no need to created new GeometryFactory() objects during the tests.
Please use GEOMETRY_FACTORY here
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -1078,6 +1078,34 @@ public void affine2DHybridGeomCollection() {
assertEquals(expectedPolygon2.toText(),
actualGeomCollection.getGeometryN(0).getGeometryN(1).getGeometryN(1).toText());
}
+ @Test
+ public void geometryTypeWithMeasured() {
+ String expected = "POINT";
+ String actual =
Functions.geometryTypeWithMeasured(GEOMETRY_FACTORY.createPoint(new
Coordinate(10, 5)));
+ assertEquals(expected, actual);
+
+ // Create a point with measure value
+ CoordinateXYM coords = new CoordinateXYM(2, 3, 4);
+ Point measuredPoint = new GeometryFactory().createPoint(coords);
+ String expected2 = "POINTM";
+ String actual2 = Functions.geometryTypeWithMeasured(measuredPoint);
+ assertEquals(expected2, actual2);
+
+ // Create a linestring with measure value
+ CoordinateXYM[] coordsLineString = new CoordinateXYM[] {new
CoordinateXYM(1, 2, 3), new CoordinateXYM(4, 5, 6)};
+ LineString measuredLineString = new
GeometryFactory().createLineString(coordsLineString);
+ String expected3 = "LINESTRINGM";
+ String actual3 =
Functions.geometryTypeWithMeasured(measuredLineString);
+ assertEquals(expected3, actual3);
+
Review Comment:
Have you checked for XYZM coordinate geometries? I see that PostGIS does not
implement that properly even though documentation says otherwise.
Does our function return say POINTM for POINT with XYZM coordinates? Please
add testcases testing that
##########
common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java:
##########
@@ -489,4 +489,11 @@ public static Double getHausdorffDistance(Geometry g1,
Geometry g2, double densi
}
return hausdorffDistanceObj.distance();
}
+
+ public static Boolean isMeasuredGeometry(Geometry geom) {
+ Coordinate[] coordinates = geom.getCoordinates();
+ GeometryFactory geometryFactory = new GeometryFactory();
Review Comment:
Sedona will not support creating geometryCollections with hybrid dimensions.
Hence, to check for measure availability, it is better to poll 1 coordinate
using getCoordinate, and check for presence of M by checking
!Double.isNan(coordinate.getM()). This avoids having to create a
geometryFactory, and a coordinate sequence everytime.
--
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]