[geos-commits] r3140 - in trunk: include/geos/operation/overlay/snap
src/operation/overlay/snap
svn_geos at osgeo.org
svn_geos at osgeo.org
Thu Dec 2 04:36:16 EST 2010
Author: strk
Date: 2010-12-02 01:36:16 -0800 (Thu, 02 Dec 2010)
New Revision: 3140
Modified:
trunk/include/geos/operation/overlay/snap/GeometrySnapper.h
trunk/src/operation/overlay/snap/GeometrySnapper.cpp
Log:
Take GeometrySnapper forward to r309 (JTS-1.11+): add self-snapping
Modified: trunk/include/geos/operation/overlay/snap/GeometrySnapper.h
===================================================================
--- trunk/include/geos/operation/overlay/snap/GeometrySnapper.h 2010-11-30 08:31:28 UTC (rev 3139)
+++ trunk/include/geos/operation/overlay/snap/GeometrySnapper.h 2010-12-02 09:36:16 UTC (rev 3140)
@@ -14,7 +14,7 @@
*
***********************************************************************
*
- * Last port: operation/overlay/snap/GeometrySnapper.java rev 1.8 (JTS-1.10)
+ * Last port: operation/overlay/snap/GeometrySnapper.java r309 (JTS-1.11+)
*
**********************************************************************/
@@ -41,8 +41,19 @@
namespace snap { // geos::operation::overlay::snap
/** \brief
- * Snaps the vertices and segments of a geometry to another's vertices.
- * Should improve robustness for overlay operations.
+ * Snaps the vertices and segments of a {@link Geometry}
+ * to another Geometry's vertices.
+ *
+ * A snap distance tolerance is used to control where snapping is performed.
+ * Snapping one geometry to another can improve
+ * robustness for overlay operations by eliminating
+ * nearly-coincident edges
+ * (which cause problems during noding and intersection calculation).
+ * Too much snapping can result in invalid topology
+ * beging created, so the number and location of snapped vertices
+ * is decided using heuristics to determine when it
+ * is safe to snap.
+ * This can result in some potential snaps being omitted, however.
*/
class GEOS_DLL GeometrySnapper {
@@ -64,6 +75,9 @@
const geom::Geometry& g1,
double snapTolerance, GeomPtrPair& ret);
+ static GeomPtr snapToSelf(const geom::Geometry& g0,
+ double snapTolerance, bool cleanResult);
+
/**
* Creates a new snapper acting on the given geometry
*
@@ -88,6 +102,18 @@
double snapTolerance);
/** \brief
+ * Snaps the vertices in the component {@link LineString}s
+ * of the source geometry to the vertices of itself
+ * with a given snap tolerance and optionally cleaning the result.
+ *
+ * @param snapTolerance
+ * @param cleanResult clean the result
+ * @return a new snapped Geometry
+ */
+ std::auto_ptr<geom::Geometry> snapToSelf(double snapTolerance,
+ bool cleanResult);
+
+ /** \brief
* Estimates the snap tolerance for a Geometry, taking into account
* its precision model.
*
Modified: trunk/src/operation/overlay/snap/GeometrySnapper.cpp
===================================================================
--- trunk/src/operation/overlay/snap/GeometrySnapper.cpp 2010-11-30 08:31:28 UTC (rev 3139)
+++ trunk/src/operation/overlay/snap/GeometrySnapper.cpp 2010-12-02 09:36:16 UTC (rev 3140)
@@ -14,7 +14,7 @@
*
***********************************************************************
*
- * Last port: operation/overlay/snap/GeometrySnapper.java rev 1.8 (JTS-1.10)
+ * Last port: operation/overlay/snap/GeometrySnapper.java r309 (JTS-1.11+)
*
**********************************************************************/
@@ -22,6 +22,8 @@
#include <geos/operation/overlay/snap/LineStringSnapper.h>
#include <geos/geom/util/GeometryTransformer.h> // inherit. of SnapTransformer
#include <geos/geom/CoordinateSequence.h>
+#include <geos/geom/Polygon.h>
+#include <geos/geom/MultiPolygon.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/CoordinateSequenceFactory.h>
@@ -41,7 +43,7 @@
namespace overlay { // geos.operation.overlay
namespace snap { // geos.operation.overlay.snap
-const double GeometrySnapper::snapPrecisionFactor = 10e-10;
+const double GeometrySnapper::snapPrecisionFactor = 1e-9;
class SnapTransformer: public geos::geom::util::GeometryTransformer {
@@ -115,6 +117,33 @@
return snapTrans->transform(&srcGeom);
}
+/*public*/
+std::auto_ptr<geom::Geometry>
+GeometrySnapper::snapToSelf(double snapTolerance, bool cleanResult)
+{
+
+ using std::auto_ptr;
+ using geom::util::GeometryTransformer;
+
+ // Get snap points
+ auto_ptr<Coordinate::ConstVect> snapPts=extractTargetCoordinates(srcGeom);
+
+ // Apply a SnapTransformer to source geometry
+ // (we need a pointer for dynamic polymorphism)
+ auto_ptr<GeometryTransformer> snapTrans(new SnapTransformer(snapTolerance, *snapPts));
+
+ GeomPtr result = snapTrans->transform(&srcGeom);
+
+ if (cleanResult && ( dynamic_cast<const Polygon*>(result.get()) ||
+ dynamic_cast<const MultiPolygon*>(result.get()) ) )
+ {
+ // TODO: use better cleaning approach
+ result.reset(result->buffer(0));
+ }
+
+ return result;
+}
+
/*public static*/
double
GeometrySnapper::computeSizeBasedSnapTolerance(const geom::Geometry& g)
@@ -169,13 +198,12 @@
GeometrySnapper snapper0(g0);
snapGeom.first = snapper0.snapTo(g1, snapTolerance);
- GeometrySnapper snapper1(g1);
-
/**
* Snap the second geometry to the snapped first geometry
* (this strategy minimizes the number of possible different
* points in the result)
*/
+ GeometrySnapper snapper1(g1);
snapGeom.second = snapper1.snapTo(*snapGeom.first, snapTolerance);
// cout << *snapGeom.first << endl;
@@ -183,6 +211,15 @@
}
+/* public static */
+GeometrySnapper::GeomPtr
+GeometrySnapper::snapToSelf(const geom::Geometry& g,
+ double snapTolerance,
+ bool cleanResult)
+{
+ GeometrySnapper snapper0(g);
+ return snapper0.snapToSelf(snapTolerance, cleanResult);
+}
} // namespace geos.operation.snap
} // namespace geos.operation.overlay
More information about the geos-commits
mailing list