UnaryUnionOp.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
*
* 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/UnaryUnionOp.java r320 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <memory>
#include <vector>
#include <geos/export.h>
#include <geos/geom/GeometryFactory.h>
#include <geos/geom/Point.h>
#include <geos/geom/LineString.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/util/GeometryExtracter.h>
#include <geos/operation/union/CascadedPolygonUnion.h>
#include <geos/util.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 GeometryFactory;
class Geometry;
}
}
namespace geos {
namespace operation { // geos::operation
namespace geounion { // geos::operation::geounion
class GEOS_DLL UnaryUnionOp {
public:
template <typename T>
static std::unique_ptr<geom::Geometry>
Union(const T& geoms)
{
UnaryUnionOp op(geoms);
return op.Union();
}
template <class T>
static std::unique_ptr<geom::Geometry>
Union(const T& geoms,
geom::GeometryFactory& geomFact)
{
UnaryUnionOp op(geoms, geomFact);
return op.Union();
}
static std::unique_ptr<geom::Geometry>
Union(const geom::Geometry& geom)
{
UnaryUnionOp op(geom);
return op.Union();
}
template <class T>
UnaryUnionOp(const T& geoms, geom::GeometryFactory& geomFactIn)
: geomFact(&geomFactIn)
, unionFunction(&defaultUnionFunction)
{
extractGeoms(geoms);
}
template <class T>
UnaryUnionOp(const T& geoms)
: geomFact(nullptr)
, unionFunction(&defaultUnionFunction)
{
extractGeoms(geoms);
}
UnaryUnionOp(const geom::Geometry& geom)
: geomFact(geom.getFactory())
, unionFunction(&defaultUnionFunction)
{
extract(geom);
}
void setUnionFunction(UnionStrategy* unionFun)
{
unionFunction = unionFun;
}
std::unique_ptr<geom::Geometry> Union();
private:
template <typename T>
void
extractGeoms(const T& geoms)
{
for(typename T::const_iterator
i = geoms.begin(),
e = geoms.end();
i != e;
++i) {
const geom::Geometry* geom = *i;
extract(*geom);
}
}
void
extract(const geom::Geometry& geom)
{
util::ensureNoCurvedComponents(geom);
using namespace geom::util;
if(! geomFact) {
geomFact = geom.getFactory();
}
GeometryExtracter::extract<geom::Polygon>(geom, polygons);
GeometryExtracter::extract<geom::LineString>(geom, lines);
GeometryExtracter::extract<geom::Point>(geom, points);
}
std::unique_ptr<geom::Geometry>
unionNoOpt(const geom::Geometry& g0)
{
if(! empty.get()) {
empty = geomFact->createEmptyGeometry();
}
return unionFunction->Union(&g0, empty.get());
}
std::unique_ptr<geom::Geometry> unionWithNull(
std::unique_ptr<geom::Geometry> g0,
std::unique_ptr<geom::Geometry> g1
);
// Members
std::vector<const geom::Polygon*> polygons;
std::vector<const geom::LineString*> lines;
std::vector<const geom::Point*> points;
const geom::GeometryFactory* geomFact;
std::unique_ptr<geom::Geometry> empty;
UnionStrategy* unionFunction;
ClassicUnionStrategy defaultUnionFunction;
};
} // namespace geos::operation::union
} // namespace geos::operation
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::GeometryFactory
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition GeometryFactory.h:70
geos::geom::GeometryFactory::createEmptyGeometry
std::unique_ptr< Geometry > createEmptyGeometry(GeometryTypeId type=GEOS_GEOMETRYCOLLECTION, bool hasZ=false, bool hasM=false) const
Construct the EMPTY Geometry.
geos::geom::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::operation::geounion::UnaryUnionOp::Union
std::unique_ptr< geom::Geometry > Union()
Gets the union of the input geometries.
geos::operation::geounion::UnionStrategy
Definition UnionStrategy.h:40
geos::geom::util
Provides classes that parse and modify Geometry objects.
Definition ComponentCoordinateExtracter.h:28
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