Polygonizer.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2010 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2006 Refractions Research Inc.
* Copyright (C) 2001-2002 Vivid Solutions 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/polygonize/Polygonizer.java 0b3c7e3eb0d3e
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/GeometryComponentFilter.h> // for LineStringAdder inheritance
#include <geos/operation/polygonize/PolygonizeGraph.h>
#include <memory>
#include <vector>
#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 Geometry;
class LineString;
class Polygon;
}
namespace operation {
namespace polygonize {
class EdgeRing;
}
}
}
namespace geos {
namespace operation { // geos::operation
namespace polygonize { // geos::operation::polygonize
class GEOS_DLL Polygonizer {
private:
class GEOS_DLL LineStringAdder: public geom::GeometryComponentFilter {
public:
Polygonizer* pol;
explicit LineStringAdder(Polygonizer* p);
//void filter_rw(geom::Geometry *g);
void filter_ro(const geom::Geometry* g) override;
};
// default factory
LineStringAdder lineStringAdder;
void add(const geom::LineString* line);
void polygonize();
static void findValidRings(const std::vector<EdgeRing*>& edgeRingList,
std::vector<EdgeRing*>& validEdgeRingList,
std::vector<EdgeRing*>& invalidRingList);
std::vector<std::unique_ptr<geom::LineString>> extractInvalidLines(
std::vector<EdgeRing*>& invalidRings);
bool isIncludedInvalid(EdgeRing* invalidRing);
void findShellsAndHoles(const std::vector<EdgeRing*>& edgeRingList);
void findDisjointShells();
static void findOuterShells(std::vector<EdgeRing*>& shellList);
static std::vector<std::unique_ptr<geom::Polygon>> extractPolygons(std::vector<EdgeRing*> & shellList, bool includeAll);
bool extractOnlyPolygonal;
bool computed;
protected:
std::unique_ptr<PolygonizeGraph> graph;
// initialize with empty collections, in case nothing is computed
std::vector<const geom::LineString*> dangles;
std::vector<const geom::LineString*> cutEdges;
std::vector<std::unique_ptr<geom::LineString>> invalidRingLines;
std::vector<EdgeRing*> holeList;
std::vector<EdgeRing*> shellList;
std::vector<std::unique_ptr<geom::Polygon>> polyList;
public:
explicit Polygonizer(bool onlyPolygonal = false);
~Polygonizer() = default;
void add(std::vector<geom::Geometry*>* geomList);
void add(std::vector<const geom::Geometry*>* geomList);
void add(const geom::Geometry* g);
std::vector<std::unique_ptr<geom::Polygon>> getPolygons();
const std::vector<const geom::LineString*>& getDangles();
bool hasDangles();
const std::vector<const geom::LineString*>& getCutEdges();
bool hasCutEdges();
const std::vector<std::unique_ptr<geom::LineString>>& getInvalidRingLines();
bool hasInvalidRingLines();
bool allInputsFormPolygons();
// This seems to be needed by GCC 2.95.4
friend class Polygonizer::LineStringAdder;
};
} // namespace geos::operation::polygonize
} // namespace geos::operation
} // namespace geos
#ifdef _MSC_VER
#pragma warning(pop)
#endif
geos::geom::GeometryComponentFilter
Definition GeometryComponentFilter.h:41
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::Polygon
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
geos::operation::polygonize::EdgeRing
Represents a ring of PolygonizeDirectedEdge which form a ring of a polygon. The ring may be either an...
Definition operation/polygonize/EdgeRing.h:59
geos::operation::polygonize::Polygonizer::getDangles
const std::vector< const geom::LineString * > & getDangles()
Get the list of dangling lines found during polygonization.
geos::operation::polygonize::Polygonizer::add
void add(std::vector< const geom::Geometry * > *geomList)
Add a collection of geometries to be polygonized. May be called multiple times. Any dimension of Geom...
geos::operation::polygonize::Polygonizer::Polygonizer
Polygonizer(bool onlyPolygonal=false)
Create a Polygonizer with the same GeometryFactory as the input Geometrys.
geos::operation::polygonize::Polygonizer::getInvalidRingLines
const std::vector< std::unique_ptr< geom::LineString > > & getInvalidRingLines()
Get the list of lines forming invalid rings found during polygonization.
geos::operation::polygonize::Polygonizer::add
void add(const geom::Geometry *g)
geos::operation::polygonize::Polygonizer::getCutEdges
const std::vector< const geom::LineString * > & getCutEdges()
Get the list of cut edges found during polygonization.
geos::operation::polygonize::Polygonizer::add
void add(std::vector< geom::Geometry * > *geomList)
Add a collection of geometries to be polygonized. May be called multiple times. Any dimension of Geom...
geos::operation::polygonize::Polygonizer::getPolygons
std::vector< std::unique_ptr< geom::Polygon > > getPolygons()
Gets the list of polygons formed by the polygonization.
geos::geom
Definition Angle.h:26
geos::operation::polygonize
An API for polygonizing sets of lines.
Definition namespaces.h:232
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38