OverlayUtil.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2020 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/geom/Point.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/LineString.h>
#include <geos/geom/Geometry.h>
#include <geos/export.h>
#include <vector>
#include <memory>
// Forward declarations
namespace geos {
namespace geom {
class Coordinate;
class CoordinateSequence;
class Envelope;
class GeometryFactory;
class PrecisionModel;
}
namespace operation {
namespace overlayng {
class InputGeometry;
class OverlayGraph;
}
}
}
namespace geos { // geos.
namespace operation { // geos.operation
namespace overlayng { // geos.operation.overlayng
class GEOS_DLL OverlayUtil {
using Geometry = geos::geom::Geometry;
using Coordinate = geos::geom::Coordinate;
using CoordinateSequence = geos::geom::CoordinateSequence;
using Envelope = geos::geom::Envelope;
using Point = geos::geom::Point;
using LineString = geos::geom::LineString;
using Polygon = geos::geom::Polygon;
using GeometryFactory = geos::geom::GeometryFactory;
using PrecisionModel = geos::geom::PrecisionModel;
private:
static constexpr double SAFE_ENV_BUFFER_FACTOR = 0.1;
static constexpr int SAFE_ENV_GRID_FACTOR = 3;
static constexpr double AREA_HEURISTIC_TOLERANCE = 0.1;
static bool resultEnvelope(int opCode, const InputGeometry* inputGeom, const PrecisionModel* pm, Envelope& rsltEnvelope);
static double safeExpandDistance(const Envelope* env, const PrecisionModel* pm);
static bool safeEnv(const Envelope* env, const PrecisionModel* pm, Envelope& rsltEnvelope);
static bool isEmpty(const Geometry* geom);
static bool isDisjoint(const Envelope* envA, const Envelope* envB, const PrecisionModel* pm);
static bool isLess(double v1, double v2, double tol) {
return v1 <= v2 * (1 + tol);
};
static bool isGreater(double v1, double v2, double tol) {
return v1 >= v2 * (1 - tol);
}
public:
static bool isFloating(const PrecisionModel* pm);
static bool clippingEnvelope(int opCode, const InputGeometry* inputGeom, const PrecisionModel* pm, Envelope& rsltEnvelope);
static bool isEmptyResult(int opCode, const Geometry* a, const Geometry* b, const PrecisionModel* pm);
static bool isEnvDisjoint(const Geometry* a, const Geometry* b, const PrecisionModel* pm);
static std::unique_ptr<Geometry> createEmptyResult(int dim, size_t coordDim, const GeometryFactory* geomFact);
static int resultDimension(int opCode, int dim0, int dim1);
static uint8_t resultCoordinateDimension(uint8_t coordDim0, uint8_t coordDim1);
static std::unique_ptr<Geometry> createResultGeometry(
std::vector<std::unique_ptr<Polygon>>& resultPolyList,
std::vector<std::unique_ptr<LineString>>& resultLineList,
std::vector<std::unique_ptr<Point>>& resultPointList,
const GeometryFactory* geometryFactory);
static std::unique_ptr<Geometry> toLines(OverlayGraph* graph, bool isOutputEdges, const GeometryFactory* geomFact);
static bool isResultAreaConsistent(
const Geometry* geom0, const Geometry* geom1,
int opCode, const Geometry* result);
static bool round(const Point* pt, const PrecisionModel* pm, Coordinate& rsltCoord);
template<typename T>
static void moveGeometry(std::vector<std::unique_ptr<T>>& inGeoms, std::vector<std::unique_ptr<Geometry>>& outGeoms)
{
static_assert(std::is_base_of<Geometry, T>::value, "");
for (auto& geom: inGeoms) {
Geometry* outGeom = static_cast<Geometry*>(geom.release());
outGeoms.emplace_back(outGeom);
}
return;
}
};
} // namespace geos.operation.overlayng
} // 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::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::Envelope
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
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::Point
Definition Point.h:61
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::geom::PrecisionModel
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
geos::operation::overlayng::InputGeometry
Definition InputGeometry.h:41
geos::operation::overlayng::OverlayGraph
Definition OverlayGraph.h:52
geos::operation::overlayng::OverlayUtil
Definition OverlayUtil.h:54
geos::operation::overlayng::OverlayUtil::round
static bool round(const Point *pt, const PrecisionModel *pm, Coordinate &rsltCoord)
geos::operation::overlayng::OverlayUtil::resultDimension
static int resultDimension(int opCode, int dim0, int dim1)
geos::operation::overlayng::OverlayUtil::resultCoordinateDimension
static uint8_t resultCoordinateDimension(uint8_t coordDim0, uint8_t coordDim1)
geos::operation::overlayng::OverlayUtil::isEmptyResult
static bool isEmptyResult(int opCode, const Geometry *a, const Geometry *b, const PrecisionModel *pm)
geos::operation::overlayng::OverlayUtil::isEnvDisjoint
static bool isEnvDisjoint(const Geometry *a, const Geometry *b, const PrecisionModel *pm)
geos::operation::overlayng::OverlayUtil::isResultAreaConsistent
static bool isResultAreaConsistent(const Geometry *geom0, const Geometry *geom1, int opCode, const Geometry *result)
geos::operation::overlayng::OverlayUtil::createResultGeometry
static std::unique_ptr< Geometry > createResultGeometry(std::vector< std::unique_ptr< Polygon > > &resultPolyList, std::vector< std::unique_ptr< LineString > > &resultLineList, std::vector< std::unique_ptr< Point > > &resultPointList, const GeometryFactory *geometryFactory)
geos::operation::overlayng::OverlayUtil::createEmptyResult
static std::unique_ptr< Geometry > createEmptyResult(int dim, size_t coordDim, const GeometryFactory *geomFact)
geos::operation::overlayng::OverlayUtil::clippingEnvelope
static bool clippingEnvelope(int opCode, const InputGeometry *inputGeom, const PrecisionModel *pm, Envelope &rsltEnvelope)
geos::geom
Definition Angle.h:26
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38