[geos-commits] r2917 - in trunk: . capi tests/unit tests/unit/capi

svn_geos at osgeo.org svn_geos at osgeo.org
Sun Feb 21 10:03:15 EST 2010


Author: strk
Date: 2010-02-21 10:03:15 -0500 (Sun, 21 Feb 2010)
New Revision: 2917

Added:
   trunk/tests/unit/capi/GEOSGeom_extractUniquePointsTest.cpp
Modified:
   trunk/NEWS
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/Makefile.am
Log:
GEOSGeom_extractUniquePoints [RT-SIGTA]


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2010-02-21 14:50:16 UTC (rev 2916)
+++ trunk/NEWS	2010-02-21 15:03:15 UTC (rev 2917)
@@ -5,6 +5,7 @@
   - CAPI: GEOSContext_setNoticeHandler_r, GEOSContext_setErrorHandler_r
   - CAPI: GEOSGeom_createEmptyPoint_r, GEOSGeom_createEmptyLineString_r
           GEOSGeom_createEmptyPolygon_r, GEOSGeom_createEmptyCollection_r
+  - CAPI: GEOSGeom_extractUniquePoints_r
 
 Changes in 3.2.0 
 

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-02-21 14:50:16 UTC (rev 2916)
+++ trunk/capi/geos_c.h.in	2010-02-21 15:03:15 UTC (rev 2917)
@@ -546,6 +546,11 @@
                               GEOSContextHandle_t handle,
                               const GEOSGeometry* g1, double tolerance);
 
+/* Return all distinct vertices of input geometry as a MULTIPOINT */
+extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints_r(
+                              GEOSContextHandle_t handle,
+                              const GEOSGeometry* g);
+
 /************************************************************************
  *
  *  Binary predicates - return 2 on exception, 1 on true, 0 on false

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-02-21 14:50:16 UTC (rev 2916)
+++ trunk/capi/geos_ts_c.cpp	2010-02-21 15:03:15 UTC (rev 2917)
@@ -54,6 +54,7 @@
 #include <geos/linearref/LengthIndexedLine.h>
 #include <geos/geom/BinaryOp.h>
 #include <geos/util/IllegalArgumentException.h>
+#include <geos/util/UniqueCoordinateArrayFilter.h>
 #include <geos/util/Machine.h>
 #include <geos/version.h> 
 
@@ -4672,6 +4673,55 @@
     return GEOSInterpolate_r(extHandle, g, d * length);
 }
 
+GEOSGeometry*
+GEOSGeom_extractUniquePoints_r(GEOSContextHandle_t extHandle,
+                              const GEOSGeometry* g)
+{
+    if ( 0 == extHandle ) return 0;
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( handle->initialized == 0 ) return 0;
 
+    using namespace geos::geom;
+    using namespace geos::util;
+    using namespace std;
+
+    try
+    {
+
+    /* 1: extract points */
+    vector<const Coordinate*> coords;
+    UniqueCoordinateArrayFilter filter(coords);
+    g->apply_ro(&filter);
+
+    /* 2: for each point, create a geometry and put into a vector */
+    vector<Geometry*>* points = new vector<Geometry*>();
+    points->reserve(coords.size());
+    const GeometryFactory* factory = g->getFactory();
+    for (vector<const Coordinate*>::iterator it=coords.begin(),
+                                             itE=coords.end();
+                                             it != itE; ++it)
+    {
+        Geometry* point = factory->createPoint(*(*it));
+        points->push_back(point);
+    }
+
+    /* 3: create a multipoint */
+    return factory->createMultiPoint(points);
+
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+        return 0;
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+        return 0;
+    }
+}
+
+
 } /* extern "C" */
 

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2010-02-21 14:50:16 UTC (rev 2916)
+++ trunk/tests/unit/Makefile.am	2010-02-21 15:03:15 UTC (rev 2917)
@@ -92,7 +92,8 @@
 	capi/GEOSPreparedGeometryTest.cpp \
 	capi/GEOSPolygonizer_getCutEdgesTest.cpp \
 	capi/GEOSBufferTest.cpp \
