[geos-commits] [SCM] GEOS branch master updated. 7eb3369032d42425fafd4defe799f43f352215ec

git at osgeo.org git at osgeo.org
Fri Jun 22 22:38:48 PDT 2018


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".

The branch, master has been updated
       via  7eb3369032d42425fafd4defe799f43f352215ec (commit)
       via  fe5b4d41ed19fc8c076a6482f60e10c50b488e0f (commit)
      from  681d852f9a12b3d0c03d90075f6c42aaf60a199f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 7eb3369032d42425fafd4defe799f43f352215ec
Merge: 681d852 fe5b4d4
Author: Regina Obe <lr at pcorp.us>
Date:   Fri Jun 22 22:38:47 2018 -0700

    Merge branch 'add-GEOSGeomGetZ' of darkpanda/geos into master


commit fe5b4d41ed19fc8c076a6482f60e10c50b488e0f
Author: J Smith <dark.panda at gmail.com>
Date:   Tue Jan 19 12:54:05 2016 -0500

    Expose getZ to the CAPI via GEOSGeomGetZ.

diff --git a/capi/geos_c.cpp b/capi/geos_c.cpp
index 901556e..cd22cd4 100644
--- a/capi/geos_c.cpp
+++ b/capi/geos_c.cpp
@@ -666,6 +666,16 @@ GEOSGeomGetY(const Geometry *g, double *y)
 }
 
 /*
+ * For POINT
+ * returns 0 on exception, otherwise 1
+ */
+int
+GEOSGeomGetZ(const Geometry *g1, double *z)
+{
+	return GEOSGeomGetZ_r(handle, g1, z);
+}
+
+/*
  * Call only on polygon
  * Return a copy of the internal Geometry.
  */
diff --git a/capi/geos_c.h.in b/capi/geos_c.h.in
index 0c81f31..639aa67 100644
--- a/capi/geos_c.h.in
+++ b/capi/geos_c.h.in
@@ -1069,6 +1069,7 @@ extern int GEOS_DLL GEOSGeomGetNumPoints_r(GEOSContextHandle_t handle,
 /* Return -1 on exception, Geometry must be a Point. */
 extern int GEOS_DLL GEOSGeomGetX_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *x);
 extern int GEOS_DLL GEOSGeomGetY_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *y);
+extern int GEOS_DLL GEOSGeomGetZ_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *z);
 
 /*
  * Return NULL on exception, Geometry must be a Polygon.
@@ -1993,6 +1994,7 @@ extern int GEOS_DLL GEOSGeomGetNumPoints(const GEOSGeometry* g);
 /* Return -1 on exception, Geometry must be a Point. */
 extern int GEOS_DLL GEOSGeomGetX(const GEOSGeometry *g, double *x);
 extern int GEOS_DLL GEOSGeomGetY(const GEOSGeometry *g, double *y);
+extern int GEOS_DLL GEOSGeomGetZ(const GEOSGeometry *g, double *z);
 
 /*
  * Return NULL on exception, Geometry must be a Polygon.
diff --git a/capi/geos_ts_c.cpp b/capi/geos_ts_c.cpp
index 533b097..47cda5a 100644
--- a/capi/geos_ts_c.cpp
+++ b/capi/geos_ts_c.cpp
@@ -3199,6 +3199,49 @@ GEOSGeomGetY_r(GEOSContextHandle_t extHandle, const Geometry *g1, double *y)
 }
 
 /*
+ * For POINT
+ * returns 0 on exception, otherwise 1
+ */
+int
+GEOSGeomGetZ_r(GEOSContextHandle_t extHandle, const Geometry *g1, double *z)
+{
+    if ( 0 == extHandle )
+    {
+        return 0;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 0;
+    }
+
+    try
+    {
+        using geos::geom::Point;
+        const Point *po = dynamic_cast<const Point *>(g1);
+        if ( ! po )
+        {
+            handle->ERROR_MESSAGE("Argument is not a Point");
+            return 0;
+        }
+        *z = po->getZ();
+        return 1;
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+
+    return 0;
+}
+
+/*
  * Call only on polygon
  * Return a copy of the internal Geometry.
  */
diff --git a/include/geos/geom/Point.h b/include/geos/geom/Point.h
index 7360caa..000b348 100644
--- a/include/geos/geom/Point.h
+++ b/include/geos/geom/Point.h
@@ -113,6 +113,7 @@ public:
 
 	double getX() const;
 	double getY() const;
+  double getZ() const;
 	const Coordinate* getCoordinate() const override;
 	std::string getGeometryType() const override;
 	GeometryTypeId getGeometryTypeId() const override;
diff --git a/src/geom/Point.cpp b/src/geom/Point.cpp
index 0f02d68..a602d05 100644
--- a/src/geom/Point.cpp
+++ b/src/geom/Point.cpp
@@ -126,6 +126,15 @@ Point::getY() const
 	return getCoordinate()->y;
 }
 
