34 return a.second > b.second;
42 int np = coords.
count();
46 double x0 = coords[0].x(), y0 = coords[0].y();
49 for (
int i = 1; i < np; ++i )
53 dist += sqrt(( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) );
66 int plcount = pl.
count();
67 double prevX = pldata[0].
x(), prevY = pldata[0].
y();
68 double segmentPtX, segmentPtY;
69 for (
int i = 1; i < plcount; ++i )
71 double currentX = pldata[i].
x();
72 double currentY = pldata[i].
y();
74 if ( testDist < sqrDist )
97 int otherVertex(
int v0 )
const {
return v1 == v0 ? v2 : v1; }
132 int v1 = -1, v2 = -1;
135 v1 = point2vertex.
value( p1 );
142 point2vertex[p1] = v1;
147 v2 = point2vertex.
value( p2 );
154 point2vertex[p2] = v2;
165 int eIdx = g->
e.count() - 1;
166 g->
v[v1].edges << eIdx;
167 g->
v[v2].edges << eIdx;
176 if ( v1 == -1 || v2 == -1 )
181 std::priority_queue< DijkstraQueueItem, std::vector< DijkstraQueueItem >,
comp > Q;
210 for (
int i = 0; i < count; ++i )
215 if ( !F[v] && D[u] + w < D[v] )
238 if ( edgePoints[0] != g.
v[u].pt )
239 std::reverse( edgePoints.
begin(), edgePoints.
end() );
242 points << edgePoints;
246 std::reverse( path.
begin(), path.
end() );
250 std::reverse( points.
begin(), points.
end() );
259 for (
int i = 0; i < g.
v.count(); ++i )
262 if ( v.
pt == pt || ( fabs( v.
pt.
x() - pt.
x() ) < epsilon && fabs( v.
pt.
y() - pt.
y() ) < epsilon ) )
274 for (
int i = 0; i < g.
e.count(); ++i )
283 lineVertexAfter = vertexAfter;
293 int count1 = lineVertexAfter;
294 int count2 = points.
count() - lineVertexAfter;
296 for (
int i = 0; i < count1; ++i )
298 if ( points[lineVertexAfter-1] != pt )
301 if ( pt != points[lineVertexAfter] )
303 for (
int i = 0; i < count2; ++i )
304 pts2 << points[i + lineVertexAfter];
312 int eIdx =
point2edge( g, pt, lineVertexAfter );
326 int vIdx = g.
v.count();
327 int e1Idx = g.
e.count();
328 int e2Idx = e1Idx + 1;
334 v.
edges << e1Idx << e2Idx;
383 if ( eIdx >= g.
e.count() )
389 if ( v1.
edges[i] >= g.
e.count() )
397 if ( v2.
edges[i] >= g.
e.count() )
441 , mReprojectionEnabled( false )
442 , mMaxFeatureCount( 0 )
443 , mHasTopologyProblem( false )
448 bool QgsTracer::initGraph()
453 mHasTopologyProblem =
false;
462 QTime t1, t2, t2a, t3;
465 int featuresCounted = 0;
481 if ( mReprojectionEnabled && !ct.isShortCircuited() )
496 if ( mMaxFeatureCount != 0 && featuresCounted >= mMaxFeatureCount )
500 int timeExtract = t1.
elapsed();
506 int timeNodingCall = 0;
518 timeNodingCall = t2a.
elapsed();
528 catch ( GEOSException &e )
533 mHasTopologyProblem =
true;
535 QgsDebugMsg(
"Tracer Noding Exception: " + e.what() );
547 Q_UNUSED( timeExtract );
548 Q_UNUSED( timeNoding );
549 Q_UNUSED( timeNodingCall );
550 Q_UNUSED( timeMake );
552 .arg( timeExtract ).arg( timeNoding ).arg( timeNodingCall ).arg( timeMake ) );
563 if ( mLayers == layers )
589 if ( mReprojectionEnabled == enabled )
592 mReprojectionEnabled = enabled;
607 if ( mExtent == extent )
651 void QgsTracer::onLayerDestroyed(
QObject* obj )
654 mLayers.
removeAll( static_cast<QgsVectorLayer*>( obj ) );
671 int tPrep = t.elapsed();
687 int tPath = t2.elapsed();
691 QgsDebugMsg(
QString(
"path timing: prep %1 ms, path %2 ms" ).arg( tPrep ).arg( tPath ) );
711 int e =
point2edge( *mGraph, pt, lineVertexAfter );
QgsPolygon asPolygon() const
Return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
QVector< E > e
Edges of the graph.
Wrapper for iterator of features from vector data provider or vector layer.
QgsMultiPolyline asMultiPolyline() const
Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
A rectangle specified with double values.
QVector< QgsPoint > shortestPath(const QgsTracerGraph &g, int v1, int v2)
int joinedVertices
Temporarily added vertices (for each there are two extra edges)
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
int indexOf(const T &value, int from) const
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
int pointInGraph(QgsTracerGraph &g, const QgsPoint &pt)
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
void setExtent(const QgsRectangle &extent)
Set extent to which graph's features will be limited (empty extent means no limit) ...
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
int point2vertex(const QgsTracerGraph &g, const QgsPoint &pt, double epsilon=1e-6)
QList< QgsVectorLayer * > layers() const
Get layers used for tracing.
A geometry is the spatial representation of a feature.
QgsTracerGraph * makeGraph(const QVector< QgsPolyline > &edges)
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
double closestSegment(const QgsPolyline &pl, const QgsPoint &pt, int &vertexAfter, double epsilon)
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
std::pair< int, double > DijkstraQueueItem
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
double y() const
Get the y value of the point.
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
bool isEmpty() const
test if rectangle is empty.
QSet< int > inactiveEdges
Temporarily removed edges.
Max feature count threshold was reached while reading features.
int removeAll(const T &value)
PathError
Possible errors that may happen when calling findShortestPath()
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
void fromGeos(GEOSGeometry *geos)
Set the geometry, feeding in a geometry in GEOS format.
void splitLinestring(const QgsPolyline &points, const QgsPoint &pt, int lineVertexAfter, QgsPolyline &pts1, QgsPolyline &pts2)
const T * constData() const
Simple graph structure for shortest path search.
A class to represent a point.
const T value(const Key &key) const
void resetGraph(QgsTracerGraph &g)
QgsGeometry * geometry()
Get the geometry object associated with this feature.
bool contains(const T &value) const
static QgsGeometry * fromMultiPolyline(const QgsMultiPolyline &multiline)
Creates a new geometry from a QgsMultiPolyline object.
End point cannot be joined to the graph.
QVector< V > v
Vertices of the graph.
void setCrsTransformEnabled(bool enabled)
Set whether to do reprojection to destination CRS.
QVector< int > edges
indices of adjacent edges (used in Dijkstra algorithm)
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
static GEOSContextHandle_t getGEOSHandler()
Return GEOS context handle.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
QgsMultiPolygon asMultiPolygon() const
Return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
QgsPoint pt
location of the vertex
void invalidateGraph()
Destroy the existing graph structure if any (de-initialize)
const GEOSGeometry * asGeos(double precision=0) const
Returns a geos geometry.
Class for storing a coordinate reference system (CRS)
int count(const T &value) const
bool isPointSnapped(const QgsPoint &pt)
Find out whether the point is snapped to a vertex or edge (i.e. it can be used for tracing start/stop...
QgsRectangle extent() const
Get extent to which graph's features will be limited (empty extent means no limit) ...
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
void replace(int i, const T &value)
QVector< QgsPoint > coords
coordinates of the edge (including endpoints)
static double sqrDistToLine(double ptX, double ptY, double x1, double y1, double x2, double y2, double &minDistX, double &minDistY, double epsilon)
Returns the squared distance between a point and a line.
bool init()
Build the internal data structures.
static Type flatType(Type type)
Returns the flat type for a WKB type.
bool contains(const Key &key) const
Custom exception class for Coordinate Reference System related exceptions.
double distance2D(const QgsPolyline &coords)
bool nextFeature(QgsFeature &f)
int otherVertex(int v0) const
bool operator()(DijkstraQueueItem a, DijkstraQueueItem b)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
void extractLinework(const QgsGeometry *g, QgsMultiPolyline &mpl)
int point2edge(const QgsTracerGraph &g, const QgsPoint &pt, int &lineVertexAfter, double epsilon=1e-6)
void setLayers(const QList< QgsVectorLayer *> &layers)
Set layers used for tracing.
void destroyed(QObject *obj)
QVector< QgsPoint > findShortestPath(const QgsPoint &p1, const QgsPoint &p2, PathError *error=nullptr)
Given two points, find the shortest path and return points on the way.
QgsFeatureRequest & setFilterRect(const QgsRectangle &rect)
Set rectangle from which features will be taken.
Points are not connected in the graph.
double x() const
Get the x value of the point.
Start point cannot be joined to the graph.
int v1
vertices that the edge connects
int joinVertexToGraph(QgsTracerGraph &g, const QgsPoint &pt)
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Set CRS used for tracing.