iGN5117 commented on code in PR #877:
URL: https://github.com/apache/sedona/pull/877#discussion_r1245559557
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -1200,6 +1199,31 @@ public void geometryTypeWithMeasuredCollection() {
assertEquals(expected4, actual4);
}
+ @Test
+ public void closestPoint() {
+ Point point1 = GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1));
+ LineString lineString1 =
GEOMETRY_FACTORY.createLineString(coordArray(1, 0, 1, 1, 2, 1, 2, 0, 1, 0));
+ String expected1 = "POINT (1 1)";
+ String actual1 = Functions.closestPoint(point1, lineString1).toText();
+ assertEquals(expected1, actual1);
+
+ Point point2 = GEOMETRY_FACTORY.createPoint(new Coordinate(160, 40));
+ LineString lineString2 =
GEOMETRY_FACTORY.createLineString(coordArray(10, 30, 50, 50, 30, 110, 70, 90,
180, 140, 130, 190));
+ String expected2 = "POINT (160 40)";
+ String actual2 = Functions.closestPoint(point2, lineString2).toText();
+ assertEquals(expected2, actual2);
+ Point expectedPoint3 = GEOMETRY_FACTORY.createPoint(new
Coordinate(125.75342465753425, 115.34246575342466));
+ Double expected3 = Functions.closestPoint(lineString2,
point2).distance(expectedPoint3);
+ assertEquals(expected3, 0, 1e-3);
Review Comment:
Why is the tolerance level 1e-3 here? please standardize to 1e-6 or we can
even go upto 1e-9.
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -1200,6 +1199,31 @@ public void geometryTypeWithMeasuredCollection() {
assertEquals(expected4, actual4);
}
+ @Test
+ public void closestPoint() {
+ Point point1 = GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1));
+ LineString lineString1 =
GEOMETRY_FACTORY.createLineString(coordArray(1, 0, 1, 1, 2, 1, 2, 0, 1, 0));
Review Comment:
What happens if one or both the geometries are empty? Please add unit tests
testing that.
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -1200,6 +1199,31 @@ public void geometryTypeWithMeasuredCollection() {
assertEquals(expected4, actual4);
}
+ @Test
+ public void closestPoint() {
+ Point point1 = GEOMETRY_FACTORY.createPoint(new Coordinate(1, 1));
+ LineString lineString1 =
GEOMETRY_FACTORY.createLineString(coordArray(1, 0, 1, 1, 2, 1, 2, 0, 1, 0));
+ String expected1 = "POINT (1 1)";
+ String actual1 = Functions.closestPoint(point1, lineString1).toText();
+ assertEquals(expected1, actual1);
+
+ Point point2 = GEOMETRY_FACTORY.createPoint(new Coordinate(160, 40));
+ LineString lineString2 =
GEOMETRY_FACTORY.createLineString(coordArray(10, 30, 50, 50, 30, 110, 70, 90,
180, 140, 130, 190));
+ String expected2 = "POINT (160 40)";
+ String actual2 = Functions.closestPoint(point2, lineString2).toText();
+ assertEquals(expected2, actual2);
+ Point expectedPoint3 = GEOMETRY_FACTORY.createPoint(new
Coordinate(125.75342465753425, 115.34246575342466));
+ Double expected3 = Functions.closestPoint(lineString2,
point2).distance(expectedPoint3);
+ assertEquals(expected3, 0, 1e-3);
+
+ Point point4 = GEOMETRY_FACTORY.createPoint(new Coordinate(80, 160));
+ Polygon polygonA = GEOMETRY_FACTORY.createPolygon(coordArray(190, 150,
20, 10, 160, 70, 190, 150));
+ Geometry polygonB = Functions.buffer(point4, 30);
+ Point expectedPoint4 = GEOMETRY_FACTORY.createPoint(new
Coordinate(131.59149149528952, 101.89887534906197));
+ Double expected4 = Functions.closestPoint(polygonA,
polygonB).distance(expectedPoint4);
+ assertEquals(expected4, 0, 1e-6);
+ }
Review Comment:
Please add a unit test case testing geometry collections
##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -447,6 +448,12 @@ public static Geometry lineFromMultiPoint(Geometry
geometry) {
return GEOMETRY_FACTORY.createLineString(coordinates.toArray(new
Coordinate[0]));
}
+ public static Geometry closestPoint(Geometry left, Geometry right) {
+ DistanceOp distanceOp = new DistanceOp(left, right);
+ Coordinate[] closestPoints = distanceOp.nearestPoints();
Review Comment:
Since we're using JTS DistanceOp, what happens if the one or both the input
geometries are 3D? Is the z ordinate ignored, or it is supported?
We will have to update documentation and tests accordingly.
##########
docs/api/flink/Function.md:
##########
@@ -363,6 +363,31 @@ Input: `MULTILINESTRING((0 0, 10 0, 10 10, 0 10, 0 0),(10
10, 20 10, 20 20, 10 2
Output: `MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((10 10,10 20,20 20,20 10,10
10)))`
+## ST_ClosestPoint
+
+Introduction: Returns the 2-dimensional point on geom1 that is closest to
geom2. This is the first point of the shortest line between the geometries.
+
+Format: `ST_ClosestPoint(g1: geomtry, g2: geometry)`
+
+Since: `1.5.0`
+
+Example1:
+```sql
+SELECT ST_AsText( ST_ClosestPoint(g1, g2)) As ptwkt;
Review Comment:
This documentation needs to be updated about 3D geometries, based on testing
JTS DistanceOp
--
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]