+double
+Point::getZ() const
+{
+	if (isEmpty()) {
+		throw util::UnsupportedOperationException("getZ called on empty Point\n");
+	}
+	return getCoordinate()->z;
+}
+
 const Coordinate *
 Point::getCoordinate() const
 {
diff --git a/tests/unit/capi/GEOSLineString_PointTest.cpp b/tests/unit/capi/GEOSLineString_PointTest.cpp
index 1bc2572..8db60fe 100644
--- a/tests/unit/capi/GEOSLineString_PointTest.cpp
+++ b/tests/unit/capi/GEOSLineString_PointTest.cpp
@@ -7,6 +7,7 @@
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
+#include <cmath>
 
 namespace tut
 {
@@ -61,7 +62,7 @@ namespace tut
     {
         geom1_ = GEOSGeomFromWKT("LINESTRING(0 0, 5 5, 10 10)");
         GEOSGeometry *geom2;
-        double x, y;
+        double x, y, z;
         ensure( nullptr != geom1_ );
 
         char const r1 = GEOSisClosed(geom1_);
@@ -71,27 +72,33 @@ namespace tut
         geom2 = GEOSGeomGetPointN(geom1_, 0);
         GEOSGeomGetX(geom2, &x);
         GEOSGeomGetY(geom2, &y);
+        GEOSGeomGetZ(geom2, &z);
 
         ensure_equals(x, 0);
         ensure_equals(y, 0);
+        ensure(std::isnan(z));
 
         GEOSGeom_destroy(geom2);
 
         geom2 = GEOSGeomGetStartPoint(geom1_);
         GEOSGeomGetX(geom2, &x);
         GEOSGeomGetY(geom2, &y);
+        GEOSGeomGetZ(geom2, &z);
 
         ensure_equals(x, 0);
         ensure_equals(y, 0);
+        ensure(std::isnan(z));
 
         GEOSGeom_destroy(geom2);
 
         geom2 = GEOSGeomGetEndPoint(geom1_);
         GEOSGeomGetX(geom2, &x);
         GEOSGeomGetY(geom2, &y);
+        GEOSGeomGetZ(geom2, &z);
 
         ensure_equals(x, 10);
         ensure_equals(y, 10);
+        ensure(std::isnan(z));
 
         GEOSGeom_destroy(geom2);
     }
@@ -119,4 +126,20 @@ namespace tut
         points = GEOSGeomGetNumPoints(geom1_);
         ensure_equals(points, 3);
     }
+
+    template<>
+    template<>
+    void object::test<4>()
+    {
+        geom1_ = GEOSGeomFromWKT("POINT Z(0 10 20)");
+        double x, y, z;
+
+        GEOSGeomGetX(geom1_, &x);
+        GEOSGeomGetY(geom1_, &y);
+        GEOSGeomGetZ(geom1_, &z);
+
+        ensure_equals(x, 0);
+        ensure_equals(y, 10);
+        ensure_equals(z, 20);
+    }
 } // namespace tut

-----------------------------------------------------------------------

Summary of changes:
 capi/geos_c.cpp                              | 10 +++++++
 capi/geos_c.h.in                             |  2 ++
 capi/geos_ts_c.cpp                           | 43 ++++++++++++++++++++++++++++
 include/geos/geom/Point.h                    |  1 +
 src/geom/Point.cpp                           |  9 ++++++
 tests/unit/capi/GEOSLineString_PointTest.cpp | 25 +++++++++++++++-
 6 files changed, 89 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list