PolygonHullSimplifier.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2021 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/Geometry.h>
#include <geos/util/IllegalArgumentException.h>
#include <geos/simplify/RingHull.h>
namespace geos {
namespace geom {
class GeometryFactory;
class LinearRing;
class MultiPolygon;
class Polygon;
}
namespace algorithm {
namespace hull {
class RingHullIndex;
}
}
}
namespace geos {
namespace simplify { // geos::simplify
class GEOS_DLL PolygonHullSimplifier
{
using Envelope = geos::geom::Envelope;
using Geometry = geos::geom::Geometry;
using GeometryFactory = geos::geom::GeometryFactory;
using LinearRing = geos::geom::LinearRing;
using MultiPolygon = geos::geom::MultiPolygon;
using Polygon = geos::geom::Polygon;
public:
PolygonHullSimplifier(const Geometry* geom, bool bOuter)
: inputGeom(geom)
, geomFactory(geom->getFactory())
, isOuter(bOuter)
, vertexNumFraction(-1.0)
, areaDeltaRatio(-1.0)
{
if (!geom->isPolygonal()) {
throw util::IllegalArgumentException("Input geometry must be polygonal");
}
};
static std::unique_ptr<Geometry> hull(
const Geometry* geom,
bool isOuter,
double vertexNumFraction);
static std::unique_ptr<Geometry> hullByAreaDelta(
const Geometry* geom,
bool isOuter,
double areaDeltaRatio);
void setVertexNumFraction(double p_vertexNumFraction);
void setAreaDeltaRatio(double p_areaDeltaRatio);
std::unique_ptr<Geometry> getResult();
private:
// Members
const Geometry* inputGeom;
const GeometryFactory* geomFactory;
bool isOuter;
double vertexNumFraction;
double areaDeltaRatio;
// Allocate the RingHull* in here so they are cleaned
// up with PolygonHullSimplifier
std::vector<std::unique_ptr<RingHull>> ringStore;
std::unique_ptr<Geometry> computeMultiPolygonAll(const MultiPolygon* multiPoly);
std::unique_ptr<Geometry> computeMultiPolygonEach(const MultiPolygon* multiPoly);
std::unique_ptr<Polygon> computePolygon(const Polygon* poly);
std::vector<RingHull*> initPolygon(const Polygon* poly,
RingHullIndex& hullIndex);
double ringArea(const Polygon* poly) const;
RingHull* createRingHull(
const LinearRing* ring,
bool isOuter,
double areaTotal,
RingHullIndex& hullIndex);
std::unique_ptr<Polygon> polygonHull(
const Polygon* poly,
std::vector<RingHull*>& ringHulls,
RingHullIndex& hullIndex) const;
PolygonHullSimplifier(const PolygonHullSimplifier&) = delete;
PolygonHullSimplifier& operator=(const PolygonHullSimplifier&) = delete;
}; // PolygonHullSimplifier
} // geos::simplify
} // 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::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::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::simplify::PolygonHullSimplifier::hull
static std::unique_ptr< Geometry > hull(const Geometry *geom, bool isOuter, double vertexNumFraction)
geos::simplify::PolygonHullSimplifier::setAreaDeltaRatio
void setAreaDeltaRatio(double p_areaDeltaRatio)
geos::simplify::PolygonHullSimplifier::getResult
std::unique_ptr< Geometry > getResult()
geos::simplify::PolygonHullSimplifier::PolygonHullSimplifier
PolygonHullSimplifier(const Geometry *geom, bool bOuter)
Definition PolygonHullSimplifier.h:96
geos::simplify::PolygonHullSimplifier::setVertexNumFraction
void setVertexNumFraction(double p_vertexNumFraction)
geos::simplify::PolygonHullSimplifier::hullByAreaDelta
static std::unique_ptr< Geometry > hullByAreaDelta(const Geometry *geom, bool isOuter, double areaDeltaRatio)
geos::algorithm
Contains classes and interfaces implementing fundamental computational geometry algorithms.
Definition Angle.h:32
geos::geom
Definition Angle.h:26
geos::simplify
Classes which implement algorithms for simplifying or generalizing geometries.
Definition Corner.h:26
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38