33 return a.second > b.second;
41 int np = coords.
count();
45 double x0 = coords[0].x(), y0 = coords[0].y();
48 for (
int i = 1; i < np; ++i )
52 dist += sqrt(( x1 - x0 ) * ( x1 - x0 ) + ( y1 - y0 ) * ( y1 - y0 ) );
65 int plcount = pl.
count();
66 double prevX = pldata[0].
x(), prevY = pldata[0].
y();
67 double segmentPtX, segmentPtY;
68 for (
int i = 1; i < plcount; ++i )
70 double currentX = pldata[i].
x();
71 double currentY = pldata[i].
y();
73 if ( testDist < sqrDist )
96 int otherVertex(
int v0 )
const {
return v1 == v0 ? v2 : v1; }
131 int v1 = -1, v2 = -1;
134 v1 = point2vertex.
value( p1 );
141 point2vertex[p1] = v1;
146 v2 = point2vertex.
value( p2 );
153 point2vertex[p2] = v2;
164 int eIdx = g->
e.count() - 1;
165 g->
v[v1].edges << eIdx;
166 g->
v[v2].edges << eIdx;
175 if ( v1 == -1 || v2 == -1 )
180 std::priority_queue< DijkstraQueueItem, std::vector< DijkstraQueueItem >,
comp > Q;
209 for (
int i = 0; i < count; ++i )
214 if ( !F[v] && D[u] + w < D[v] )
237 if ( edgePoints[0] != g.
v[u].pt )
238 std::reverse( edgePoints.
begin(), edgePoints.
end() );
241 points << edgePoints;
245 std::reverse( path.
begin(), path.
end() );
249 std::reverse( points.
begin(), points.
end() );
258 for (
int i = 0; i < g.
v.count(); ++i )
261 if ( v.
pt == pt || ( fabs( v.
pt.
x() - pt.
x() ) < epsilon && fabs( v.
pt.
y() - pt.
y() ) < epsilon ) )
273 for (
int i = 0; i < g.
e.count(); ++i )
282 lineVertexAfter = vertexAfter;
292 int count1 = lineVertexAfter;
293 int count2 = points.
count() - lineVertexAfter;
295 for (
int i = 0; i < count1; ++i )
297 if ( points[lineVertexAfter-1] != pt )
300 if ( pt != points[lineVertexAfter] )
302 for (
int i = 0; i < count2; ++i )
303 pts2 << points[i + lineVertexAfter];
311 int eIdx =
point2edge( g, pt, lineVertexAfter );
325 int vIdx = g.
v.count();
326 int e1Idx = g.
e.count();
327 int e2Idx = e1Idx + 1;
333 v.
edges << e1Idx << e2Idx;
382 if ( eIdx >= g.
e.count() )
388 if ( v1.
edges[i] >= g.
e.count() )
396 if ( v2.
edges[i] >= g.
e.count() )
440 , mReprojectionEnabled( false )
441 , mMaxFeatureCount( 0 )
446 bool QgsTracer::initGraph()
458 QTime t1, t2, t2a, t3;
461 int featuresCounted = 0;
477 if ( mReprojectionEnabled && !ct.isShortCircuited() )
492 if ( mMaxFeatureCount != 0 && featuresCounted >= mMaxFeatureCount )
496 int timeExtract = t1.
elapsed();
504 int timeNodingCall = 0;
510 int timeNodingCall = t2a.
elapsed();
529 Q_UNUSED( timeExtract );
530 Q_UNUSED( timeNoding );
531 Q_UNUSED( timeNodingCall );
532 Q_UNUSED( timeMake );
534 .arg( timeExtract ).arg( timeNoding ).arg( timeNodingCall ).arg( timeMake ) );
545 if ( mLayers == layers )
571 if ( mReprojectionEnabled == enabled )
574 mReprojectionEnabled = enabled;
589 if ( mExtent == extent )
633 void QgsTracer::onLayerDestroyed(
QObject* obj )
636 mLayers.
removeAll( static_cast<QgsVectorLayer*>( obj ) );
653 int tPrep = t.elapsed();
669 int tPath = t2.elapsed();
673 QgsDebugMsg(
QString(
"path timing: prep %1 ms, path %2 ms" ).arg( tPrep ).arg( tPath ) );
693 int e =
point2edge( *mGraph, pt, lineVertexAfter );
QVector< E > e
Edges of the graph.
Wrapper for iterator of features from vector data provider or vector layer.
QgsWKBTypes::Type wkbType() const
Returns the WKB type of the geometry.
A rectangle specified with double values.
bool isEmpty() const
test if rectangle is empty.
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
QgsAbstractGeometryV2 * geometry() const
Returns the underlying geometry store.
QgsMultiPolyline asMultiPolyline() const
Return contents of the geometry as a multi linestring if wkbType is WKBMultiLineString, otherwise an empty list.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
int pointInGraph(QgsTracerGraph &g, const QgsPoint &pt)
QgsPolygon asPolygon() const
Return contents of the geometry as a polygon if wkbType is WKBPolygon, otherwise an empty list...
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)
A geometry is the spatial representation of a feature.
QgsTracerGraph * makeGraph(const QVector< QgsPolyline > &edges)
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)
double x() const
Get the x value of the point.
std::pair< int, double > DijkstraQueueItem
QgsMultiPolygon asMultiPolygon() const
Return contents of the geometry as a multi polygon if wkbType is WKBMultiPolygon, otherwise an empty ...
double ANALYSIS_EXPORT max(double x, double y)
Returns the maximum of two doubles or the first argument if both are equal.
QSet< int > inactiveEdges
Temporarily removed edges.
Max feature count threshold was reached while reading features.
void setLayers(const QList< QgsVectorLayer * > &layers)
Set layers used for tracing.
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.
QList< QgsVectorLayer * > layers() const
Get layers used for tracing.
const GEOSGeometry * asGeos(double precision=0) const
Returns a geos geometry.
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.
QgsPolyline asPolyline() const
Return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list...
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)
static GEOSContextHandle_t getGEOSHandler()
Return GEOS context handle.
QgsPoint pt
location of the vertex
void invalidateGraph()
Destroy the existing graph structure if any (de-initialize)
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...
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
int transform(const QgsCoordinateTransform &ct)
Transform this geometry as described by CoordinateTransform ct.
void replace(int i, const T &value)
QgsRectangle extent() const
Get extent to which graph's features will be limited (empty extent means no limit) ...
double y() const
Get the y value of the point.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
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)
bool operator()(DijkstraQueueItem a, DijkstraQueueItem b)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
int otherVertex(int v0) const
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 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.
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.