[geos-commits] r2463 - in trunk/source:
headers/geos/operation/overlay
headers/geos/operation/overlay/snap operation/overlay
operation/overlay/snap
svn_geos at osgeo.org
svn_geos at osgeo.org
Mon May 4 18:03:12 EDT 2009
Author: strk
Date: 2009-05-04 18:03:12 -0400 (Mon, 04 May 2009)
New Revision: 2463
Added:
trunk/source/headers/geos/operation/overlay/snap/SnapIfNeededOverlayOp.h
trunk/source/operation/overlay/snap/SnapIfNeededOverlayOp.cpp
Modified:
trunk/source/headers/geos/operation/overlay/Makefile.am
trunk/source/headers/geos/operation/overlay/snap/SnapOverlayOp.h
trunk/source/operation/overlay/Makefile.am
Log:
Port SnapIfNeededOverlayOp
Modified: trunk/source/headers/geos/operation/overlay/Makefile.am
===================================================================
--- trunk/source/headers/geos/operation/overlay/Makefile.am 2009-05-04 21:28:26 UTC (rev 2462)
+++ trunk/source/headers/geos/operation/overlay/Makefile.am 2009-05-04 22:03:12 UTC (rev 2463)
@@ -24,6 +24,7 @@
snap/GeometrySnapper.h \
snap/LineStringSnapper.h \
snap/SnapOverlayOp.h \
+ snap/SnapIfNeededOverlayOp.h \
validate/FuzzyPointLocator.h \
validate/OffsetPointGenerator.h \
validate/OverlayResultValidator.h
Added: trunk/source/headers/geos/operation/overlay/snap/SnapIfNeededOverlayOp.h
===================================================================
--- trunk/source/headers/geos/operation/overlay/snap/SnapIfNeededOverlayOp.h (rev 0)
+++ trunk/source/headers/geos/operation/overlay/snap/SnapIfNeededOverlayOp.h 2009-05-04 22:03:12 UTC (rev 2463)
@@ -0,0 +1,118 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ *
+ * 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/overlay/snap/SnapIfNeededOverlayOp.java rev 1.1
+ * (JTS-1.10)
+ *
+ **********************************************************************/
+
+#ifndef GEOS_OP_OVERLAY_SNAP_SNAPIFNEEDEDOVERLAYOP_H
+#define GEOS_OP_OVERLAY_SNAP_SNAPIFNEEDEDOVERLAYOP_H
+
+#include <geos/operation/overlay/OverlayOp.h> // for enums
+
+#include <memory> // for auto_ptr
+
+// Forward declarations
+namespace geos {
+ namespace geom {
+ class Geometry;
+ }
+}
+
+namespace geos {
+namespace operation { // geos::operation
+namespace overlay { // geos::operation::overlay
+namespace snap { // geos::operation::overlay::snap
+
+/** \brief
+ * Performs an overlay operation using snapping and enhanced precision
+ * to improve the robustness of the result.
+ *
+ * This class only uses snapping
+ * if an error is detected when running the standard JTS overlay code.
+ * Errors detected include thrown exceptions
+ * (in particular, {@link TopologyException})
+ * and invalid overlay computations.
+ *
+ */
+class SnapIfNeededOverlayOp
+{
+
+public:
+
+ static std::auto_ptr<geom::Geometry>
+ overlayOp(const geom::Geometry& g0, const geom::Geometry& g1,
+ OverlayOp::OpCode opCode)
+ {
+ SnapIfNeededOverlayOp op(g0, g1);
+ return op.getResultGeometry(opCode);
+ }
+
+ static std::auto_ptr<geom::Geometry>
+ intersection(const geom::Geometry& g0, const geom::Geometry& g1)
+ {
+ return overlayOp(g0, g1, OverlayOp::opINTERSECTION);
+ }
+
+ static std::auto_ptr<geom::Geometry>
+ Union(const geom::Geometry& g0, const geom::Geometry& g1)
+ {
+ return overlayOp(g0, g1, OverlayOp::opUNION);
+ }
+
+ static std::auto_ptr<geom::Geometry>
+ difference(const geom::Geometry& g0, const geom::Geometry& g1)
+ {
+ return overlayOp(g0, g1, OverlayOp::opDIFFERENCE);
+ }
+
+ static std::auto_ptr<geom::Geometry>
+ symDifference(const geom::Geometry& g0, const geom::Geometry& g1)
+ {
+ return overlayOp(g0, g1, OverlayOp::opSYMDIFFERENCE);
+ }
+
+ SnapIfNeededOverlayOp(const geom::Geometry& g1, const geom::Geometry& g2)
+ :
+ geom0(g1),
+ geom1(g2)
+ {
+ }
+
+
+ typedef std::auto_ptr<geom::Geometry> GeomPtr;
+
+ GeomPtr getResultGeometry(OverlayOp::OpCode opCode);
+
+private:
+
+ const geom::Geometry& geom0;
+ const geom::Geometry& geom1;
+
+};
+
+
+} // namespace geos::operation::overlay::snap
+} // namespace geos::operation::overlay
+} // namespace geos::operation
+} // namespace geos
+
+#endif // ndef GEOS_OP_OVERLAY_SNAP_SNAPIFNEEDEDOVERLAYOP_H
+
+/**********************************************************************
+ * $Log$
+ **********************************************************************/
+
Modified: trunk/source/headers/geos/operation/overlay/snap/SnapOverlayOp.h
===================================================================
--- trunk/source/headers/geos/operation/overlay/snap/SnapOverlayOp.h 2009-05-04 21:28:26 UTC (rev 2462)
+++ trunk/source/headers/geos/operation/overlay/snap/SnapOverlayOp.h 2009-05-04 22:03:12 UTC (rev 2463)
@@ -22,18 +22,13 @@
#include <geos/operation/overlay/OverlayOp.h> // for enums
#include <geos/precision/CommonBitsRemover.h> // for dtor visibility by auto_ptr
-//#include <geos/geom/LineSegment.h> // for composition
-//#include <geos/geom/LineString.h> // for inlined ctor
-//#include <vector>
#include <memory> // for auto_ptr
// Forward declarations
namespace geos {
namespace geom {
class Geometry;
- //class Coordinate;
- //class CoordinateSequence;
}
}
Modified: trunk/source/operation/overlay/Makefile.am
===================================================================
--- trunk/source/operation/overlay/Makefile.am 2009-05-04 21:28:26 UTC (rev 2462)
+++ trunk/source/operation/overlay/Makefile.am 2009-05-04 22:03:12 UTC (rev 2463)
@@ -18,6 +18,7 @@
snap/GeometrySnapper.cpp \
snap/LineStringSnapper.cpp \
snap/SnapOverlayOp.cpp \
+ snap/SnapIfNeededOverlayOp.cpp \
validate/FuzzyPointLocator.cpp \
validate/OffsetPointGenerator.cpp \
validate/OverlayResultValidator.cpp
Added: trunk/source/operation/overlay/snap/SnapIfNeededOverlayOp.cpp
===================================================================
--- trunk/source/operation/overlay/snap/SnapIfNeededOverlayOp.cpp (rev 0)
+++ trunk/source/operation/overlay/snap/SnapIfNeededOverlayOp.cpp 2009-05-04 22:03:12 UTC (rev 2463)
@@ -0,0 +1,82 @@
+/**********************************************************************
+ * $Id$
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.refractions.net
+ *
+ * Copyright (C) 2009 Sandro Santilli <strk at keybit.net>
+ *
+ * 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/overlay/snap/SnapIfNeededOverlayOp.java rev 1.1
+ * (JTS-1.10)
+ *
+ **********************************************************************/
+
+#include <geos/operation/overlay/snap/SnapIfNeededOverlayOp.h>
+#include <geos/operation/overlay/snap/SnapOverlayOp.h>
+#include <geos/operation/overlay/OverlayOp.h>
+#include <geos/geom/Geometry.h> // for use in auto_ptr
+
+#include <cassert>
+#include <limits> // for numeric_limits
+#include <memory> // for auto_ptr
+
+#ifndef GEOS_DEBUG
+#define GEOS_DEBUG 0
+#endif
+
+using namespace std;
+using namespace geos::geom;
+
+namespace geos {
+namespace operation { // geos.operation
+namespace overlay { // geos.operation.overlay
+namespace snap { // geos.operation.overlay.snap
+
+/* public */
+auto_ptr<Geometry>
+SnapIfNeededOverlayOp::getResultGeometry(OverlayOp::OpCode opCode)
+{
+ auto_ptr<Geometry> result;
+
+ bool isSuccess = false;
+
+ try {
+ result.reset( OverlayOp::overlayOp(&geom0, &geom1, opCode) );
+ bool isValid = true;
+
+ // not needed if noding validation is used
+ // bool isValid = OverlayResultValidator::isValid(
+ // geom0, geom1, OverlayOp::INTERSECTION,
+ // result);
+
+ if (isValid) isSuccess = true;
+
+ }
+ catch (std::exception& ex) {
+ // ignore this exception, since the operation will be rerun
+ // System.out.println(ex.getMessage());
+ // ex.printStackTrace();
+ std::cerr << "Overlay op threw " << ex.what() << ". Will try snapping now" << std::endl;
+ }
+
+ if (! isSuccess) {
+ // this may still throw an exception - just let it go if it does
+ result = SnapOverlayOp::overlayOp(geom0, geom1, opCode);
+ }
+
+ return result;
+}
+
+
+} // namespace geos.operation.snap
+} // namespace geos.operation.overlay
+} // namespace geos.operation
+} // namespace geos
+
More information about the geos-commits
mailing list