[geos-commits] r2903 - in trunk: . capi

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Feb 5 09:39:30 EST 2010


Author: strk
Date: 2010-02-05 09:39:27 -0500 (Fri, 05 Feb 2010)
New Revision: 2903

Modified:
   trunk/NEWS
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
Log:
New CAPI interface: GEOSisValidDetail ( tell state, reason & location apart )


Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2010-02-04 23:35:41 UTC (rev 2902)
+++ trunk/NEWS	2010-02-05 14:39:27 UTC (rev 2903)
@@ -1,3 +1,8 @@
+Changes in 3.3.0 
+
+- New things:
+  - CAPI: GEOSisValidDetail: tell state, reason & location apart
+
 Changes in 3.2.0 
 
 - Add Single-sided buffer operation

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2010-02-04 23:35:41 UTC (rev 2902)
+++ trunk/capi/geos_c.cpp	2010-02-05 14:39:27 UTC (rev 2903)
@@ -193,6 +193,13 @@
     return GEOSisValidReason_r( handle, g1 );
 }
 
+char
+GEOSisValidDetail(const Geometry *g,
+	char** reason, const Geometry ** location)
+{
+    return GEOSisValidDetail_r( handle, g, reason, location );
+}
+
 //-----------------------------------------------------------------
 // general purpose
 //-----------------------------------------------------------------

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-02-04 23:35:41 UTC (rev 2902)
+++ trunk/capi/geos_c.h.in	2010-02-05 14:39:27 UTC (rev 2903)
@@ -684,6 +684,8 @@
 extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g1);
 extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g1);
 extern char GEOS_DLL *GEOSisValidReason(const GEOSGeometry *g1);
+extern char GEOS_DLL GEOSisValidDetail(const GEOSGeometry* g, char** reason,
+                                         const GEOSGeometry** location);
 extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g1);
 extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g1);
 extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g1);
@@ -694,6 +696,9 @@
                                    const GEOSGeometry* g1);
 extern char GEOS_DLL *GEOSisValidReason_r(GEOSContextHandle_t handle,
                                          const GEOSGeometry* g1);
+extern char GEOS_DLL GEOSisValidDetail_r(GEOSContextHandle_t handle,
+                                         const GEOSGeometry* g, char** reason,
+                                         const GEOSGeometry** location);
 extern char GEOS_DLL GEOSisSimple_r(GEOSContextHandle_t handle,
                                     const GEOSGeometry* g1);
 extern char GEOS_DLL GEOSisRing_r(GEOSContextHandle_t handle,

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-02-04 23:35:41 UTC (rev 2902)
+++ trunk/capi/geos_ts_c.cpp	2010-02-05 14:39:27 UTC (rev 2903)
@@ -629,6 +629,61 @@
     return 0;
 }
 
+char
+GEOSisValidDetail_r(GEOSContextHandle_t extHandle, const Geometry *g,
+	char** reason, const Geometry ** location)
+{
+    if ( 0 == extHandle )
+    {
+        return 0;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 0;
+    }
+
+    try
+    {
+        using geos::operation::valid::IsValidOp;
+        using geos::operation::valid::TopologyValidationError;
+
+        IsValidOp ivo(g);
+        bool isvalid = ivo.isValid();
+        if ( ! isvalid )
+        {
+            TopologyValidationError *err = ivo.getValidationError();
+            if (0 != err)
+            {
+                *location = handle->geomFactory->createPoint(err->getCoordinate());
+                std::string errmsg(err->getMessage());
+                *reason = gstrdup(errmsg);
+            }
+            else {
+                /* is it ever possible for getValidationError to be 0 ? */
+            }
+            return 0; /* invalid */
+        }
+
+        *location = 0;
+        *reason = 0;
+        return 1; /* valid */
+
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+
+    return 2; /* exception */
+}
+
 //-----------------------------------------------------------------
 // general purpose
 //-----------------------------------------------------------------



More information about the geos-commits mailing list