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

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Sep 13 10:03:30 PDT 2013


Author: strk
Date: 2013-09-13 10:03:30 -0700 (Fri, 13 Sep 2013)
New Revision: 3959

Modified:
   trunk/capi/geos_c.cpp
   trunk/capi/geos_c.h.in
   trunk/capi/geos_ts_c.cpp
   trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp
Log:
Added onlyEdges parameter to GEOSVoronoiDiagram (#627)

Contributed by Vishal Tiwari

Modified: trunk/capi/geos_c.cpp
===================================================================
--- trunk/capi/geos_c.cpp	2013-09-13 12:18:58 UTC (rev 3958)
+++ trunk/capi/geos_c.cpp	2013-09-13 17:03:30 UTC (rev 3959)
@@ -1271,9 +1271,9 @@
 }
 
 Geometry*
-GEOSVoronoiDiagram(const Geometry *g, double tolerance)
+GEOSVoronoiDiagram(const Geometry *g, double tolerance, int onlyEdges)
 {
-  return GEOSVoronoiDiagram_r(handle, g, tolerance);
+  return GEOSVoronoiDiagram_r(handle, g, tolerance, onlyEdges);
 }
 
 } /* extern "C" */

Modified: trunk/capi/geos_c.h.in
===================================================================
--- trunk/capi/geos_c.h.in	2013-09-13 12:18:58 UTC (rev 3958)
+++ trunk/capi/geos_c.h.in	2013-09-13 17:03:30 UTC (rev 3959)
@@ -754,12 +754,14 @@
  */
 extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram(
 				const GEOSGeometry *g,  
-				double tolerance);
+				double tolerance,
+				int onlyEdges);
 
 extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram_r(
 				GEOSContextHandle_t extHandle, 
 				const GEOSGeometry *g1, 
-				double tolerance);
+				double tolerance,
+				int onlyEdges);
 
 
 /************************************************************************

Modified: trunk/capi/geos_ts_c.cpp
===================================================================
--- trunk/capi/geos_ts_c.cpp	2013-09-13 12:18:58 UTC (rev 3958)
+++ trunk/capi/geos_ts_c.cpp	2013-09-13 17:03:30 UTC (rev 3959)
@@ -6219,7 +6219,7 @@
     return NULL;
 }
 Geometry* 
-GEOSVoronoiDiagram_r(GEOSContextHandle_t extHandle, const Geometry *g1,double tolerance)
+GEOSVoronoiDiagram_r(GEOSContextHandle_t extHandle, const Geometry *g1,double tolerance ,int onlyEdges)
 {
 	if ( 0 == extHandle ) return NULL;
 
@@ -6234,7 +6234,8 @@
 		VoronoiDiagramBuilder builder;
 		builder.setSites(*g1);
 		builder.setTolerance(tolerance);
-		return builder.getDiagram(*(g1->getFactory())).release();
+		if(onlyEdges) return builder.getSubdivision()->getEdges(*g1->getFactory()).release();
+		else return builder.getDiagram(*(g1->getFactory())).release();
 	}    
 	catch(const std::exception &e)
 	{    

Modified: trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp
===================================================================
--- trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp	2013-09-13 12:18:58 UTC (rev 3958)
+++ trunk/tests/unit/capi/GEOSVoronoiDiagramTest.cpp	2013-09-13 17:03:30 UTC (rev 3959)
@@ -88,11 +88,18 @@
     template<>
     void object::test<1>()
     {
-        geom1_ = GEOSGeomFromWKT("POINT(10 20)");
+	    geom1_ = GEOSGeomFromWKT("POINT(10 20)");
 
-        geom2_ = GEOSVoronoiDiagram(geom1_,0);
-        ensure_equals ( GEOSisEmpty(geom2_), 1 );
-        ensure_equals ( GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION );
+	    geom2_ = GEOSVoronoiDiagram(geom1_,0, 0);
+	    ensure_equals ( GEOSisEmpty(geom2_), 1 );
+	    ensure_equals ( GEOSGeomTypeId(geom2_), GEOS_GEOMETRYCOLLECTION );
+
+	    GEOSGeom_destroy(geom2_);
+	    geom2_ = GEOSVoronoiDiagram(geom1_, 0, 1); 
+	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
+	    std::string out(wkt_c);
+	    free(wkt_c);
+	    ensure_equals(out,"MULTILINESTRING EMPTY");
     }
 
     //More points:
@@ -102,8 +109,15 @@
     {
 	    geom1_ = GEOSGeomFromWKT("MULTIPOINT ((280 300), (420 330), (380 230), (320 160))");
 
-	    geom2_ = GEOSVoronoiDiagram(geom1_,0);
+	    geom2_ = GEOSVoronoiDiagram(geom1_,0,0);
 	    ensure_equals_wkt(geom2_ ,"GEOMETRYCOLLECTION (POLYGON ((110 175.71428571428572, 110 500, 310.35714285714283 500, 353.515625 298.59375, 306.875 231.96428571428572, 110 175.71428571428572)), POLYGON ((590 204, 590 -10, 589.1666666666666 -10, 306.875 231.96428571428572, 353.515625 298.59375, 590 204)), POLYGON ((110 -10, 110 175.71428571428572, 306.875 231.96428571428572, 589.1666666666666 -10, 110 -10)), POLYGON ((310.35714285714283 500, 590 500, 590 204, 353.515625 298.59375, 310.35714285714283 500)))" );
+
+	    GEOSGeom_destroy(geom2_);
+	    geom2_ = GEOSVoronoiDiagram(geom1_, 0, 1); 
+	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
+	    std::string out(wkt_c);
+	    free(wkt_c);
+	    ensure_equals(out, "MULTILINESTRING ((280 300, 420 330), (280 300, 320 160), (320 160, 380 230), (380 230, 420 330), (280 300, 380 230))");
     }
     //Larger number of points:
     template<>
@@ -112,8 +126,15 @@
     {
 	    geom1_ = GEOSGeomFromWKT("MULTIPOINT ((170 270), (270 270), (230 310), (180 330), (250 340), (315 318), (330 260), (240 170), (220 220), (270 220))");
 
-	    geom2_ = GEOSVoronoiDiagram(geom1_,0);
+	    geom2_ = GEOSVoronoiDiagram(geom1_,0,0);
 	    ensure_equals_wkt(geom2_,"GEOMETRYCOLLECTION (POLYGON ((0 329.1666666666667, 0 510, 190 510, 213.94736842105263 342.36842105263156, 195.625 296.5625, 0 329.1666666666667)), POLYGON ((0 76.50000000000001, 0 329.1666666666667, 195.625 296.5625, 216 266, 88.33333333333333 138.33333333333334, 0 76.50000000000001)), POLYGON ((216 266, 195.625 296.5625, 213.94736842105263 342.36842105263156, 267 307, 225 265, 216 266)), POLYGON ((245 245, 225 265, 267 307, 275.9160583941606 309.54744525547443, 303.1666666666667 284, 296.6666666666667 245, 245 245)), POLYGON ((225 265, 245 245, 245 201, 88.33333333333333 138.33333333333334, 216 266, 225 265)), POLYGON ((0 0, 0 76.50000000000001, 88.33333333333333 138.33333333333334, 245 201, 380 120, 500 0, 0 0)), POLYGON ((190 510, 343.76153846153846 510, 275.9160583941606 309.54744525547443, 267 307, 213.94736842105263 342.36842105263156, 190 510)), POLYGON ((245 201, 245 245, 296.6666666666667 245, 380 120, 245 201)), POLYGON ((343.76153846
 153846 510, 500 510, 500 334.9051724137931, 303.1666666666667 284, 275.9160583941606 309.54744525547443, 343.76153846153846 510)), POLYGON ((500 334.9051724137931, 500 0, 380 120, 296.6666666666667 245, 303.1666666666667 284, 500 334.9051724137931)))");
+
+	    GEOSGeom_destroy(geom2_);
+	    geom2_ = GEOSVoronoiDiagram(geom1_, 0, 1);
+	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_); 
+	    std::string out(wkt_c);
+	    free(wkt_c);
+	    ensure_equals(out, "MULTILINESTRING ((250 340, 315 318), (180 330, 250 340), (170 270, 180 330), (170 270, 240 170), (240 170, 330 260), (315 318, 330 260), (270 270, 330 260), (270 270, 315 318), (250 340, 270 270), (230 310, 270 270), (230 310, 250 340), (180 330, 230 310), (170 270, 230 310), (220 220, 230 310), (170 270, 220 220), (220 220, 240 170), (220 220, 270 220), (240 170, 270 220), (270 220, 330 260), (270 220, 270 270), (220 220, 270 270))");
     }
     //Test with non-zero Tolerance value
     template<>
@@ -122,8 +143,15 @@
     {
 	    geom1_ = GEOSGeomFromWKT("MULTIPOINT ((150 210), (210 270), (150 220), (220 210), (215 269))");
 
-	    geom2_ = GEOSVoronoiDiagram(geom1_,10);
+	    geom2_ = GEOSVoronoiDiagram(geom1_,10,0);
 	    ensure_equals_wkt(geom2_,"GEOMETRYCOLLECTION (POLYGON ((290 252.5, 290 140, 185 140, 185 215, 187.9268292682927 235.4878048780488, 290 252.5)), POLYGON ((80 215, 80 340, 100.83333333333336 340, 187.9268292682927 235.4878048780488, 185 215, 80 215)), POLYGON ((80 140, 80 215, 185 215, 185 140, 80 140)), POLYGON ((100.83333333333336 340, 290 340, 290 252.5, 187.9268292682927 235.4878048780488, 100.83333333333336 340)))");
+
+	    GEOSGeom_destroy(geom2_);
+	    geom2_ = GEOSVoronoiDiagram(geom1_, 10, 1);
+	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_); 
+	    std::string out(wkt_c);
+	    free(wkt_c);
+	    ensure_equals(out,"MULTILINESTRING ((150 220, 210 270), (150 210, 150 220), (150 210, 220 210), (210 270, 220 210), (150 220, 220 210))");
     }
     template<>
     template<>
@@ -131,8 +159,27 @@
     {
 	    geom1_ = GEOSGeomFromWKT("MULTIPOINT ((40 420), (50 420), (210 290), (300 360), (350 150), (170 70), (134 135) ,(305 359), (351 145), (175 71))");
 
-	    geom2_ = GEOSVoronoiDiagram(geom1_,10);
+	    geom2_ = GEOSVoronoiDiagram(geom1_,10,0);
 	    ensure_equals_wkt(geom2_, "GEOMETRYCOLLECTION (POLYGON ((-310 146.559649122807, -310 770, 45 770, 45 263.64736842105265, -310 146.559649122807)), POLYGON ((-310 -153.37692307692305, -310 146.559649122807, 45 263.64736842105265, 59.16911764705881 267.8235294117647, 239.43506493506493 179.43506493506493, 241.34156378600824 151.98148148148147, -310 -153.37692307692305)), POLYGON ((45 770, 266.20000000000005 770, 181.94323144104806 418.9301310043668, 59.16911764705881 267.8235294117647, 45 263.64736842105265, 45 770)), POLYGON ((59.16911764705881 267.8235294117647, 181.94323144104806 418.9301310043668, 311.875 251.875, 239.43506493506493 179.43506493506493, 59.16911764705881 267.8235294117647)), POLYGON ((-310 -280, -310 -153.37692307692305, 241.34156378600824 151.98148148148147, 433.3333333333333 -280, -310 -280)), POLYGON ((266.20000000000005 770, 701 770, 701 344.5238095238096, 311.875 251.875, 181.94323144104806 418.9301310043668, 266.20000000000005 770)), POLYGON ((701
  344.5238095238096, 701 -280, 433.3333333333333 -280, 241.34156378600824 151.98148148148147, 239.43506493506493 179.43506493506493, 311.875 251.875, 701 344.5238095238096)))");
+
+	    GEOSGeom_destroy(geom2_);
+	    geom2_ = GEOSVoronoiDiagram(geom1_, 10, 1);
+	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
+	    std::string out(wkt_c);
+	    free(wkt_c);
+	    ensure_equals(out,"MULTILINESTRING ((50 420, 300 360), (40 420, 50 420), (40 420, 134 135), (134 135, 170 70), (170 70, 350 150), (300 360, 350 150), (210 290, 350 150), (210 290, 300 360), (50 420, 210 290), (134 135, 210 290), (50 420, 134 135), (134 135, 350 150))");
     }
+    template<>
+    template<>
+    void object::test<6>()
+    {
+	    geom1_ = GEOSGeomFromWKT("MULTIPOINT ((123 245), (165 313), (240 310), (260 260), (180 210), (240 210))");
+	    geom2_ = GEOSVoronoiDiagram(geom1_,0,1);
+
+	    char* wkt_c = GEOSWKTWriter_write(w_, geom2_);
+	    std::string out(wkt_c);
+	    free(wkt_c);
+	    ensure_equals(out , "MULTILINESTRING ((240 310, 260 260), (165 313, 240 310), (123 245, 165 313), (123 245, 180 210), (180 210, 240 210), (240 210, 260 260), (180 210, 260 260), (180 210, 240 310), (165 313, 180 210))");
+    }
 } // namespace tut
 



More information about the geos-commits mailing list