TPVWSimplifier.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 <queue>
#include <geos/index/strtree/TemplateSTRtree.h>
#include <geos/index/VertexSequencePackedRtree.h>
#include <geos/simplify/LinkedLine.h>
#include <geos/coverage/Corner.h>
#include <geos/export.h>
namespace geos {
namespace geom {
class Coordinate;
class CoordinateSequence;
class Envelope;
class Geometry;
class GeometryFactory;
class LineString;
class MultiLineString;
}
}
namespace geos {
namespace coverage { // geos::coverage
class GEOS_DLL TPVWSimplifier
{
using Corner = geos::coverage::Corner;
using Coordinate = geos::geom::Coordinate;
using CoordinateSequence = geos::geom::CoordinateSequence;
using Envelope = geos::geom::Envelope;
using Geometry = geos::geom::Geometry;
using GeometryFactory = geos::geom::GeometryFactory;
using LineString = geos::geom::LineString;
using MultiLineString = geos::geom::MultiLineString;
using VertexSequencePackedRtree = geos::index::VertexSequencePackedRtree;
template<typename ItemType>
using TemplateSTRtree = geos::index::strtree::TemplateSTRtree<ItemType>;
using LinkedLine = geos::simplify::LinkedLine;
public:
// Prototype
class EdgeIndex;
/* private static */
class Edge {
public:
// Members
double areaTolerance;
bool isFreeRing;
const Envelope* envelope;
std::size_t nbPts;
LinkedLine linkedLine;
VertexSequencePackedRtree vertexIndex;
std::size_t minEdgeSize;
Edge(const LineString* p_inputLine, bool p_isFreeRing, double p_areaTolerance);
const Coordinate& getCoordinate(std::size_t index) const;
const Envelope* getEnvelopeInternal() const;
std::size_t size() const;
std::unique_ptr<CoordinateSequence> simplify(EdgeIndex& edgeIndex);
void createQueue(Corner::PriorityQueue& pq);
void addCorner(std::size_t i, Corner::PriorityQueue& cornerQueue);
bool isRemovable(Corner& corner, EdgeIndex& edgeIndex) const;
bool hasIntersectingVertex(const Corner& corner,
const Envelope& cornerEnv,
const Edge& edge) const;
std::vector<std::size_t> query(const Envelope& cornerEnv) const;
void removeCorner(
Corner& corner,
Corner::PriorityQueue& cornerQueue);
}; // Edge
class EdgeIndex
{
public:
TemplateSTRtree<const Edge*> index;
void add(std::vector<Edge>& edges);
std::vector<const Edge*> query(const Envelope& queryEnv);
}; // EdgeIndex
static std::unique_ptr<MultiLineString> simplify(
const MultiLineString* lines,
double distanceTolerance);
static std::unique_ptr<MultiLineString> simplify(
const MultiLineString* lines,
std::vector<bool>& freeRings,
const MultiLineString* constraintLines,
double distanceTolerance);
// Constructor
TPVWSimplifier(const MultiLineString* lines,
double distanceTolerance);
private:
// Members
const MultiLineString* inputLines;
std::vector<bool> isFreeRing;
double areaTolerance;
const GeometryFactory* geomFactory;
const MultiLineString* constraintLines;
// Methods
void setFreeRingIndices(std::vector<bool>& freeRing);
void setConstraints(const MultiLineString* constraints);
std::unique_ptr<MultiLineString> simplify();
std::vector<Edge> createEdges(
const MultiLineString* lines,
std::vector<bool>& freeRing);
}; // TPVWSimplifier
} // geos::coverage
} // geos
geos::coverage::TPVWSimplifier::simplify
static std::unique_ptr< MultiLineString > simplify(const MultiLineString *lines, double distanceTolerance)
geos::coverage::TPVWSimplifier::simplify
static std::unique_ptr< MultiLineString > simplify(const MultiLineString *lines, std::vector< bool > &freeRings, const MultiLineString *constraintLines, double distanceTolerance)
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::MultiLineString
Models a collection of LineStrings.
Definition MultiLineString.h:49
geos::index::VertexSequencePackedRtree
Definition VertexSequencePackedRtree.h:49
geos::geom
Definition Angle.h:26
geos::index
Provides classes for various kinds of spatial indexes.
Definition CleanCoverage.h:39
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38