[geos-commits] r3078 - in trunk: include/geos/operation/polygonize
include/geos/planargraph php/test src/operation/polygonize
src/planargraph
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Jul 1 17:44:33 EDT 2010
Author: strk
Date: 2010-07-01 21:44:33 +0000 (Thu, 01 Jul 2010)
New Revision: 3078
Modified:
trunk/include/geos/operation/polygonize/EdgeRing.h
trunk/include/geos/operation/polygonize/PolygonizeGraph.h
trunk/include/geos/planargraph/PlanarGraph.h
trunk/php/test/test.php
trunk/src/operation/polygonize/EdgeRing.cpp
trunk/src/operation/polygonize/PolygonizeGraph.cpp
trunk/src/planargraph/PlanarGraph.cpp
Log:
Fix PolygonizeGraph::deleteDangles so it doesn't return duplicated LineStrings, as per JTS design. Fixes the Polygonizer Bug reported in list. This commit also takes the chance to reduce some heap allocations.
Modified: trunk/include/geos/operation/polygonize/EdgeRing.h
===================================================================
--- trunk/include/geos/operation/polygonize/EdgeRing.h 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/include/geos/operation/polygonize/EdgeRing.h 2010-07-01 21:44:33 UTC (rev 3078)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: operation/polygonize/EdgeRing.java rev. 109 (JTS-1.10)
+ * Last port: operation/polygonize/EdgeRing.java rev. 109/138 (JTS-1.10)
*
**********************************************************************/
Modified: trunk/include/geos/operation/polygonize/PolygonizeGraph.h
===================================================================
--- trunk/include/geos/operation/polygonize/PolygonizeGraph.h 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/include/geos/operation/polygonize/PolygonizeGraph.h 2010-07-01 21:44:33 UTC (rev 3078)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: operation/polygonize/PolygonizeGraph.java rev. 1.6 (JTS-1.10)
+ * Last port: operation/polygonize/PolygonizeGraph.java rev. 6/138 (JTS-1.10)
*
**********************************************************************/
Modified: trunk/include/geos/planargraph/PlanarGraph.h
===================================================================
--- trunk/include/geos/planargraph/PlanarGraph.h 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/include/geos/planargraph/PlanarGraph.h 2010-07-01 21:44:33 UTC (rev 3078)
@@ -11,6 +11,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: planargraph/PlanarGraph.java rev. 107/138 (JTS-1.10)
+ *
**********************************************************************/
#ifndef GEOS_PLANARGRAPH_PLANARGRAPH_H
@@ -231,6 +235,14 @@
* The return value is a newly allocated vector of existing nodes
*/
std::vector<Node*>* findNodesOfDegree(std::size_t degree);
+
+ /**
+ * \brief
+ * Get all Nodes with the given number of Edges around it.
+ *
+ * Found nodes are pushed to the given vector
+ */
+ void findNodesOfDegree(std::size_t degree, std::vector<Node*>& to);
};
} // namespace geos::planargraph
Modified: trunk/php/test/test.php
===================================================================
--- trunk/php/test/test.php 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/php/test/test.php 2010-07-01 21:44:33 UTC (rev 3078)
@@ -952,49 +952,64 @@
)');
$g2 = $reader->read('POINT(0 0)');
- $g = $g->union($g2); /* Make sure linestrings are noded */
$ret = GEOSPolygonize($g);
- /*
- * NOTE: the following expected results are suspicious
- * due to the duplicated dangle and lack of a cut edge
- */
-
- //var_dump($ret);
-
$this->assertEquals('array', gettype($ret));
$this->assertEquals('array', gettype($ret['rings']));
$this->assertEquals('array', gettype($ret['cut_edges']));
$this->assertEquals('array', gettype($ret['dangles']));
$this->assertEquals('array', gettype($ret['invalid_rings']));
- $this->assertEquals(3, count($ret['rings']));
+ $this->assertEquals(2, count($ret['rings']));
$this->assertEquals(
-'POLYGON ((185 221, 132 146, 83 187, 185 221))'
+'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))' # JTS-confirmed!
, $writer->write($ret['rings'][0]));
$this->assertEquals(
-'POLYGON ((132 146, 185 221, 325 168, 189 98, 132 146))'
+'POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98))' # JTS-confirmed !
, $writer->write($ret['rings'][1]));
- $this->assertEquals(
-'POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))'
- , $writer->write($ret['rings'][2]));
$this->assertEquals(0, count($ret['cut_edges']));
- $this->assertEquals(3, count($ret['dangles']));
+ $this->assertEquals(0, count($ret['invalid_rings']));
+
+ /*
+ * FIXME: the duplicated dangle (0 0, 10 10) is unexpected
+ */
+
+ $this->assertEquals(2, count($ret['dangles']));
$this->assertEquals(
+'LINESTRING (185 221, 100 100)' # JTS-confirmed !
+ , $writer->write($ret['dangles'][0]));
+ $this->assertEquals(
+'LINESTRING (0 0, 10 10)' # JTS-confirmed !
+ , $writer->write($ret['dangles'][1]));
+
+
+ ###########################################################
+
+ $g = $g->union($g2); /* Now make sure linestrings are noded */
+
+ $ret = GEOSPolygonize($g);
+
+ $this->assertEquals('array', gettype($ret));
+ $this->assertEquals('array', gettype($ret['rings']));
+ $this->assertEquals('array', gettype($ret['cut_edges']));
+ $this->assertEquals('array', gettype($ret['dangles']));
+ $this->assertEquals('array', gettype($ret['invalid_rings']));
+
+ $this->assertEquals(2, count($ret['dangles']));
+ $this->assertEquals(
'LINESTRING (132 146, 100 100)'
, $writer->write($ret['dangles'][0]));
$this->assertEquals(
'LINESTRING (0 0, 10 10)'
, $writer->write($ret['dangles'][1]));
- $this->assertEquals(
-'LINESTRING (0 0, 10 10)'
- , $writer->write($ret['dangles'][2]));
$this->assertEquals(0, count($ret['invalid_rings']));
+ // TODO: test a polygonize run with cut lines and invalid_rings
+
}
public function testGeometry_lineMerge()
Modified: trunk/src/operation/polygonize/EdgeRing.cpp
===================================================================
--- trunk/src/operation/polygonize/EdgeRing.cpp 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/src/operation/polygonize/EdgeRing.cpp 2010-07-01 21:44:33 UTC (rev 3078)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: operation/polygonize/EdgeRing.java rev. 109 (JTS-1.10)
+ * Last port: operation/polygonize/EdgeRing.java rev. 109/138 (JTS-1.10)
*
**********************************************************************/
Modified: trunk/src/operation/polygonize/PolygonizeGraph.cpp
===================================================================
--- trunk/src/operation/polygonize/PolygonizeGraph.cpp 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/src/operation/polygonize/PolygonizeGraph.cpp 2010-07-01 21:44:33 UTC (rev 3078)
@@ -14,7 +14,7 @@
*
**********************************************************************
*
- * Last port: operation/polygonize/PolygonizeGraph.java rev. 1.6 (JTS-1.10)
+ * Last port: operation/polygonize/PolygonizeGraph.java rev. 6/138 (JTS-1.10)
*
**********************************************************************/
@@ -30,6 +30,7 @@
#include <cassert>
#include <vector>
+#include <set>
//using namespace std;
using namespace geos::planargraph;
@@ -444,14 +445,13 @@
void
PolygonizeGraph::deleteDangles(std::vector<const LineString*>& dangleLines)
{
- std::vector<Node*> *nodesToRemove=findNodesOfDegree(1);
std::vector<Node*> nodeStack;
- for(int i=0;i<(int)nodesToRemove->size();i++) {
- nodeStack.push_back((*nodesToRemove)[i]);
- }
- delete nodesToRemove;
+ findNodesOfDegree(1, nodeStack);
+
+ std::set<const LineString*> uniqueDangles;
+
while (!nodeStack.empty()) {
- Node *node=nodeStack[nodeStack.size()-1];
+ Node *node=nodeStack.back();
nodeStack.pop_back();
deleteAllEdges(node);
std::vector<DirectedEdge*> &nodeOutEdges=node->getOutEdges()->getEdges();
@@ -465,13 +465,17 @@
sym->setMarked(true);
// save the line as a dangle
PolygonizeEdge *e=(PolygonizeEdge*) de->getEdge();
- dangleLines.push_back(e->getLine());
+ const LineString* ls = e->getLine();
+ if ( uniqueDangles.insert(ls).second )
+ dangleLines.push_back(ls);
Node *toNode=de->getToNode();
- // add the toNode to the list to be processed, if it is now a dangle
+ // add the toNode to the list to be processed,
+ // if it is now a dangle
if (getDegreeNonDeleted(toNode)==1)
nodeStack.push_back(toNode);
}
}
+
}
} // namespace geos.operation.polygonize
Modified: trunk/src/planargraph/PlanarGraph.cpp
===================================================================
--- trunk/src/planargraph/PlanarGraph.cpp 2010-07-01 20:49:03 UTC (rev 3077)
+++ trunk/src/planargraph/PlanarGraph.cpp 2010-07-01 21:44:33 UTC (rev 3078)
@@ -12,6 +12,10 @@
* by the Free Software Foundation.
* See the COPYING file for more information.
*
+ **********************************************************************
+ *
+ * Last port: planargraph/PlanarGraph.java rev. 107/138 (JTS-1.10)
+ *
**********************************************************************/
#include <geos/planargraph/PlanarGraph.h>
@@ -126,16 +130,21 @@
PlanarGraph::findNodesOfDegree(size_t degree)
{
vector<Node*> *nodesFound=new vector<Node*>();
+ findNodesOfDegree(degree, *nodesFound);
+ return nodesFound;
+}
+
+/*public*/
+void
+PlanarGraph::findNodesOfDegree(size_t degree, vector<Node*>& nodesFound)
+{
NodeMap::container &nm=nodeMap.getNodeMap();
-// NodeMap::container::iterator it=nm.begin();
-// for ( ; it!=nm.end(); ++it)
for (NodeMap::container::iterator it=nm.begin(), itEnd=nm.end();
it!=itEnd; ++it)
{
Node *node=it->second;
- if (node->getDegree()==degree) nodesFound->push_back(node);
+ if (node->getDegree()==degree) nodesFound.push_back(node);
}
- return nodesFound;
}
} // namespace planargraph
More information about the geos-commits
mailing list