CascadedPolygonUnion.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 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/union/CascadedPolygonUnion.java r487 (JTS-1.12+)
* Includes custom code to deal with https://trac.osgeo.org/geos/ticket/837
*
**********************************************************************/
#pragma once
#include <vector>
#include <geos/export.h>
#include <geos/operation/union/UnionStrategy.h>
// Forward declarations
namespace geos {
namespace geom {
class GeometryFactory;
class Geometry;
class Polygon;
class MultiPolygon;
class Envelope;
}
}
namespace geos {
namespace operation { // geos::operation
namespace geounion { // geos::operation::geounion
class GEOS_DLL ClassicUnionStrategy : public UnionStrategy {
public:
ClassicUnionStrategy() {};
std::unique_ptr<geom::Geometry> Union(const geom::Geometry*, const geom::Geometry*) override;
bool isFloatingPrecision() const override;
private:
std::unique_ptr<geom::Geometry> unionPolygonsByBuffer(const geom::Geometry* g0, const geom::Geometry* g1);
};
class GEOS_DLL CascadedPolygonUnion {
private:
std::vector<geom::Polygon*>* inputPolys;
geom::GeometryFactory const* geomFactory;
static int const STRTREE_NODE_CAPACITY = 4;
static std::unique_ptr<geom::Geometry> restrictToPolygons(std::unique_ptr<geom::Geometry> g);
public:
CascadedPolygonUnion();
static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys);
static std::unique_ptr<geom::Geometry> Union(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun);
template <class T>
static std::unique_ptr<geom::Geometry>
Union(T start, T end, UnionStrategy *unionStrategy)
{
std::vector<geom::Polygon*> polys;
for(T i = start; i != end; ++i) {
const geom::Polygon* p = dynamic_cast<const geom::Polygon*>(*i);
polys.push_back(const_cast<geom::Polygon*>(p));
}
return Union(&polys, unionStrategy);
}
static std::unique_ptr<geom::Geometry> Union(const geom::MultiPolygon* polys);
CascadedPolygonUnion(std::vector<geom::Polygon*>* polys)
: inputPolys(polys)
, geomFactory(nullptr)
, unionFunction(&defaultUnionFunction)
{}
CascadedPolygonUnion(std::vector<geom::Polygon*>* polys, UnionStrategy* unionFun)
: inputPolys(polys)
, geomFactory(nullptr)
, unionFunction(unionFun)
{}
std::unique_ptr<geom::Geometry> Union();
private:
UnionStrategy* unionFunction;
ClassicUnionStrategy defaultUnionFunction;
std::unique_ptr<geom::Geometry> binaryUnion(const std::vector<const geom::Geometry*> & geoms, std::size_t start, std::size_t end);
std::unique_ptr<geom::Geometry> unionSafe(const geom::Geometry* g0, const geom::Geometry* g1) const;
std::unique_ptr<geom::Geometry> unionSafe(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&);
std::unique_ptr<geom::Geometry> unionActual(const geom::Geometry* g0, const geom::Geometry* g1) const;
std::unique_ptr<geom::Geometry> unionActual(std::unique_ptr<geom::Geometry> &&, std::unique_ptr<geom::Geometry> &&) const;
};
} // namespace geos::operation::union
} // namespace geos::operation
} // namespace geos
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::MultiPolygon
Definition MultiPolygon.h:58
geos::geom::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::operation::geounion::CascadedPolygonUnion
Provides an efficient method of unioning a collection of polygonal geometries.
Definition CascadedPolygonUnion.h:103
geos::operation::geounion::CascadedPolygonUnion::CascadedPolygonUnion
CascadedPolygonUnion(std::vector< geom::Polygon * > *polys)
Creates a new instance to union the given collection of Geometrys.
Definition CascadedPolygonUnion.h:180
geos::operation::geounion::CascadedPolygonUnion::Union
static std::unique_ptr< geom::Geometry > Union(T start, T end, UnionStrategy *unionStrategy)
Computes the union of a set of polygonal Geometrys.
Definition CascadedPolygonUnion.h:155
geos::operation::geounion::CascadedPolygonUnion::Union
static std::unique_ptr< geom::Geometry > Union(std::vector< geom::Polygon * > *polys)
Computes the union of a collection of polygonal Geometrys.
geos::operation::geounion::CascadedPolygonUnion::Union
std::unique_ptr< geom::Geometry > Union()
Computes the union of the input geometries.
geos::operation::geounion::CascadedPolygonUnion::Union
static std::unique_ptr< geom::Geometry > Union(const geom::MultiPolygon *polys)
Computes the union of a collection of polygonal Geometrys.
geos::operation::geounion::ClassicUnionStrategy
Implementation of UnionStrategy that provides overlay using the first generation overlay routines.
Definition CascadedPolygonUnion.h:50
geos::operation::geounion::ClassicUnionStrategy::isFloatingPrecision
bool isFloatingPrecision() const override
geos::operation::geounion::ClassicUnionStrategy::Union
std::unique_ptr< geom::Geometry > Union(const geom::Geometry *, const geom::Geometry *) override
geos::operation::geounion::UnionStrategy
Definition UnionStrategy.h:40
geos::geom
Definition Angle.h:26
geos::operation::geounion
Classes to perform efficient unioning of collections of geometries.
Definition namespaces.h:286
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38