1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2009 Sandro Santilli <strk@kbt.io>
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
13 ***********************************************************************
15 * Last port: operation/overlay/snap/SnapOverlayOp.java r320 (JTS-1.12)
17 **********************************************************************/
19 #include <geos/operation/overlay/snap/SnapOverlayOp.h>
20 #include <geos/operation/overlay/snap/GeometrySnapper.h>
21 #include <geos/precision/CommonBitsRemover.h>
22 #include <geos/geom/Geometry.h>
25 #include <limits> // for numeric_limits
26 #include <memory> // for auto_ptr
33 using namespace geos::geom
;
36 namespace operation
{ // geos.operation
37 namespace overlay
{ // geos.operation.overlay
38 namespace snap
{ // geos.operation.overlay.snap
42 SnapOverlayOp::computeSnapTolerance()
44 snapTolerance
= GeometrySnapper::computeOverlaySnapTolerance(geom0
,
47 // cout << "Snap tol = " << snapTolerance << endl;
52 SnapOverlayOp::getResultGeometry(OverlayOp::OpCode opCode
)
54 geom::GeomPtrPair prepGeom
;
56 GeomPtr
result ( OverlayOp::overlayOp(prepGeom
.first
.get(),
57 prepGeom
.second
.get(), opCode
) );
58 prepareResult(*result
);
64 SnapOverlayOp::snap(geom::GeomPtrPair
& snapGeom
)
66 geom::GeomPtrPair remGeom
;
67 removeCommonBits(geom0
, geom1
, remGeom
);
69 GeometrySnapper::snap(*remGeom
.first
, *remGeom
.second
,
70 snapTolerance
, snapGeom
);
72 // MD - may want to do this at some point, but it adds cycles
73 // checkValid(snapGeom[0]);
74 // checkValid(snapGeom[1]);
77 System.out.println("Snapped geoms: ");
78 System.out.println(snapGeom[0]);
79 System.out.println(snapGeom[1]);
86 SnapOverlayOp::removeCommonBits(const geom::Geometry
& geom0
,
87 const geom::Geometry
& geom1
,
88 geom::GeomPtrPair
& remGeom
)
90 cbr
.reset(new precision::CommonBitsRemover());
94 remGeom
.first
.reset( cbr
->removeCommonBits(geom0
.clone()) );
95 remGeom
.second
.reset( cbr
->removeCommonBits(geom1
.clone()) );
100 SnapOverlayOp::prepareResult(geom::Geometry
& geom
)
102 cbr
->addCommonBits(&geom
);
106 } // namespace geos.operation.snap
107 } // namespace geos.operation.overlay
108 } // namespace geos.operation