NodedSegmentString.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions 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: noding/NodedSegmentString.java r320 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/algorithm/LineIntersector.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/CoordinateSequence.h> // for inlines
#include <geos/noding/NodedSegmentString.h>
#include <geos/noding/NodableSegmentString.h> // for inheritance
#include <geos/noding/SegmentNode.h>
#include <geos/noding/SegmentNodeList.h>
#include <geos/noding/SegmentString.h>
#include <geos/util/IllegalArgumentException.h>
#include <cstddef>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251 4355) // warning C4355: 'this' : used in base member initializer list
#endif
namespace geos {
namespace noding { // geos::noding
class GEOS_DLL NodedSegmentString : public NodableSegmentString {
public:
// TODO: provide a templated method using an output iterator
template <class II>
static void
getNodedSubstrings(II from, II too_far,
SegmentString::NonConstVect* resultEdgelist)
{
for(II i = from; i != too_far; ++i) {
NodedSegmentString* nss = dynamic_cast<NodedSegmentString*>(*i);
assert(nss);
nss->getNodeList().addSplitEdges(resultEdgelist);
}
}
template <class C>
static void
getNodedSubstrings(C* segStrings,
SegmentString::NonConstVect* resultEdgelist)
{
getNodedSubstrings(segStrings->begin(), segStrings->end(), resultEdgelist);
}
static void getNodedSubstrings(const SegmentString::NonConstVect& segStrings,
SegmentString::NonConstVect* resultEdgeList);
static SegmentString::NonConstVect* getNodedSubstrings(
const SegmentString::NonConstVect& segStrings);
std::unique_ptr<geom::CoordinateSequence> getNodedCoordinates();
bool hasNodes() const
{
return nodeList.size() > 0;
}
NodedSegmentString(geom::CoordinateSequence* newPts, bool constructZ, bool constructM, const void* newContext)
: NodableSegmentString(newContext, newPts)
, nodeList(*this, constructZ, constructM)
{}
NodedSegmentString(SegmentString* ss, bool constructZ, bool constructM)
: NodableSegmentString(ss->getData(), ss->getCoordinates()->clone().release())
, nodeList(*this, constructZ, constructM)
{}
~NodedSegmentString() override {
delete seq;
}
SegmentNodeList& getNodeList();
const SegmentNodeList& getNodeList() const;
std::unique_ptr<geom::CoordinateSequence> releaseCoordinates();
std::ostream& print(std::ostream& os) const override;
void addIntersections(algorithm::LineIntersector* li,
std::size_t segmentIndex, std::size_t geomIndex)
{
for (std::size_t i = 0, n = li->getIntersectionNum(); i < n; ++i) {
addIntersection(li, segmentIndex, geomIndex, i);
}
};
void addIntersection(algorithm::LineIntersector* li,
std::size_t segmentIndex,
std::size_t geomIndex, std::size_t intIndex)
{
::geos::ignore_unused_variable_warning(geomIndex);
const auto& intPt = li->getIntersection(intIndex);
addIntersection(intPt, segmentIndex);
};
template<typename CoordType>
void addIntersection(const CoordType& intPt,
std::size_t segmentIndex)
{
std::size_t normalizedSegmentIndex = segmentIndex;
if (segmentIndex > size() - 2) {
throw util::IllegalArgumentException("SegmentString::addIntersection: SegmentIndex out of range");
}
// normalize the intersection point location
auto nextSegIndex = normalizedSegmentIndex + 1;
if (nextSegIndex < size()) {
const auto& nextPt = getCoordinate<geom::CoordinateXY>(nextSegIndex);
// Normalize segment index if intPt falls on vertex
// The check for point equality is 2D only -
// Z values are ignored
if(intPt.equals2D(nextPt)) {
normalizedSegmentIndex = nextSegIndex;
}
}
/*
* Add the intersection point to edge intersection list
* (unless the node is already known)
*/
nodeList.add(intPt, normalizedSegmentIndex);
}
private:
SegmentNodeList nodeList;
};
} // namespace geos::noding
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::algorithm::LineIntersector
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:53
geos::algorithm::LineIntersector::getIntersection
const geom::CoordinateXYZM & getIntersection(std::size_t intIndex) const
Definition LineIntersector.h:209
geos::algorithm::LineIntersector::getIntersectionNum
size_t getIntersectionNum() const
Definition LineIntersector.h:196
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::noding::NodableSegmentString
An interface for classes which support adding nodes to a segment string.
Definition NodableSegmentString.h:36
geos::noding::NodedSegmentString
Represents a list of contiguous line segments, and supports noding the segments.
Definition NodedSegmentString.h:58
geos::noding::NodedSegmentString::getNodedSubstrings
static SegmentString::NonConstVect * getNodedSubstrings(const SegmentString::NonConstVect &segStrings)
Returns allocated object.
geos::noding::NodedSegmentString::addIntersection
void addIntersection(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex, std::size_t intIndex)
Add an SegmentNode for intersection intIndex.
Definition NodedSegmentString.h:149
geos::noding::NodedSegmentString::NodedSegmentString
NodedSegmentString(geom::CoordinateSequence *newPts, bool constructZ, bool constructM, const void *newContext)
Creates a new segment string from a list of vertices.
Definition NodedSegmentString.h:106
geos::noding::NodedSegmentString::addIntersection
void addIntersection(const CoordType &intPt, std::size_t segmentIndex)
Add an SegmentNode for intersection intIndex.
Definition NodedSegmentString.h:167
geos::noding::NodedSegmentString::addIntersections
void addIntersections(algorithm::LineIntersector *li, std::size_t segmentIndex, std::size_t geomIndex)
Add SegmentNodes for one or both intersections found for a segment of an edge to the edge intersectio...
Definition NodedSegmentString.h:134
geos::noding::SegmentNodeList
A list of the SegmentNode present along a NodedSegmentString.
Definition SegmentNodeList.h:54
geos::noding::SegmentNodeList::addSplitEdges
void addSplitEdges(std::vector< SegmentString * > &edgeList)
geos::noding::SegmentString
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
geos::util::IllegalArgumentException
Indicates one or more illegal arguments.
Definition IllegalArgumentException.h:33
geos::noding
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition CoverageCleaner.h:42
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38