-	capi/GEOSGeom_create.cpp
+	capi/GEOSGeom_create.cpp \
+	capi/GEOSGeom_extractUniquePointsTest.cpp
 
 noinst_HEADERS = \
 	utility.h

Added: trunk/tests/unit/capi/GEOSGeom_extractUniquePointsTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSGeom_extractUniquePointsTest.cpp	                        (rev 0)
+++ trunk/tests/unit/capi/GEOSGeom_extractUniquePointsTest.cpp	2010-02-21 15:03:15 UTC (rev 2917)
@@ -0,0 +1,100 @@
+// $Id: GEOSContainsTest.cpp 2424 2009-04-29 23:52:36Z mloskot $
+// 
+// Test Suite for C-API GEOSGeom_extractUniquePoints_r
+
+#include <tut.hpp>
+// geos
+#include <geos_c.h>
+// std
+#include <cstdarg>
+#include <cstdio>
+#include <cstdlib>
+
+namespace tut
+{
+    //
+    // Test Group
+    //
+
+    // Common data used in test cases.
+    struct test_capigeosextractuniquepoints_data
+    {
+        GEOSGeometry* geom1_;
+        GEOSGeometry* geom2_;
+        GEOSContextHandle_t handle_;
+
+        static void notice(const char *fmt, ...)
+        {
+            std::fprintf( stdout, "NOTICE: ");
+
+            va_list ap;
+            va_start(ap, fmt);
+            std::vfprintf(stdout, fmt, ap);
+            va_end(ap);
+        
+            std::fprintf(stdout, "\n");
+        }
+
+        test_capigeosextractuniquepoints_data()
+            : geom1_(0), geom2_(0)
+        {
+            handle_ = initGEOS_r(notice, notice);
+        }       
+
+        ~test_capigeosextractuniquepoints_data()
+        {
+            GEOSGeom_destroy_r(handle_, geom1_);
+            GEOSGeom_destroy_r(handle_, geom2_);
+            geom1_ = 0;
+            geom2_ = 0;
+            finishGEOS_r(handle_);
+        }
+
+    };
+
+    typedef test_group<test_capigeosextractuniquepoints_data> group;
+    typedef group::object object;
+
+    group test_capigeosextractuniquepoints_group("capi::GEOSGeom_extractUniquePoints");
+
+    //
+    // Test Cases
+    //
+
+    template<>
+    template<>
+    void object::test<1>()
+    {
+        geom1_ = GEOSGeomFromWKT_r(handle_, "POLYGON EMPTY");
+        /* ensure_equals(GEOSGetNumGeometries_r(handle_, geom2_), 0); */
+        ensure(GEOSisEmpty_r(handle_,
+		GEOSGeom_extractUniquePoints_r(handle_, geom1_)));
+    }
+
+    template<>
+    template<>
+    void object::test<2>()
+    {
+        geom1_ = GEOSGeomFromWKT_r(handle_, "MULTIPOINT(0 0, 0 0, 1 1)");
+        geom2_ = GEOSGeomFromWKT_r(handle_, "MULTIPOINT(0 0, 1 1)");
+        /* ensure_equals(GEOSGetNumGeometries_r(handle_, geom2_), 0); */
+        ensure(GEOSEquals_r(handle_,
+		GEOSGeom_extractUniquePoints_r(handle_, geom1_),
+		geom2_));
+    }
+
+    template<>
+    template<>
+    void object::test<3>()
+    {
+        geom1_ = GEOSGeomFromWKT_r(handle_, "GEOMETRYCOLLECTION(MULTIPOINT(0 0, 0 0, 1 1),LINESTRING(1 1, 2 2, 2 2, 0 0),POLYGON((5 5, 0 0, 0 2, 2 2, 5 5)))");
+        geom2_ = GEOSGeomFromWKT_r(handle_, "MULTIPOINT(0 0, 1 1, 2 2, 5 5, 0 2)");
+        /* ensure_equals(GEOSGetNumGeometries_r(handle_, geom2_), 0); */
+        ensure(GEOSEquals_r(handle_,
+		GEOSGeom_extractUniquePoints_r(handle_, geom1_),
+		geom2_));
+    }
+
+ 
+} // namespace tut
+



More information about the geos-commits mailing list