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

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Jun 24 17:43:34 EDT 2009


Author: pramsey
Date: 2009-06-24 17:43:33 -0400 (Wed, 24 Jun 2009)
New Revision: 2604

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/capi/geostest.c
   trunk/tests/unit/capi/test.expected
Log:
Expose Hausdorf distance to CAPI (#264) from Vincent Picavet


Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2009-06-24 21:30:37 UTC (rev 2603)
+++ trunk/capi/geos_c.cpp	2009-06-24 21:43:33 UTC (rev 2604)
@@ -23,6 +23,7 @@
 #include <geos/io/CLocalizer.h>
 #include <geos/operation/overlay/OverlayOp.h>
 #include <geos/operation/union/CascadedPolygonUnion.h>
+#include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
 
 // Some extra magic to make type declarations in geos_c.h work - for cross-checking of types in header.
 #define GEOSGeometry geos::geom::Geometry
@@ -208,6 +209,18 @@
 }
 
 int
+GEOSHausdorffDistance(const Geometry *g1, const Geometry *g2, double *dist)
+{
+    return GEOSHausdorffDistance_r( handle, g1, g2, dist );
+}
+
+int
+GEOSHausdorffDistanceDensify(const Geometry *g1, const Geometry *g2, double densifyFrac, double *dist)
+{
+    return GEOSHausdorffDistanceDensify_r( handle, g1, g2, densifyFrac, dist );
+}
+
+int
 GEOSArea(const Geometry *g, double *area)
 {
     return GEOSArea_r( handle, g, area );

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2009-06-24 21:30:37 UTC (rev 2603)
+++ trunk/capi/geos_c.h.in	2009-06-24 21:43:33 UTC (rev 2604)
@@ -719,7 +719,10 @@
 extern int GEOS_DLL GEOSLength(const GEOSGeometry* g1, double *length);
 extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2,
 	double *dist);
-
+extern int GEOS_DLL GEOSHausdorffDistance(const GEOSGeometry *g1,
+        const GEOSGeometry *g2, double *dist);
+extern int GEOS_DLL GEOSHausdorffDistanceDensify(const GEOSGeometry *g1,
+        const GEOSGeometry *g2, double densifyFrac, double *dist);
 extern int GEOS_DLL GEOSArea_r(GEOSContextHandle_t handle,
                                const GEOSGeometry* g1, double *area);
 extern int GEOS_DLL GEOSLength_r(GEOSContextHandle_t handle,
@@ -727,6 +730,14 @@
 extern int GEOS_DLL GEOSDistance_r(GEOSContextHandle_t handle,
                                    const GEOSGeometry* g1,
                                    const GEOSGeometry* g2, double *dist);
+extern int GEOS_DLL GEOSHausdorffDistance_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry *g1,
+                                   const GEOSGeometry *g2,
+                                   double *dist);
+extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry *g1,
+                                   const GEOSGeometry *g2,
+                                   double densifyFrac, double *dist);
 
 
 /************************************************************************

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2009-06-24 21:30:37 UTC (rev 2603)
+++ trunk/capi/geos_ts_c.cpp	2009-06-24 21:43:33 UTC (rev 2604)
@@ -35,6 +35,7 @@
 #include <geos/io/WKBReader.h>
 #include <geos/io/WKTWriter.h>
 #include <geos/io/WKBWriter.h>
+#include <geos/algorithm/distance/DiscreteHausdorffDistance.h>
 #include <geos/simplify/DouglasPeuckerSimplifier.h>
 #include <geos/simplify/TopologyPreservingSimplifier.h>
 #include <geos/operation/valid/IsValidOp.h>
@@ -97,6 +98,8 @@
 using geos::operation::overlay::overlayOp;
 using geos::operation::geounion::CascadedPolygonUnion;
 
+using geos::algorithm::distance::DiscreteHausdorffDistance;
+
 typedef std::auto_ptr<Geometry> GeomAutoPtr;
 
 typedef struct GEOSContextHandleInternal
@@ -698,6 +701,74 @@
 }
 
 int
+GEOSHausdorffDistance_r(GEOSContextHandle_t extHandle, const Geometry *g1, const Geometry *g2, double *dist)
+{
+    assert(0 != dist);
+
+    if ( 0 == extHandle )
+    {
+        return 0;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 0;
+    }
+
+    try
+    {
+        *dist = DiscreteHausdorffDistance::distance(*g1, *g2);
+        return 1;
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return 0;
+}
+
+int
+GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t extHandle, const Geometry *g1, const Geometry *g2, double densifyFrac, double *dist)
+{
+    assert(0 != dist);
+
+    if ( 0 == extHandle )
+    {
+        return 0;
+    }
+
+    GEOSContextHandleInternal_t *handle = 0;
+    handle = reinterpret_cast<GEOSContextHandleInternal_t*>(extHandle);
+    if ( 0 == handle->initialized )
+    {
+        return 0;
+    }
+
+    try
+    {
+        *dist = DiscreteHausdorffDistance::distance(*g1, *g2, densifyFrac);
+        return 1;
+    }
+    catch (const std::exception &e)
+    {
+        handle->ERROR_MESSAGE("%s", e.what());
+    }
+    catch (...)
+    {
+        handle->ERROR_MESSAGE("Unknown exception thrown");
+    }
+    
+    return 0;
+}
+
+int
 GEOSArea_r(GEOSContextHandle_t extHandle, const Geometry *g, double *area)
 {
     assert(0 != area);

Modified: trunk/tests/unit/capi/geostest.c
===================================================================
--- trunk/tests/unit/capi/geostest.c	2009-06-24 21:30:37 UTC (rev 2603)
+++ trunk/tests/unit/capi/geostest.c	2009-06-24 21:43:33 UTC (rev 2604)
@@ -332,6 +332,12 @@
 	/* Distance */
 	if ( GEOSDistance(g1, g2, &dist) ) printf("Distance: %g\n", dist);
 
