Repository: calcite
Updated Branches:
  refs/heads/master 3ab5664b7 -> 17cd76af7


[CALCITE-2031] Implement ST_X and ST_Y GIS functions


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/17cd76af
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/17cd76af
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/17cd76af

Branch: refs/heads/master
Commit: 17cd76af79920524e7da12a08acee3b52f0055a8
Parents: 3ab5664
Author: Michael Mior <[email protected]>
Authored: Thu Nov 2 13:49:46 2017 -0400
Committer: Michael Mior <[email protected]>
Committed: Thu Nov 2 13:49:46 2017 -0400

----------------------------------------------------------------------
 .../apache/calcite/runtime/GeoFunctions.java    | 10 ++++++
 core/src/test/resources/sql/spatial.iq          | 33 +++++++++++++++++++-
 site/_docs/reference.md                         |  4 +--
 3 files changed, 44 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/17cd76af/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java 
b/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java
index 6ddcc8a..73884c0 100644
--- a/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java
+++ b/core/src/main/java/org/apache/calcite/runtime/GeoFunctions.java
@@ -257,6 +257,16 @@ public class GeoFunctions {
     return geom.g().hasZ();
   }
 
+  /** Returns the x-value of the first coordinate of {@code geom}. */
+  public static Double ST_X(Geom geom) {
+    return geom.g() instanceof Point ? ((Point) geom.g()).getX() : null;
+  }
+
+  /** Returns the y-value of the first coordinate of {@code geom}. */
+  public static Double ST_Y(Geom geom) {
+    return geom.g() instanceof Point ? ((Point) geom.g()).getY() : null;
+  }
+
   /** Returns the z-value of the first coordinate of {@code geom}. */
   public static Double ST_Z(Geom geom) {
     return geom.g().getDescription().hasZ() && geom.g() instanceof Point

http://git-wip-us.apache.org/repos/asf/calcite/blob/17cd76af/core/src/test/resources/sql/spatial.iq
----------------------------------------------------------------------
diff --git a/core/src/test/resources/sql/spatial.iq 
b/core/src/test/resources/sql/spatial.iq
index 1a37b44..95003ff 100755
--- a/core/src/test/resources/sql/spatial.iq
+++ b/core/src/test/resources/sql/spatial.iq
@@ -295,6 +295,18 @@ EXPR$0
 {"x":1,"y":2,"z":1.5}
 !ok
 
+# Get x of point
+SELECT ST_X(ST_MakePoint(1.0, 2.0,1.5));
+EXPR$0
+1.0
+!ok
+
+# Get y of point
+SELECT ST_Y(ST_MakePoint(1.0, 2.0,1.5));
+EXPR$0
+2.0
+!ok
+
 # Get z of point
 SELECT ST_Z(ST_MakePoint(1.0, 2.0,1.5));
 EXPR$0
@@ -544,7 +556,16 @@ p , POINT, 1
 # Not implemented
 
 # ST_X(geom) Returns the x-value of the first coordinate of *geom*
-# Not implemented
+
+SELECT ST_X(ST_GeomFromText('POINT Z(1 2 3)'));
+EXPR$0
+1.0
+!ok
+
+SELECT ST_X(ST_GeomFromText('POINT (1 2)'));
+EXPR$0
+1.0
+!ok
 
 # ST_XMax(geom) Returns the maximum x-value of *geom*
 # Not implemented
@@ -555,6 +576,16 @@ p , POINT, 1
 # ST_Y(geom) Returns the y-value of the first coordinate of *geom*
 # Not implemented
 
+SELECT ST_Y(ST_GeomFromText('POINT Z(1 2 3)'));
+EXPR$0
+2.0
+!ok
+
+SELECT ST_Y(ST_GeomFromText('POINT (1 2)'));
+EXPR$0
+2.0
+!ok
+
 # ST_YMax(geom) Returns the maximum y-value of *geom*
 # Not implemented
 

http://git-wip-us.apache.org/repos/asf/calcite/blob/17cd76af/site/_docs/reference.md
----------------------------------------------------------------------
diff --git a/site/_docs/reference.md b/site/_docs/reference.md
index 2bc70fd..8f0b4e8 100644
--- a/site/_docs/reference.md
+++ b/site/_docs/reference.md
@@ -1667,6 +1667,8 @@ Not implemented:
 | o | ST_GeometryType(geom) | Returns the type of *geom*
 | o | ST_GeometryTypeCode(geom) | Returns the OGC SFS type code of *geom*
 | o | ST_Envelope(geom [, srid ]) | Returns the envelope of *geom* (which may 
be a GEOMETRYCOLLECTION) as a GEOMETRY
+| o | ST_X(geom) | Returns the x-value of the first coordinate of *geom*
+| o | ST_Y(geom) | Returns the y-value of the first coordinate of *geom*
 
 Not implemented:
 
@@ -1698,10 +1700,8 @@ Not implemented:
 * ST_PointOnSurface(geom) Returns an interior or boundary point of *geom*
 * ST_SRID(geom) Returns SRID value of *geom* or 0 if it does not have one
 * ST_StartPoint(lineString) Returns the first coordinate of *lineString*
-* ST_X(geom) Returns the x-value of the first coordinate of *geom*
 * ST_XMax(geom) Returns the maximum x-value of *geom*
 * ST_XMin(geom) Returns the minimum x-value of *geom*
-* ST_Y(geom) Returns the y-value of the first coordinate of *geom*
 * ST_YMax(geom) Returns the maximum y-value of *geom*
 * ST_YMin(geom) Returns the minimum y-value of *geom*
 

Reply via email to