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

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Dec 21 03:55:29 EST 2010


Author: strk
Date: 2010-12-21 00:55:29 -0800 (Tue, 21 Dec 2010)
New Revision: 3161

Added:
   trunk/tests/unit/capi/GEOSRelatePatternMatchTest.cpp
Modified:
   trunk/NEWS
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/Makefile.am
Log:
Add GEOSRelatePatternMatch C-API interface [RT-SIGTA]

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2010-12-20 11:34:43 UTC (rev 3160)
+++ trunk/NEWS	2010-12-21 08:55:29 UTC (rev 3161)
@@ -12,6 +12,7 @@
   - CAPI: GEOSOrientationIndex
   - CAPI: GEOSSharedPaths to find shared paths and their orientation
   - CAPI: GEOSSnap 
+  - CAPI: GEOSRelatePatternMatch 
   -  PHP: new PHP5 bindings based on CAPI
 - C++ API changes:
   - Geometry::isWithinDistance method is now const

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2010-12-20 11:34:43 UTC (rev 3160)
+++ trunk/capi/geos_c.cpp	2010-12-21 08:55:29 UTC (rev 3161)
@@ -176,6 +176,12 @@
     return GEOSRelatePattern_r( handle, g1, g2, pat );
 }
 
+char
+GEOSRelatePatternMatch(const char *mat, const char *pat)
+{
+    return GEOSRelatePatternMatch_r( handle, mat, pat );
+}
+
 char *
 GEOSRelate(const Geometry *g1, const Geometry *g2)
 {

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2010-12-20 11:34:43 UTC (rev 3160)
+++ trunk/capi/geos_c.h.in	2010-12-21 08:55:29 UTC (rev 3161)
@@ -628,8 +628,8 @@
  *
  ***********************************************************************/
 
-extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2,
-	const char *pat);
+extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat);
+extern char GEOS_DLL GEOSRelatePatternMatch(const char* mat, const char *pat);
 extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2);
 extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2);
 extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2);
@@ -644,6 +644,9 @@
                                          const GEOSGeometry* g1,
                                          const GEOSGeometry* g2,
                                          const char *pat);
+extern char GEOS_DLL GEOSRelatePatternMatch_r(GEOSContextHandle_t handle,
+                                         const char* mat,
+                                         const char *pat);
 extern char GEOS_DLL GEOSDisjoint_r(GEOSContextHandle_t handle,
                                     const GEOSGeometry* g1,
                                     const GEOSGeometry* g2);

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2010-12-20 11:34:43 UTC (rev 3160)
+++ trunk/capi/geos_ts_c.cpp	2010-12-21 08:55:29 UTC (rev 3161)
@@ -525,6 +525,45 @@
     return 2;
 }
 
+char
+GEOSRelatePatternMatch_r(GEOSContextHandle_t extHandle, const char *mat,
+                           const char *pat)
+{
+    if ( 0 == extHandle )
+    {
+        return 2;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 2;
+    }
+
+    try
+    {
+        using geos::geom::IntersectionMatrix;
+
+        std::string m(mat);
+        std::string p(pat);
+        IntersectionMatrix im(m);
+
+        bool result = im.matches(p);
+        return result;
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return 2;
+}
+
 char *
 GEOSRelate_r(GEOSContextHandle_t extHandle, const Geometry *g1, const Geometry *g2)
 {

Modified: trunk/tests/unit/Makefile.am
===================================================================
--- trunk/tests/unit/Makefile.am	2010-12-20 11:34:43 UTC (rev 3160)
+++ trunk/tests/unit/Makefile.am	2010-12-21 08:55:29 UTC (rev 3161)
@@ -101,7 +101,8 @@
 	capi/GEOSOrientationIndex.cpp \
 	capi/GEOSLineString_PointTest.cpp \
 	capi/GEOSSnapTest.cpp \
-	capi/GEOSSharedPathsTest.cpp
+	capi/GEOSSharedPathsTest.cpp \
+	capi/GEOSRelatePatternMatchTest.cpp
 
 noinst_HEADERS = \
 	utility.h

Added: trunk/tests/unit/capi/GEOSRelatePatternMatchTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSRelatePatternMatchTest.cpp	                        (rev 0)
+++ trunk/tests/unit/capi/GEOSRelatePatternMatchTest.cpp	2010-12-21 08:55:29 UTC (rev 3161)
@@ -0,0 +1,102 @@
+// $Id$
+// 
+// Test Suite for C-API GEOSRelatePatternMatch
+
+#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_capigeosrelatepatternmatch_data
+    {
+
+        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_capigeosrelatepatternmatch_data()
+        {
+            initGEOS(notice, notice);
+        }       
+
+        ~test_capigeosrelatepatternmatch_data()
+        {
+            finishGEOS();
+        }
+
+    };
+
+    typedef test_group<test_capigeosrelatepatternmatch_data> group;
+    typedef group::object object;
+
+    group test_capigeosrelatepatternmatch_group("capi::GEOSRelatePatternMatch");
+
+    //
+    // Test Cases
+    //
+
+    template<>
+    template<>
+    void object::test<1>()
+    {
+        char ret = GEOSRelatePatternMatch("000000000", "*********");
+	ensure_equals(ret, char(1));
+    }
+
+    template<>
+    template<>
+    void object::test<2>()
+    {
+        char ret = GEOSRelatePatternMatch("000000000", "TTTTTTTTT");
+	ensure_equals(ret, char(1));
+    }
+ 
+    template<>
+    template<>
+    void object::test<3>()
+    {
+        char ret = GEOSRelatePatternMatch("000000000", "000000000");
+	ensure_equals(ret, char(1));
+    }
+
+    template<>
+    template<>
+    void object::test<4>()
+    {
+        char ret = GEOSRelatePatternMatch("000000000", "FFFFFFFFF");
+	ensure_equals(ret, char(0));
+    }
+
+    template<>
+    template<>
+    void object::test<5>()
+    {
+        const char* mat = "012TF012F";
+
+        char ret = GEOSRelatePatternMatch(mat, "TTTTFTTTF");
+	ensure_equals(ret, char(1));
+
+        ret = GEOSRelatePatternMatch(mat, "TT1TFTTTF");
+	ensure_equals(ret, char(0));
+    }
+
+} // namespace tut
+



More information about the geos-commits mailing list