GEOS
3.4.2
|
00001 /********************************************************************** 00002 * 00003 * GEOS - Geometry Engine Open Source 00004 * http://geos.osgeo.org 00005 * 00006 * Copyright (C) 2009-2010 Sandro Santilli <strk@keybit.net> 00007 * Copyright (C) 2006 Refractions Research Inc. 00008 * 00009 * This is free software; you can redistribute and/or modify it under 00010 * the terms of the GNU Lesser General Public Licence as published 00011 * by the Free Software Foundation. 00012 * See the COPYING file for more information. 00013 * 00014 *********************************************************************** 00015 * 00016 * Last port: operation/overlay/snap/LineStringSnapper.java r320 (JTS-1.12) 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H 00021 #define GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H 00022 00023 #include <geos/geom/Coordinate.h> 00024 #include <geos/geom/CoordinateSequence.h> 00025 #include <geos/geom/CoordinateList.h> 00026 00027 #include <memory> 00028 00029 // Forward declarations 00030 namespace geos { 00031 namespace geom { 00032 //class PrecisionModel; 00033 //class CoordinateSequence; 00034 class CoordinateList; 00035 class Geometry; 00036 } 00037 } 00038 00039 namespace geos { 00040 namespace operation { // geos::operation 00041 namespace overlay { // geos::operation::overlay 00042 namespace snap { // geos::operation::overlay::snap 00043 00051 class GEOS_DLL LineStringSnapper { 00052 00053 public: 00054 00062 LineStringSnapper(const geom::Coordinate::Vect& nSrcPts, 00063 double nSnapTol) 00064 : 00065 srcPts(nSrcPts), 00066 snapTolerance(nSnapTol), 00067 allowSnappingToSourceVertices(false) 00068 { 00069 size_t s = srcPts.size(); 00070 isClosed = s < 2 ? false : srcPts[0].equals2D(srcPts[s-1]); 00071 } 00072 00073 // Snap points are assumed to be all distinct points (a set would be better, uh ?) 00074 std::auto_ptr<geom::Coordinate::Vect> snapTo(const geom::Coordinate::ConstVect& snapPts); 00075 00076 void setAllowSnappingToSourceVertices(bool allow) { 00077 allowSnappingToSourceVertices = allow; 00078 } 00079 00080 private: 00081 00082 const geom::Coordinate::Vect& srcPts; 00083 00084 double snapTolerance; 00085 00086 bool allowSnappingToSourceVertices; 00087 bool isClosed; 00088 00089 00090 // Modifies first arg 00091 void snapVertices(geom::CoordinateList& srcCoords, 00092 const geom::Coordinate::ConstVect& snapPts); 00093 00094 00095 // Returns snapPts.end() if no snap point is close enough (within snapTol distance) 00096 geom::Coordinate::ConstVect::const_iterator findSnapForVertex(const geom::Coordinate& pt, 00097 const geom::Coordinate::ConstVect& snapPts); 00098 00114 void snapSegments(geom::CoordinateList& srcCoords, 00115 const geom::Coordinate::ConstVect& snapPts); 00116 00120 // 00144 geom::CoordinateList::iterator findSegmentToSnap( 00145 const geom::Coordinate& snapPt, 00146 geom::CoordinateList::iterator from, 00147 geom::CoordinateList::iterator too_far); 00148 00149 geom::CoordinateList::iterator findVertexToSnap( 00150 const geom::Coordinate& snapPt, 00151 geom::CoordinateList::iterator from, 00152 geom::CoordinateList::iterator too_far); 00153 00154 // Declare type as noncopyable 00155 LineStringSnapper(const LineStringSnapper& other); 00156 LineStringSnapper& operator=(const LineStringSnapper& rhs); 00157 }; 00158 00159 00160 } // namespace geos::operation::overlay::snap 00161 } // namespace geos::operation::overlay 00162 } // namespace geos::operation 00163 } // namespace geos 00164 00165 #endif // GEOS_OP_OVERLAY_SNAP_LINESTRINGSNAPPER_H 00166