operation/polygonize/EdgeRing.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* 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: operation/polygonize/EdgeRing.java 0b3c7e3eb0d3e
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/algorithm/locate/IndexedPointInAreaLocator.h>
#include <geos/operation/polygonize/PolygonizeDirectedEdge.h>
#include <geos/geom/Geometry.h>
#include <geos/geom/LinearRing.h>
#include <geos/geom/Polygon.h>
#include <memory>
#include <vector>
#include <geos/geom/Location.h>
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
#endif
// Forward declarations
namespace geos {
namespace geom {
class LineString;
class CoordinateSequence;
class GeometryFactory;
class Coordinate;
}
namespace planargraph {
class DirectedEdge;
}
}
namespace geos {
namespace operation { // geos::operation
namespace polygonize { // geos::operation::polygonize
class GEOS_DLL EdgeRing {
private:
const geom::GeometryFactory* factory;
typedef std::vector<const PolygonizeDirectedEdge*> DeList;
DeList deList;
// cache the following data for efficiency
std::unique_ptr<geom::LinearRing> ring;
std::unique_ptr<geom::CoordinateSequence> ringPts;
std::unique_ptr<algorithm::locate::PointOnGeometryLocator> ringLocator;
std::unique_ptr<std::vector<std::unique_ptr<geom::LinearRing>>> holes;
EdgeRing* shell = nullptr;
bool is_hole;
bool is_valid = false;
bool is_processed = false;
bool is_included_set = false;
bool is_included = false;
bool visitedByUpdateIncludedRecursive = false;
const geom::CoordinateSequence* getCoordinates();
static void addEdge(const geom::CoordinateSequence* coords,
bool isForward,
geom::CoordinateSequence* coordList);
algorithm::locate::PointOnGeometryLocator* getLocator() {
if (ringLocator == nullptr) {
ringLocator.reset(new algorithm::locate::IndexedPointInAreaLocator(*getRingInternal()));
}
return ringLocator.get();
}
public:
void add(const PolygonizeDirectedEdge* de);
EdgeRing* findEdgeRingContaining(const std::vector<EdgeRing*> & erList);
static std::vector<PolygonizeDirectedEdge*> findDirEdgesInRing(PolygonizeDirectedEdge* startDE);
static const geom::Coordinate& ptNotInList(
const geom::CoordinateSequence* testPts,
const geom::CoordinateSequence* pts);
static bool isInList(const geom::Coordinate& pt,
const geom::CoordinateSequence* pts);
explicit EdgeRing(const geom::GeometryFactory* newFactory);
~EdgeRing() = default;
void build(PolygonizeDirectedEdge* startDE);
void computeHole();
const DeList& getEdges() const {
return deList;
}
bool isHole() const {
return is_hole;
}
/* Indicates whether we know if the ring should be included in a polygonizer
* output of only polygons.
*/
bool isIncludedSet() const {
return is_included_set;
}
/* Indicates whether the ring should be included in a polygonizer output of
* only polygons.
*/
bool isIncluded() const {
return is_included;
}
void setIncluded(bool included) {
is_included = included;
is_included_set = true;
}
bool isProcessed() const {
return is_processed;
}
void setProcessed(bool processed) {
is_processed = processed;
}
void setShell(EdgeRing* shellRing) {
shell = shellRing;
}
bool hasShell() const {
return shell != nullptr;
}
EdgeRing* getShell() {
return isHole() ? shell : this;
}
bool isOuterHole() const {
if (!isHole()) {
return false;
}
return !hasShell();
}
bool isOuterShell() const {
return getOuterHole() != nullptr;
}
EdgeRing* getOuterHole() const;
void updateIncludedRecursive();
void addHole(geom::LinearRing* hole);
void addHole(EdgeRing* holeER);
std::unique_ptr<geom::Polygon> getPolygon();
bool isValid() const;
void computeValid();
std::unique_ptr<geom::LineString> getLineString();
geom::LinearRing* getRingInternal();
std::unique_ptr<geom::LinearRing> getRingOwnership();
bool isInRing(const geom::Coordinate & pt) {
return geom::Location::EXTERIOR != getLocator()->locate(&pt);
}
};
} // namespace geos::operation::polygonize
} // namespace geos::operation
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::algorithm::locate::IndexedPointInAreaLocator
Determines the location of Coordinates relative to an areal geometry, using indexing for efficiency.
Definition IndexedPointInAreaLocator.h:54
geos::algorithm::locate::PointOnGeometryLocator
An interface for classes which determine the Location of points in Polygon or MultiPolygon geometries...
Definition PointOnGeometryLocator.h:36
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::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::LineString
Definition LineString.h:66
geos::geom::LinearRing
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
geos::operation::polygonize::EdgeRing::setShell
void setShell(EdgeRing *shellRing)
Sets the containing shell ring of a ring that has been determined to be a hole.
Definition operation/polygonize/EdgeRing.h:220
geos::operation::polygonize::EdgeRing::isInList
static bool isInList(const geom::Coordinate &pt, const geom::CoordinateSequence *pts)
Tests whether a given point is in an array of points. Uses a value-based test.
geos::operation::polygonize::EdgeRing::getRingInternal
geom::LinearRing * getRingInternal()
Returns this ring as a LinearRing, or null if an Exception occurs while creating it (such as a topolo...
geos::operation::polygonize::EdgeRing::getOuterHole
EdgeRing * getOuterHole() const
Gets the outer hole of a shell, if it has one. An outer hole is one that is not contained in any othe...
geos::operation::polygonize::EdgeRing::isOuterHole
bool isOuterHole() const
Tests whether this ring is an outer hole. A hole is an outer hole if it is not contained by any shell...
Definition operation/polygonize/EdgeRing.h:249
geos::operation::polygonize::EdgeRing::isOuterShell
bool isOuterShell() const
Tests whether this ring is an outer shell.
Definition operation/polygonize/EdgeRing.h:262
geos::operation::polygonize::EdgeRing::getRingOwnership
std::unique_ptr< geom::LinearRing > getRingOwnership()
Returns this ring as a LinearRing, or null if an Exception occurs while creating it (such as a topolo...
geos::operation::polygonize::EdgeRing::addHole
void addHole(geom::LinearRing *hole)
Adds a hole to the polygon formed by this ring.
geos::operation::polygonize::EdgeRing::getPolygon
std::unique_ptr< geom::Polygon > getPolygon()
Computes the Polygon formed by this ring and any contained holes.
geos::operation::polygonize::EdgeRing::ptNotInList
static const geom::Coordinate & ptNotInList(const geom::CoordinateSequence *testPts, const geom::CoordinateSequence *pts)
Finds a point in a list of points which is not contained in another list of points.
geos::operation::polygonize::EdgeRing::findEdgeRingContaining
EdgeRing * findEdgeRingContaining(const std::vector< EdgeRing * > &erList)
Find the innermost enclosing shell EdgeRing containing this, if any.
geos::operation::polygonize::EdgeRing::isHole
bool isHole() const
Tests whether this ring is a hole.
Definition operation/polygonize/EdgeRing.h:184
geos::operation::polygonize::EdgeRing::getShell
EdgeRing * getShell()
Gets the shell for this ring. The shell is the ring itself if it is not a hole, otherwise it is the p...
Definition operation/polygonize/EdgeRing.h:239
geos::operation::polygonize::EdgeRing::isValid
bool isValid() const
Tests if the LinearRing ring formed by this edge ring is topologically valid.
geos::operation::polygonize::EdgeRing::getLineString
std::unique_ptr< geom::LineString > getLineString()
Gets the coordinates for this ring as a LineString.
geos::operation::polygonize::EdgeRing::updateIncludedRecursive
void updateIncludedRecursive()
Updates the included status for currently non-included shells based on whether they are adjacent to a...
geos::operation::polygonize::EdgeRing::hasShell
bool hasShell() const
Tests whether this ring has a shell assigned to it.
Definition operation/polygonize/EdgeRing.h:229
geos::operation::polygonize::EdgeRing::findDirEdgesInRing
static std::vector< PolygonizeDirectedEdge * > findDirEdgesInRing(PolygonizeDirectedEdge *startDE)
Traverses a ring of DirectedEdges, accumulating them into a list.
geos::operation::polygonize::EdgeRing::add
void add(const PolygonizeDirectedEdge *de)
Adds a DirectedEdge which is known to form part of this ring.
geos::operation::polygonize::PolygonizeDirectedEdge
A DirectedEdge of a PolygonizeGraph, which represents an edge of a polygon formed by the graph.
Definition PolygonizeDirectedEdge.h:52
geos::planargraph::DirectedEdge
Represents a directed edge in a PlanarGraph.
Definition planargraph/DirectedEdge.h:45
geos::geom
Definition Angle.h:26
geos::geom::Location::EXTERIOR
@ EXTERIOR
Definition Location.h:57
geos::operation::polygonize
An API for polygonizing sets of lines.
Definition namespaces.h:232
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos::planargraph
Contains classes to implement a planar graph data structure.
Definition namespaces.h:293
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38