[geos-commits] r2314 - trunk/source/operation/valid

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Apr 7 05:56:44 EDT 2009


Author: strk
Date: 2009-04-07 05:56:43 -0400 (Tue, 07 Apr 2009)
New Revision: 2314

Added:
   trunk/source/operation/valid/IndexedNestedRingTester.cpp
   trunk/source/operation/valid/IndexedNestedRingTester.h
Modified:
   trunk/source/operation/valid/IsValidOp.cpp
   trunk/source/operation/valid/Makefile.am
Log:
Port IndexedNestedRingTester and have IsValidOp use it, syncing the operation to JTS-1.9


Added: trunk/source/operation/valid/IndexedNestedRingTester.cpp
===================================================================
--- trunk/source/operation/valid/IndexedNestedRingTester.cpp	                        (rev 0)
+++ trunk/source/operation/valid/IndexedNestedRingTester.cpp	2009-04-07 09:56:43 UTC (rev 2314)
@@ -0,0 +1,109 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Safe Software Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: operation/valid/IndexedNestedRingTester.java rev. 1.1 (JTS-1.9)
+ *
+ **********************************************************************/
+
+#include "IndexedNestedRingTester.h"
+
+#include <geos/geom/LinearRing.h> // for use
+#include <geos/algorithm/CGAlgorithms.h> // for use
+#include <geos/operation/valid/IsValidOp.h> // for use (findPtNotNode)
+#include <geos/index/strtree/STRtree.h> // for use
+
+// Forward declarations
+namespace geos {
+	namespace geom {
+		class CoordinateSequence;
+		class Envelope;
+	}
+}
+
+namespace geos {
+namespace operation { // geos.operation
+namespace valid { // geos.operation.valid
+
+bool
+IndexedNestedRingTester::isNonNested()
+{
+	buildIndex();
+
+	for (size_t i=0, n=rings.size(); i<n; ++i)
+	{
+		const geom::LinearRing* innerRing = rings[i];
+		const geom::CoordinateSequence *innerRingPts=innerRing->getCoordinates();
+		std::vector<void*> results;
+		index->query(innerRing->getEnvelopeInternal(), results);
+		for (size_t j=0, jn=results.size(); j<jn; ++j)
+		{
+			geom::LinearRing* searchRing = static_cast<geom::LinearRing*>(results[j]);
+			geom::CoordinateSequence *searchRingPts=searchRing->getCoordinates();
+
+			if (innerRing==searchRing)
+				continue;
+
+			if (!innerRing->getEnvelopeInternal()->intersects(
+				searchRing->getEnvelopeInternal()))
+			{
+				continue;
+			}
+
+                        const geom::Coordinate *innerRingPt =
+				IsValidOp::findPtNotNode(innerRingPts,
+							 searchRing,
+							 graph);
+
+                        // Unable to find a ring point not a node of
+			// the search ring
+			assert(innerRingPt!=NULL);
+
+			bool isInside = algorithm::CGAlgorithms::isPointInRing(	
+					*innerRingPt, searchRingPts);
+
+			if (isInside) {
+				nestedPt = innerRingPt;
+				return false;
+			}
+
+		}
+	}
+
+	return true;
+}
+
+IndexedNestedRingTester::~IndexedNestedRingTester()
+{
+	delete index;
+	//delete totalEnv;
+}
+
+void
+IndexedNestedRingTester::buildIndex()
+{
+	delete index;
+
+	index = new index::strtree::STRtree();
+	for (size_t i=0, n=rings.size(); i<n; ++i)
+	{
+		const geom::LinearRing* ring = rings[i];
+		const geom::Envelope* env = ring->getEnvelopeInternal();
+		index->insert(env, (void*)ring);
+	}
+}
+
+} // namespace geos.operation.valid
+} // namespace geos.operation
+} // namespace geos

