This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new ce3c8dd879 [GH-1922] ST_X/Y/Z ON null geometries (#1923)
ce3c8dd879 is described below
commit ce3c8dd879cf15f382ab6162205363f81464f8ed
Author: Javier Goday <[email protected]>
AuthorDate: Wed Apr 23 20:29:41 2025 +0200
[GH-1922] ST_X/Y/Z ON null geometries (#1923)
---
.../main/java/org/apache/sedona/common/Functions.java | 12 ++++++------
.../java/org/apache/sedona/common/FunctionsTest.java | 18 ++++++++++++++++++
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/common/src/main/java/org/apache/sedona/common/Functions.java
b/common/src/main/java/org/apache/sedona/common/Functions.java
index 97e08b7b0f..4e14055d8c 100644
--- a/common/src/main/java/org/apache/sedona/common/Functions.java
+++ b/common/src/main/java/org/apache/sedona/common/Functions.java
@@ -603,28 +603,28 @@ public class Functions {
}
public static Double x(Geometry geometry) {
- if (geometry instanceof Point) {
+ if (geometry instanceof Point && geometry.getCoordinate() != null) {
return geometry.getCoordinate().x;
}
return null;
}
public static Double y(Geometry geometry) {
- if (geometry instanceof Point) {
+ if (geometry instanceof Point && geometry.getCoordinate() != null) {
return geometry.getCoordinate().y;
}
return null;
}
public static Double z(Geometry geometry) {
- if (geometry instanceof Point) {
+ if (geometry instanceof Point && geometry.getCoordinate() != null) {
return geometry.getCoordinate().z;
}
return null;
}
public static Double m(Geometry geom) {
- if (geom instanceof Point) {
+ if (geom instanceof Point && geom.getCoordinate() != null) {
return geom.getCoordinate().getM();
}
return null;
@@ -708,12 +708,12 @@ public class Functions {
public static boolean hasM(Geometry geom) {
Coordinate coord = geom.getCoordinate();
- return !Double.isNaN(coord.getM());
+ return coord != null && !Double.isNaN(coord.getM());
}
public static boolean hasZ(Geometry geom) {
Coordinate coord = geom.getCoordinate();
- return !Double.isNaN(coord.getZ());
+ return coord != null && !Double.isNaN(coord.getZ());
}
public static Geometry flipCoordinates(Geometry geometry) {
diff --git a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
index 4819384e70..748c0b6c12 100644
--- a/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
+++ b/common/src/test/java/org/apache/sedona/common/FunctionsTest.java
@@ -4402,4 +4402,22 @@ public class FunctionsTest extends TestBase {
expected = 2.75;
assertEquals(expected, actual, 1e-6);
}
+
+ @Test
+ public void emptyPoint() throws ParseException {
+ Geometry point = Constructors.geomFromEWKT("POINT(1 1)");
+ Geometry emptyPoint = Constructors.geomFromEWKT("POINT EMPTY");
+
+ double actualX = Functions.x(point);
+ double expectedX = 1.0;
+ assertEquals(expectedX, actualX, 1e-6);
+
+ assertNull(Functions.x(emptyPoint));
+ assertNull(Functions.y(emptyPoint));
+ assertNull(Functions.z(emptyPoint));
+ assertNull(Functions.m(emptyPoint));
+
+ assertFalse(Functions.hasM(emptyPoint));
+ assertFalse(Functions.hasZ(emptyPoint));
+ }
}