RelateGeometry.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (c) 2024 Martin Davis
* Copyright (C) 2024 Paul Ramsey <pramsey@cleverelephant.ca>
*
* 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.
*
**********************************************************************/
#pragma once
#include <geos/algorithm/BoundaryNodeRule.h>
#include <geos/geom/Coordinate.h>
#include <geos/geom/Dimension.h>
#include <geos/geom/Location.h>
#include <geos/operation/relateng/RelatePointLocator.h>
#include <geos/operation/relateng/RelateSegmentString.h>
#include <geos/export.h>
#include <string>
#include <sstream>
// Forward declarations
namespace geos {
namespace geom {
class CoordinateSequence;
class Envelope;
class Geometry;
class LinearRing;
class LineString;
class MultiPolygon;
class Point;
}
namespace noding {
class SegmentString;
}
}
namespace geos { // geos.
namespace operation { // geos.operation
namespace relateng { // geos.operation.relateng
class GEOS_DLL RelateGeometry {
using Coordinate = geos::geom::Coordinate;
using CoordinateSequence = geos::geom::CoordinateSequence;
using Dimension = geos::geom::Dimension;
using Envelope = geos::geom::Envelope;
using Geometry = geos::geom::Geometry;
using Location = geos::geom::Location;
using CoordinateXY = geos::geom::CoordinateXY;
using LinearRing = geos::geom::LinearRing;
using LineString = geos::geom::LineString;
using MultiPolygon = geos::geom::MultiPolygon;
using Point = geos::geom::Point;
using BoundaryNodeRule = geos::algorithm::BoundaryNodeRule;
using SegmentString = geos::noding::SegmentString;
private:
// Members
const Geometry* geom;
bool m_isPrepared = false;
const Envelope* geomEnv;
const BoundaryNodeRule& boundaryNodeRule;
int geomDim = Dimension::False;
bool isLineZeroLen = false;
bool isGeomEmpty = false;
Coordinate::ConstXYSet uniquePoints;
std::unique_ptr<RelatePointLocator> locator;
int elementId = 0;
bool hasPoints = false;
bool hasLines = false;
bool hasAreas = false;
/*
* Memory contexts for lower level allocations
*/
std::vector<std::unique_ptr<const RelateSegmentString>> segStringTempStore;
std::vector<std::unique_ptr<const RelateSegmentString>> segStringPermStore;
std::vector<std::unique_ptr<CoordinateSequence>> csStore;
// Methods
void analyzeDimensions();
static bool isZeroLength(const Geometry* geom);
static bool isZeroLength(const LineString* line);
bool isZeroLengthLine(const Geometry* g) const {
// avoid expensive zero-length calculation if not linear
if (getDimension() != Dimension::L)
return false;
return isZeroLength(g);
};
RelatePointLocator* getLocator();
Coordinate::ConstXYSet createUniquePoints();
void extractSegmentStringsFromAtomic(bool isA,
const Geometry* geom, const MultiPolygon* parentPolygonal,
const Envelope* env,
std::vector<const SegmentString*>& segStrings,
std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
void extractRingToSegmentString(bool isA,
const LinearRing* ring, int ringId, const Envelope* env,
const Geometry* parentPoly,
std::vector<const SegmentString*>& segStrings,
std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
void extractSegmentStrings(bool isA,
const Envelope* env, const Geometry* geom,
std::vector<const SegmentString*>& segStrings,
std::vector<std::unique_ptr<const RelateSegmentString>>& segStore);
const CoordinateSequence* orientAndRemoveRepeated(
const CoordinateSequence* cs, bool orientCW);
const CoordinateSequence* removeRepeated(
const CoordinateSequence* cs);
public:
static constexpr bool GEOM_A = true;
static constexpr bool GEOM_B = false;
RelateGeometry(const Geometry* input)
: RelateGeometry(input, false, BoundaryNodeRule::getBoundaryRuleMod2())
{};
RelateGeometry(const Geometry* input, const BoundaryNodeRule& bnRule)
: RelateGeometry(input, false, bnRule)
{};
RelateGeometry(const Geometry* input, bool p_isPrepared, const BoundaryNodeRule& bnRule);
static std::string name(bool isA);
const Geometry* getGeometry() const {
return geom;
}
bool isPrepared() const {
return m_isPrepared;
}
const Envelope* getEnvelope() const {
return geomEnv;
}
inline int getDimension() const {
return geomDim;
}
bool hasDimension(int dim) const {
switch (dim) {
case Dimension::P: return hasPoints;
case Dimension::L: return hasLines;
case Dimension::A: return hasAreas;
}
return false;
}
bool hasAreaAndLine() const {
return hasAreas && hasLines;
}
int getDimensionReal() const;
bool hasEdges() const;
bool isNodeInArea(const CoordinateXY* nodePt, const Geometry* parentPolygonal);
int locateLineEndWithDim(const CoordinateXY* p);
Location locateAreaVertex(const CoordinateXY* pt);
Location locateNode(const CoordinateXY* pt, const Geometry* parentPolygonal);
int locateWithDim(const CoordinateXY* pt);
bool isSelfNodingRequired() const;
bool isPolygonal() const;
bool isEmpty() const;
bool hasBoundary();
Coordinate::ConstXYSet& getUniquePoints();
std::vector<const Point*> getEffectivePoints();
std::vector<const SegmentString*> extractSegmentStrings(bool isA, const Envelope* env);
std::string toString() const;
friend std::ostream& operator<<(std::ostream& os, const RelateGeometry& rg);
RelateGeometry(const RelateGeometry&) = delete;
RelateGeometry& operator=(const RelateGeometry&) = delete;
};
} // namespace geos.operation.relateng
} // namespace geos.operation
} // namespace geos
geos::geom::CoordinateSequence
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
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::geom::MultiPolygon
Definition MultiPolygon.h:58
geos::geom::Point
Definition Point.h:61
geos::noding::SegmentString
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
geos::geom
Definition Angle.h:26
geos::geom::Location
Location
Constants representing the location of a point relative to a geometry.
Definition Location.h:32
geos::noding
Classes to compute nodings for arrangements of line segments and line segment sequences.
Definition CoverageCleaner.h:42
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38