Added: trunk/source/operation/valid/IndexedNestedRingTester.h
===================================================================
--- trunk/source/operation/valid/IndexedNestedRingTester.h	                        (rev 0)
+++ trunk/source/operation/valid/IndexedNestedRingTester.h	2009-04-07 09:56:43 UTC (rev 2314)
@@ -0,0 +1,113 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Safe Software Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************
+ *
+ * Last port: operation/valid/IndexedNestedRingTester.java rev. 1.1 (JTS-1.9)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_OP_VALID_OFFSETCURVEVERTEXLIST_H
+#define GEOS_OP_VALID_OFFSETCURVEVERTEXLIST_H
+
+#include <vector> // for composition
+
+// Forward declarations
+namespace geos {
+	namespace geom {
+		//class Envelope;
+		class Coordinate;
+		class LinearRing;
+	}
+	namespace index {
+		class SpatialIndex;
+	}
+	namespace geomgraph {
+		class GeometryGraph;
+	}
+}
+
+namespace geos {
+namespace operation { // geos.operation
+namespace valid { // geos.operation.valid
+
+/** \brief
+ * Tests whether any of a set of {@link LinearRing}s are
+ * nested inside another ring in the set, using a spatial
+ * index to speed up the comparisons.
+ *
+ */
+class IndexedNestedRingTester
+{
+public:
+	// @param newGraph : ownership retained by caller
+	IndexedNestedRingTester(geomgraph::GeometryGraph* newGraph)
+		:
+		graph(newGraph),
+		//totalEnv(0),
+		index(0),
+		nestedPt(0)
+	{
+	}
+
+	~IndexedNestedRingTester();
+
+	/*
+	 * Be aware that the returned Coordinate (if != NULL)
+	 * will point to storage owned by one of the LinearRing
+	 * previously added. If you destroy them, this
+	 * will point to an invalid memory address.
+	 */
+	const geom::Coordinate* getNestedPoint() const
+	{
+		return nestedPt;
+	}
+
+	/// @param ring : ownership retained by caller
+	void add(const geom::LinearRing* ring)
+	{
+		rings.push_back(ring);
+	}
+
+	bool isNonNested();
+
+private:
+
+	/// Externally owned
+	geomgraph::GeometryGraph* graph; 
+
+	/// Ownership of this vector elements are externally owned
+	std::vector<const geom::LinearRing*> rings;
+
+	// CHECK: Owned by (seems unused)?
+	//geom::Envelope* totalEnv; 
+
+	// Owned by us (use auto_ptr ?)
+	geos::index::SpatialIndex* index; // 'index' in JTS
+
+	// Externally owned, if not null
+	const geom::Coordinate *nestedPt; 
+
+	void buildIndex();
+};
+
+} // namespace geos.operation.valid
+} // namespace geos.operation
+} // namespace geos
+
+#endif // GEOS_OP_VALID_OFFSETCURVEVERTEXLIST_H
+
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+

Modified: trunk/source/operation/valid/IsValidOp.cpp
===================================================================
--- trunk/source/operation/valid/IsValidOp.cpp	2009-04-07 09:55:45 UTC (rev 2313)
+++ trunk/source/operation/valid/IsValidOp.cpp	2009-04-07 09:56:43 UTC (rev 2314)
@@ -14,14 +14,16 @@
  *
  **********************************************************************
  *
- * Last port: operation/valid/IsValidOp.java rev. 1.39 (JTS-1.7)
+ * Last port: operation/valid/IsValidOp.java rev. 1.41 (JTS-1.9)
  *
  **********************************************************************/
 
+#include "IndexedNestedRingTester.h"
+
 #include <geos/operation/valid/IsValidOp.h>
 #include <geos/operation/valid/ConsistentAreaTester.h>
-#include <geos/operation/valid/QuadtreeNestedRingTester.h>
 #include <geos/operation/valid/ConnectedInteriorTester.h>
+#include <geos/operation/valid/ConnectedInteriorTester.h>
 #include <geos/util/UnsupportedOperationException.h>
 #include <geos/geomgraph/index/SegmentIntersector.h> 
 #include <geos/geomgraph/GeometryGraph.h> 
@@ -401,7 +403,8 @@
 {
 	//SimpleNestedRingTester nestedTester(graph);
 	//SweeplineNestedRingTester nestedTester(graph);
-	QuadtreeNestedRingTester nestedTester(graph);
+	//QuadtreeNestedRingTester nestedTester(graph);
+	IndexedNestedRingTester nestedTester(graph);
 
 	int nholes=p->getNumInteriorRing();
 	for(int i=0; i<nholes; ++i)

Modified: trunk/source/operation/valid/Makefile.am
===================================================================
--- trunk/source/operation/valid/Makefile.am	2009-04-07 09:55:45 UTC (rev 2313)
+++ trunk/source/operation/valid/Makefile.am	2009-04-07 09:56:43 UTC (rev 2314)
@@ -16,7 +16,9 @@
 	RepeatedPointTester.cpp \
 	SimpleNestedRingTester.cpp \
 	SweeplineNestedRingTester.cpp \
-	TopologyValidationError.cpp 
+	TopologyValidationError.cpp \
+	IndexedNestedRingTester.cpp \
+	IndexedNestedRingTester.h
 
 libopvalid_la_LIBADD =
 



More information about the geos-commits mailing list