Copilot commented on code in PR #2852:
URL: https://github.com/apache/sedona/pull/2852#discussion_r3125401878
##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/GeographyFunctionTest.scala:
##########
@@ -87,6 +88,16 @@ class GeographyFunctionTest extends TestBaseScala {
.first()
assertEquals(3, row.getInt(0))
}
+
+ it("ST_Centroid square polygon") {
+ val row = sparkSession
+ .sql("SELECT ST_AsText(ST_Centroid(ST_GeogFromWKT('POLYGON ((0 0, 2 0,
2 2, 0 2, 0 0))', 4326))) AS c")
+ .first()
+ val point = new WKTReader().read(row.getString(0)).asInstanceOf[Point]
+ // Planar centroid of unit square from (0,0) to (2,2) is (1,1)
Review Comment:
The comment says "unit square" but the polygon spans (0,0) to (2,2), i.e., a
2×2 square. Adjusting the wording will avoid confusion when reading the test.
##########
docs/api/sql/geography/Geography-Functions/ST_Centroid.md:
##########
@@ -0,0 +1,42 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+
+# ST_Centroid
+
+Introduction: Returns the planar centroid of a geography object as a Geography
point. Note that this computes the centroid in the projected (lon/lat)
coordinate space, not on the sphere.
+
+Format:
+
+`ST_Centroid (A: Geography)`
+
+Return type: `Geography`
+
+Since: `v1.9.1`
+
+SQL Example
+
+```sql
+SELECT ST_AsText(ST_Centroid(ST_GeogFromWKT('POLYGON ((0 0, 2 0, 2 2, 0 2, 0
0))')));
Review Comment:
This SQL example uses `ST_AsText(ST_Centroid(...))`, but `ST_Centroid` on a
Geography returns a Geography, while `ST_AsText` is the Geometry WKT formatter.
Use `ST_AsEWKT(ST_Centroid(...))`, or convert via
`ST_AsText(ST_GeogToGeometry(ST_Centroid(...)))`, or just show `SELECT
ST_Centroid(...)` output.
##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/GeographyFunctionTest.scala:
##########
@@ -87,6 +88,16 @@ class GeographyFunctionTest extends TestBaseScala {
.first()
assertEquals(3, row.getInt(0))
}
+
+ it("ST_Centroid square polygon") {
+ val row = sparkSession
+ .sql("SELECT ST_AsText(ST_Centroid(ST_GeogFromWKT('POLYGON ((0 0, 2 0,
2 2, 0 2, 0 0))', 4326))) AS c")
Review Comment:
`ST_AsText` expects a Geometry input; here
`ST_Centroid(ST_GeogFromWKT(...))` returns a Geography, so this will fail at
runtime (child expression is `SerdeAware` and gets cast to `Geometry`).
Consider converting first (`ST_AsText(ST_GeogToGeometry(ST_Centroid(...)))`) or
asserting on the returned Geography directly (e.g.,
`row.get(0).asInstanceOf[Geography]`) / using `ST_AsEWKT`.
##########
spark/common/src/test/scala/org/apache/sedona/sql/geography/GeographyFunctionTest.scala:
##########
@@ -23,7 +23,8 @@ import org.apache.sedona.sql.TestBaseScala
import org.apache.spark.sql.functions.{col, lit}
import org.apache.spark.sql.sedona_sql.expressions.{st_constructors,
st_functions, st_predicates}
import org.junit.Assert.{assertEquals, assertNotNull, assertTrue}
-import org.locationtech.jts.geom.Geometry
+import org.locationtech.jts.geom.{Geometry, Point}
Review Comment:
Unused import: `Geometry` is imported but not referenced anywhere in this
test file. Removing it will keep the imports clean (and avoids warnings if the
build treats them as errors).
--
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]