jiayuasu commented on code in PR #862:
URL: https://github.com/apache/sedona/pull/862#discussion_r1228977592
##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -881,6 +881,38 @@ public static Integer nRings(Geometry geometry) throws
Exception {
return numRings;
}
+ public static Geometry translate(Geometry geometry, double deltaX, double
deltaY, double deltaZ) {
+ if (!geometry.isEmpty()) {
+ if (geometry instanceof GeometryCollection) {
+ GeometryCollection geometryCollection = (GeometryCollection)
geometry;
Review Comment:
GeometryCollection can have child GeometryCollection. The process to extract
GeometryCollection is more complicated than you thought. See here:
https://github.com/apache/sedona/blob/master/common/src/main/java/org/apache/sedona/common/utils/GeomUtils.java#L411
Please fix it accordingly. We usually use a queue or recursive function to
implement similar logics. In this case, I would recommend a recursive function.
With such a function, the code could be even further simplified.
##########
common/src/test/java/org/apache/sedona/common/FunctionsTest.java:
##########
@@ -731,4 +731,87 @@ public void nRingsUnsupported() {
assertEquals(expected, e.getMessage());
}
+ @Test
Review Comment:
Please also create test cases that have GEOMETRYCOLLECTION(MULTILPOLYGON(),
GEOMETRYCOLLECTION())
##########
sql/common/src/test/scala/org/apache/sedona/sql/dataFrameAPITestScala.scala:
##########
@@ -978,5 +978,14 @@ class dataFrameAPITestScala extends TestBaseScala {
val actual = df.take(1)(0).getInt(0)
assert(expected == actual)
}
+
+ it("Passed ST_Translate") {
Review Comment:
Please add a test for the case that has no optional parameter.
##########
docs/api/flink/Function.md:
##########
@@ -993,6 +993,31 @@ FROM polygondf
!!!note
The detailed EPSG information can be searched on
[EPSG.io](https://epsg.io/).
+## ST_Translate
+Introduction: Returns the input geometry with its X, Y and Z coordinates (if
present in the geometry) translated by deltaX, deltaY and deltaZ (if specified)
+
+If the geometry is 2D, and a deltaZ parameter is specified, no change is done
to the Z coordinate of the geometry and the resultant geometry is also 2D.
+
+If the geometry is empty, no change is done to it.
+
+If a geometry collection is given, all geometries of the collection are
individually translated.
Review Comment:
This should apply to all geometries such as multipoint, multipolygon,
multilinestring, and geometrycollection. Not only geometrycollection.
##########
sql/common/src/test/scala/org/apache/sedona/sql/functionTestScala.scala:
##########
@@ -1954,4 +1954,22 @@ class functionTestScala extends TestBaseScala with
Matchers with GeometrySample
assertEquals(expected, actual)
}
}
+
+ it ("should pass ST_Translate") {
+ val geomTestCases = Map(
+ ("'POINT (1 1 1)'") -> ("'POINT Z(2 2 2)'", "'POINT Z(2 2 1)'"),
+ ("'POLYGON ((1 0, 1 1, 2 1, 2 0, 1 0))'") -> ("'POLYGON ((2 1, 2 2, 3 2,
3 1, 2 1))'", "'POLYGON ((2 1, 2 2, 3 2, 3 1, 2 1))'"),
+ ("'LINESTRING EMPTY'") -> ("'LINESTRING EMPTY'", "'LINESTRING EMPTY'")
+ )
+ for (((geom), expectedResult) <- geomTestCases) {
+ val df = sparkSession.sql(s"SELECT
ST_AsText(ST_Translate(ST_GeomFromWKT($geom), 1, 1, 1)) AS geom, " +
s"$expectedResult")
+ val dfDefaultValue = sparkSession.sql(s"SELECT
ST_AsText(ST_Translate(ST_GeomFromWKT($geom), 1, 1)) AS geom, " +
s"$expectedResult")
Review Comment:
Please add a test for the case that has no optional parameter.
--
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]