+	/* Hausdorff Distance */
+	if ( GEOSHausdorffDistance(g1, g2, &dist) ) printf("HausdorffDistance: %g\n", dist);
+
+	/* Hausdorff Distance with densification */
+	if ( GEOSHausdorffDistanceDensify(g1, g2, 0.001, &dist) ) printf("HausdorffDistanceDensify: %g\n", dist);
+
 	/* Area */
 	if ( GEOSArea(g1, &area) ) printf("Area 1: %g\n", area);
 	if ( GEOSArea(g2, &area) ) printf("Area 2: %g\n", area);

Modified: trunk/tests/unit/capi/test.expected
===================================================================
--- trunk/tests/unit/capi/test.expected	2009-06-24 21:30:37 UTC (rev 2603)
+++ trunk/tests/unit/capi/test.expected	2009-06-24 21:43:33 UTC (rev 2604)
@@ -19,6 +19,8 @@
 Intersect
 Contains
 Distance: 0
+HausdorffDistance: 100
+HausdorffDistanceDensify: 100
 Area 1: 2.67588e+09
 Area 2: 2.65405e+09
 Simplify: POLYGON ((335215.0239261208334938 167537.5377202073286753, 335205.1267784655792639 167536.2307696900388692, 335190.1602671957225539 167536.1341839407396037, 329275.7395326890982687 167942.1145713863952551, 329261.2026209282921627 167945.7238237099954858, 326746.7026209282921627 168774.3238237039768137, 326614.4661321343737654 168829.7659389766049571, 326483.0105803586193360 168904.0626540626399219, 326415.8285449087852612 168952.2921427348919678, 314706.9285449027665891 178006.3921427289023995, 314699.2775538869318552 178012.9502176995156333, 314692.3254273570491932 178020.2450067681784276, 314686.1427613845444284 178028.2024342618533410, 314680.7923384761670604 178036.7416956787055824, 314230.7465425680857152 178947.3026234415883664, 314226.6719709816970862 178956.7423383510031272, 314223.5882016817340627 178966.5505348258011509, 303859.9882016727351584 219020.0505348258011509, 303310.6373324339510873 221276.7480226673360448, 303244.5555483103962615 221575.2231361457088497, 303207.9014352059457451 221755.5931846564926673, 303174.1926699578762054 222016.0467631698702462, 303147.8926699608564377 222311.9467631608713418, 303145.8096594382659532 222441.7101097303093411, 303148.4957166555686854 222489.2534012109390460, 303150.6692645543371327 222504.6388423194293864, 303153.4334335363237187 222514.6280661432247143, 303157.2167087217676453 222524.2775247619138099, 303161.9784481927636079 222533.4835586513218004, 303167.6674988568993285 222542.1472717873693909, 303174.2227459607529454 222550.1755940386210568, 303181.5737696161959320 222557.4822809745091945, 303189.6416012879926711 222563.9888403478544205, 303198.3395721145207062 222569.6253752996271942, 303212.3620380503707565 222576.3191453621548135, 303222.2142427377984859 222579.5377297651721165, 303232.3466742536984384 222581.7192554557113908, 340240.9466742626973428 228562.4192554587207269, 371903.0451431074179709 233449.6295974932727404, 373488.5732348550227471 233688.9796828530670609, 373535.2659228414413519 233694.0060347228136379, 373625.1659228474600241 233697.9060347288323101, 373642.9873771221027710 233697.8969001443183515, 373658.5972774084657431 233696.5464864801033400, 373668.8035941756097600 233694.2963110199489165, 373678.7193140533054247 233690.9931775288132485, 373692.8122531549306586 233684.1461583603522740, 373705.6626988743664697 233675.1818597918318119, 373713.3821066011441872 233668.1360854624363128, 373723.4792837048298679 233656.1552833794266917, 373731.5811145076295361 233642.7443571751064155, 373737.4887050554389134 233628.2325351690815296, 373741.0570283696870320 233612.9760718587203883, 373742.1984847519779578 233597.3495021346316207, 373741.5948758341837674 233586.9155264864384662, 373738.6590603159856983 233571.5248282807588112, 373733.3552462080260739 233556.7816210339078680, 373652.5153630711138248 233377.7256075733166654, 365392.9153630621149205 216697.2256075733166654, 365330.2477527938899584 216577.1791839415382128, 339880.6477527848910540 171569.1791839415382128, 338822.4769281532499008 169840.9383075150544755, 337870.8334730038768612 168543.3540531243779697, 337827.5742276740493253 168491.7532505890121683, 337753.4899077645386569 168423.4924162378301844, 337717.4185027767089196 168392.1531549684004858, 337663.9758644747198559 168349.0786549655895215, 337651.0045043539139442 168340.2275259852758609, 337530.7915914550540037 168279.3433566540188622, 337516.7246118161710910 168273.5343728628649842, 335388.0246118131908588 167578.8343728748441208, 335310.1989645521389320 167555.1487824073119555, 335215.0239261208334938 167537.5377202073286753))



More information about the geos-commits mailing list