[geos-commits] r3532 - in branches/3.3: . include/geos/operation/union src/operation/union tests/xmltester tests/xmltester/tests/general

svn_geos at osgeo.org svn_geos at osgeo.org
Fri Dec 9 03:46:21 EST 2011


Author: strk
Date: 2011-12-09 00:46:21 -0800 (Fri, 09 Dec 2011)
New Revision: 3532

Modified:
   branches/3.3/NEWS
   branches/3.3/include/geos/operation/union/CascadedPolygonUnion.h
   branches/3.3/src/operation/union/CascadedPolygonUnion.cpp
   branches/3.3/tests/xmltester/Makefile.am
   branches/3.3/tests/xmltester/tests/general/TestUnaryUnion.xml
Log:
Fix CascadedPolygonUnion to discard non-polygonal components created during unioning

This is to avoid failures and provide more desirable behaviour.
Includes automated testing. Closes ticket #499.

Modified: branches/3.3/NEWS
===================================================================
--- branches/3.3/NEWS	2011-12-09 08:46:06 UTC (rev 3531)
+++ branches/3.3/NEWS	2011-12-09 08:46:21 UTC (rev 3532)
@@ -9,6 +9,7 @@
     - Print up to 18 digits of precision for TopologyException points
     - Fix noding with reduced precision in Buffer operation (#473)
     - Fix HotPixel original point invalidation (#498)
+    - Fix CascadedPolygonUnion to discard non-polygonal components (#499)
 
 Changes in 3.3.1
 2011-09-27

Modified: branches/3.3/include/geos/operation/union/CascadedPolygonUnion.h
===================================================================
--- branches/3.3/include/geos/operation/union/CascadedPolygonUnion.h	2011-12-09 08:46:06 UTC (rev 3531)
+++ branches/3.3/include/geos/operation/union/CascadedPolygonUnion.h	2011-12-09 08:46:21 UTC (rev 3532)
@@ -14,7 +14,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/union/CascadedPolygonUnion.java r320 (JTS-1.12)
+ * Last port: operation/union/CascadedPolygonUnion.java r487 (JTS-1.12+)
  *
  **********************************************************************/
 
@@ -25,6 +25,7 @@
 
 #include <vector>
 #include <algorithm>
+#include <memory>
 
 #include "GeometryListHolder.h"
 
@@ -82,6 +83,22 @@
      */
     static int const STRTREE_NODE_CAPACITY = 4;
 
+    /**
+     * Computes a {@link Geometry} containing only {@link Polygonal} components.
+     *
+     * Extracts the {@link Polygon}s from the input
+     * and returns them as an appropriate {@link Polygonal} geometry.
+     * 
+     * If the input is already <tt>Polygonal</tt>, it is returned unchanged.
+     *
+     * A particular use case is to filter out non-polygonal components
+     * returned from an overlay operation.
+     *
+     * @param g the geometry to filter
+     * @return a Polygonal geometry
+     */
+    static std::auto_ptr<geom::Geometry> restrictToPolygons(std::auto_ptr<geom::Geometry> g);
+
 public:
     CascadedPolygonUnion();
 
@@ -155,9 +172,9 @@
      * Unions a section of a list using a recursive binary union on each half
      * of the section.
      * 
-     * @param geoms
-     * @param start
-     * @param end
+     * @param geoms the list of geometries containing the section to union
+     * @param start the start index of the section
+     * @param end the index after the end of the section
      * @return the union of the list section
      */
     geom::Geometry* binaryUnion(GeometryListHolder* geoms, std::size_t start, 
@@ -186,7 +203,10 @@
     geom::Geometry* unionOptimized(geom::Geometry* g0, geom::Geometry* g1);
 
     /**
-     * Unions two polygonal geometries.
+     * \brief
+     * Unions two polygonal geometries, restricting computation
+     * to the envelope intersection where possible.
+     *
      * The case of MultiPolygons is optimized to union only 
      * the polygons which lie in the intersection of the two geometry's
      * envelopes.

Modified: branches/3.3/src/operation/union/CascadedPolygonUnion.cpp
===================================================================
--- branches/3.3/src/operation/union/CascadedPolygonUnion.cpp	2011-12-09 08:46:06 UTC (rev 3531)
+++ branches/3.3/src/operation/union/CascadedPolygonUnion.cpp	2011-12-09 08:46:21 UTC (rev 3532)
@@ -14,7 +14,7 @@
  *
  **********************************************************************
  *
- * Last port: operation/union/CascadedPolygonUnion.java r320 (JTS-1.12)
+ * Last port: operation/union/CascadedPolygonUnion.java r487 (JTS-1.12+)
  *
  **********************************************************************/
 
@@ -24,6 +24,7 @@
 #include <geos/geom/Polygon.h>
 #include <geos/geom/MultiPolygon.h>
 #include <geos/geom/util/GeometryCombiner.h>
+#include <geos/geom/util/PolygonExtracter.h>
 #include <geos/index/strtree/STRtree.h>
 // std
 #include <cassert>
@@ -212,9 +213,38 @@
 geom::Geometry* 
 CascadedPolygonUnion::unionActual(geom::Geometry* g0, geom::Geometry* g1)
 {
-    return g0->Union(g1);
+    return restrictToPolygons(std::auto_ptr<geom::Geometry>(g0->Union(g1))).release();
 }
 
+std::auto_ptr<geom::Geometry>
+CascadedPolygonUnion::restrictToPolygons(std::auto_ptr<geom::Geometry> g)
+{
+    using namespace geom;
+    using namespace std;
+
+    if ( dynamic_cast<Polygonal*>(g.get()) ) {
+      return g;
+    }
+
+    Polygon::ConstVect polygons;
+    util::PolygonExtracter::getPolygons(*g, polygons);
+
+    if (polygons.size() == 1)
+      return std::auto_ptr<Geometry>(polygons[0]->clone());
+
+    typedef vector<Geometry *> GeomVect;
+
+    Polygon::ConstVect::size_type n = polygons.size();
+    GeomVect* newpolys = new GeomVect(n);
+    for (Polygon::ConstVect::size_type i=0; i<n; ++i) {
+        (*newpolys)[i] = polygons[i]->clone();
+    }
+    return auto_ptr<Geometry>(
+      g->getFactory()->createMultiPolygon(newpolys)
+    );
+
+}
+
 } // namespace geos.operation.union
 } // namespace geos.operation
 } // namespace geos

Modified: branches/3.3/tests/xmltester/Makefile.am
===================================================================
--- branches/3.3/tests/xmltester/Makefile.am	2011-12-09 08:46:06 UTC (rev 3531)
+++ branches/3.3/tests/xmltester/Makefile.am	2011-12-09 08:46:21 UTC (rev 3532)
@@ -62,6 +62,7 @@
 	$(srcdir)/tests/general/TestRelatePP.xml \
 	$(srcdir)/tests/general/TestSimple.xml \
 	$(srcdir)/tests/general/TestUnaryUnion.xml \
+	$(srcdir)/tests/general/TestUnaryUnionFloating.xml \
 	$(srcdir)/tests/general/TestValid.xml \
 	$(srcdir)/tests/general/TestValid2.xml \
 	$(srcdir)/tests/general/TestValid2-big.xml \

Modified: branches/3.3/tests/xmltester/tests/general/TestUnaryUnion.xml
===================================================================
--- branches/3.3/tests/xmltester/tests/general/TestUnaryUnion.xml	2011-12-09 08:46:06 UTC (rev 3531)
+++ branches/3.3/tests/xmltester/tests/general/TestUnaryUnion.xml	2011-12-09 08:46:21 UTC (rev 3532)
@@ -151,8 +151,7 @@
   </a>
   <test>
     <op name="union" arg1="A">
-    	GEOMETRYCOLLECTION (LINESTRING (0 0, 20 0), 
-  POLYGON ((150 0, 20 0, 20 100, 180 100, 180 0, 150 0)))
+  POLYGON ((150 0, 20 0, 20 100, 180 100, 180 0, 150 0))
     </op>
   </test>
 </case>



More information about the geos-commits mailing list