LineSequencer.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/linemerge/LineSequencer.java r378 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <geos/export.h>
#include <geos/operation/linemerge/LineMergeGraph.h> // for composition
#include <geos/geom/Geometry.h> // for inlines
#include <geos/geom/LineString.h> // for inlines
#include <vector>
#include <list>
#include <memory> // for unique_ptr
#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;
class LineString;
}
namespace planargraph {
class DirectedEdge;
class Subgraph;
class Node;
}
}
namespace geos {
namespace operation { // geos::operation
namespace linemerge { // geos::operation::linemerge
class GEOS_DLL LineSequencer {
private:
typedef std::list<planargraph::DirectedEdge*> DirEdgeList;
typedef std::vector< DirEdgeList* > Sequences;
LineMergeGraph graph;
const geom::GeometryFactory* factory;
unsigned int lineCount;
bool isRun;
std::unique_ptr<geom::Geometry> sequencedGeometry;
bool isSequenceableVar;
void addLine(const geom::LineString* lineString);
void computeSequence();
Sequences* findSequences();
DirEdgeList* findSequence(planargraph::Subgraph& graph);
void delAll(Sequences&);
geom::Geometry* buildSequencedGeometry(const Sequences& sequences);
static const planargraph::Node* findLowestDegreeNode(
const planargraph::Subgraph& graph);
void addReverseSubpath(const planargraph::DirectedEdge* de,
DirEdgeList& deList,
DirEdgeList::iterator lit,
bool expectedClosed);
static const planargraph::DirectedEdge* findUnvisitedBestOrientedDE(
const planargraph::Node* node);
DirEdgeList* orient(DirEdgeList* seq);
DirEdgeList* reverse(DirEdgeList& seq);
bool hasSequence(planargraph::Subgraph& graph);
public:
static geom::Geometry*
sequence(const geom::Geometry& geom)
{
LineSequencer sequencer;
sequencer.add(geom);
return sequencer.getSequencedLineStrings();
}
LineSequencer()
:
factory(nullptr),
lineCount(0),
isRun(false),
sequencedGeometry(nullptr),
isSequenceableVar(false)
{}
static bool isSequenced(const geom::Geometry* geom);
bool
isSequenceable()
{
computeSequence();
return isSequenceableVar;
}
void
add(const geom::Geometry& geometry)
{
geometry.applyComponentFilter(*this);
}
template <class TargetContainer>
void
add(TargetContainer& geoms)
{
for(typename TargetContainer::const_iterator i = geoms.begin(),
e = geoms.end(); i != e; ++i) {
const geom::Geometry* g = *i;
add(*g);
}
}
void
filter(const geom::Geometry* g)
{
if(const geom::LineString* ls = dynamic_cast<const geom::LineString*>(g)) {
addLine(ls);
}
}
geom::Geometry*
getSequencedLineStrings(bool release = 1)
{
computeSequence();
if(release) {
return sequencedGeometry.release();
}
else {
return sequencedGeometry.get();
}
}
};
} // namespace geos::operation::linemerge
} // 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::Geometry
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:196
geos::geom::Geometry::applyComponentFilter
void applyComponentFilter(T &f) const
Apply a filter to each component of this geometry. The filter is expected to provide a ....
Definition Geometry.h:805
geos::geom::LineString
Definition LineString.h:66
geos::operation::linemerge::LineMergeGraph
A planar graph of edges that is analyzed to sew the edges together.
Definition LineMergeGraph.h:58
geos::operation::linemerge::LineSequencer::isSequenceable
bool isSequenceable()
Tests whether the arrangement of linestrings has a valid sequence.
Definition LineSequencer.h:223
geos::operation::linemerge::LineSequencer::add
void add(const geom::Geometry &geometry)
Adds a Geometry to be sequenced.
Definition LineSequencer.h:239
geos::operation::linemerge::LineSequencer::getSequencedLineStrings
geom::Geometry * getSequencedLineStrings(bool release=1)
Returns the LineString or MultiLineString built by the sequencing process, if one exists.
Definition LineSequencer.h:277
geos::operation::linemerge::LineSequencer::filter
void filter(const geom::Geometry *g)
Act as a GeometryComponentFilter so to extract the linearworks.
Definition LineSequencer.h:260
geos::operation::linemerge::LineSequencer::isSequenced
static bool isSequenced(const geom::Geometry *geom)
Tests whether a Geometry is sequenced correctly.
geos::planargraph::DirectedEdge
Represents a directed edge in a PlanarGraph.
Definition planargraph/DirectedEdge.h:45
geos::planargraph::Node
A node in a PlanarGraph is a location where 0 or more Edge meet.
Definition planargraph/Node.h:44
geos::planargraph::Subgraph
A subgraph of a PlanarGraph.
Definition Subgraph.h:52
geos::geom
Definition Angle.h:26
geos::operation::linemerge
Line merging package.
Definition namespaces.h:192
geos::operation
Provides classes for implementing operations on geometries.
Definition CleanCoverage.h:34
geos::planargraph
Contains classes to implement a planar graph data structure.
Definition namespaces.h:293
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38