LineStringSnapper.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2009-2010 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2006 Refractions Research 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/overlay/snap/LineStringSnapper.java r320 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h>
#include <geos/geom/CoordinateList.h>
#include <memory>
// Forward declarations
namespace geos {
namespace geom {
//class PrecisionModel;
//class CoordinateSequence;
class CoordinateList;
class Geometry;
}
}
namespace geos {
namespace operation { // geos::operation
namespace overlay { // geos::operation::overlay
namespace snap { // geos::operation::overlay::snap
class GEOS_DLL LineStringSnapper {
public:
LineStringSnapper(const geom::CoordinateSequence& nSrcPts,
double nSnapTol)
:
srcPts(nSrcPts),
snapTolerance(nSnapTol),
allowSnappingToSourceVertices(false)
{
std::size_t s = srcPts.size();
isClosed = s < 2 ? false : srcPts[0].equals2D(srcPts[s - 1]);
}
// Snap points are assumed to be all distinct points (a set would be better, uh ?)
std::unique_ptr<geom::CoordinateSequence> snapTo(const geom::Coordinate::ConstVect& snapPts);
void
setAllowSnappingToSourceVertices(bool allow)
{
allowSnappingToSourceVertices = allow;
}
private:
const geom::CoordinateSequence& srcPts;
double snapTolerance;
bool allowSnappingToSourceVertices;
bool isClosed;
// Modifies first arg
void snapVertices(geom::CoordinateList& srcCoords,
const geom::Coordinate::ConstVect& snapPts);
// Returns snapPts.end() if no snap point is close enough (within snapTol distance)
geom::Coordinate::ConstVect::const_iterator findSnapForVertex(const geom::Coordinate& pt,
const geom::Coordinate::ConstVect& snapPts);
void snapSegments(geom::CoordinateList& srcCoords,
const geom::Coordinate::ConstVect& snapPts);
geom::CoordinateList::iterator findSegmentToSnap(
const geom::Coordinate& snapPt,
geom::CoordinateList::iterator from,
geom::CoordinateList::iterator too_far);
geom::CoordinateList::iterator findVertexToSnap(
const geom::Coordinate& snapPt,
geom::CoordinateList::iterator from,
geom::CoordinateList::iterator too_far);
// Declare type as noncopyable
LineStringSnapper(const LineStringSnapper& other) = delete;
LineStringSnapper& operator=(const LineStringSnapper& rhs) = delete;
};
} // namespace geos::operation::overlay::snap
} // namespace geos::operation::overlay
} // namespace geos::operation
} // namespace geos
geos::geom::CoordinateList
A list of Coordinates, which may be set to prevent repeated coordinates from occurring in the list.
Definition CoordinateList.h:56
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::Coordinate::ConstVect
std::vector< const Coordinate * > ConstVect
A vector of const Coordinate pointers.
Definition Coordinate.h:229
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::operation::overlay::snap::LineStringSnapper::LineStringSnapper
LineStringSnapper(const geom::CoordinateSequence &nSrcPts, double nSnapTol)
Definition LineStringSnapper.h:61
geos::geom
Definition Angle.h:26
geos::operation::overlay
Contains classes that perform a topological overlay to compute boolean spatial functions.
Definition namespaces.h:229
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38