[geos-commits] r3574 - in branches/3.3: . src/simplify tests/unit/simplify

svn_geos at osgeo.org svn_geos at osgeo.org
Thu Mar 22 04:34:59 EDT 2012


Author: strk
Date: 2012-03-22 01:34:59 -0700 (Thu, 22 Mar 2012)
New Revision: 3574

Modified:
   branches/3.3/NEWS
   branches/3.3/src/simplify/TaggedLineString.cpp
   branches/3.3/src/simplify/TaggedLineStringSimplifier.cpp
   branches/3.3/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
Log:
Fix simplification of collections with empty items (#519)

Modified: branches/3.3/NEWS
===================================================================
--- branches/3.3/NEWS	2012-02-20 21:34:43 UTC (rev 3573)
+++ branches/3.3/NEWS	2012-03-22 08:34:59 UTC (rev 3574)
@@ -2,6 +2,7 @@
 2012-??-??
 
 - Bug fixes / improvements
+    - Fix simplification of collections with empty items (#519)
     - Fix MSVC compilation of ambiguous log() call (#506)
     - Fix CMake issues with std:: namespace detection (#493)
 

Modified: branches/3.3/src/simplify/TaggedLineString.cpp
===================================================================
--- branches/3.3/src/simplify/TaggedLineString.cpp	2012-02-20 21:34:43 UTC (rev 3573)
+++ branches/3.3/src/simplify/TaggedLineString.cpp	2012-03-22 08:34:59 UTC (rev 3574)
@@ -79,16 +79,21 @@
 	     << endl;
 #endif
 
-	segs.reserve(pts->size()-1);
-
-	for (std::size_t i=0, n=pts->size()-1; i<n; i++)
+	if ( pts->size() )
 	{
-		TaggedLineSegment* seg = new TaggedLineSegment(
-				pts->getAt(i),
-				pts->getAt(i+1),
-				parentLine, i);
 
-		segs.push_back(seg);
+		segs.reserve(pts->size()-1);
+
+		for (std::size_t i=0, n=pts->size()-1; i<n; i++)
+		{
+			TaggedLineSegment* seg = new TaggedLineSegment(
+					pts->getAt(i),
+					pts->getAt(i+1),
+					parentLine, i);
+
+			segs.push_back(seg);
+		}
+
 	}
 
 #if GEOS_DEBUG
@@ -157,18 +162,18 @@
 
 	std::size_t i=0, size=segs.size();
 
-	assert(size);
+	if ( size ) {
+		for (; i<size; i++)
+		{
+			TaggedLineSegment* seg = segs[i];
+			assert(seg);
+			pts->push_back(seg->p0);
+		}
 
-	for (; i<size; i++)
-	{
-		TaggedLineSegment* seg = segs[i];
-		assert(seg);
-		pts->push_back(seg->p0);
+		// add last point
+		pts->push_back(segs[size-1]->p1);
 	}
 
-	// add last point
-	pts->push_back(segs[size-1]->p1);
-
 	return pts;
 }
 

Modified: branches/3.3/src/simplify/TaggedLineStringSimplifier.cpp
===================================================================
--- branches/3.3/src/simplify/TaggedLineStringSimplifier.cpp	2012-02-20 21:34:43 UTC (rev 3573)
+++ branches/3.3/src/simplify/TaggedLineStringSimplifier.cpp	2012-03-22 08:34:59 UTC (rev 3574)
@@ -76,6 +76,7 @@
 	     << std::endl;
 #endif
 
+	if ( ! linePts->size() ) return;
 	simplifySection(0, linePts->size() - 1, 0);
 
 }

Modified: branches/3.3/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp
===================================================================
--- branches/3.3/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp	2012-02-20 21:34:43 UTC (rev 3573)
+++ branches/3.3/tests/unit/simplify/TopologyPreservingSimplifierTest.cpp	2012-03-22 08:34:59 UTC (rev 3574)
@@ -6,6 +6,7 @@
 #include <utility.h>
 // geos
 #include <geos/io/WKTReader.h>
+#include <geos/io/WKTWriter.h>
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/Geometry.h>
@@ -29,12 +30,15 @@
 		geos::geom::PrecisionModel pm;
 		geos::geom::GeometryFactory gf;
 		geos::io::WKTReader wktreader;
+		geos::io::WKTWriter wktwriter;
 
 		typedef geos::geom::Geometry::AutoPtr GeomPtr;
 
 		test_tpsimp_data()
-            : pm(1.0), gf(&pm), wktreader(&gf)
-		{}
+            : pm(1.0), gf(&pm), wktreader(&gf), wktwriter()
+		{
+			//wktwriter.setTrim(1);
+		}
 	};
 
 	typedef test_group<test_tpsimp_data> group;
@@ -208,5 +212,22 @@
 		ensure( "Simplified geometry is invalid!", simplified->isValid() );
         ensure_equals_geometry(g.get(), simplified.get() );
     }
+
+    // GeometryCollection with empty elements
+    // See http://trac.osgeo.org/geos/ticket/519
+    template<>
+    template<>
+    void object::test<11>()
+    {
+        std::string wkt("GEOMETRYCOLLECTION ( \
+                    LINESTRING (0 0, 10 0), POLYGON EMPTY)");
+
+        GeomPtr g(wktreader.read(wkt));
+        GeomPtr simp= TopologyPreservingSimplifier::simplify(g.get(), 1);
+
+        ensure( "Simplified geometry is invalid!", simp->isValid() );
+	ensure_equals(wktwriter.write(simp.get()),
+		"GEOMETRYCOLLECTION (LINESTRING (0 0, 10 0))");
+    }
 } // namespace tut
 



More information about the geos-commits mailing list