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 )
99 int otherVertex(
int v0 )
const {
return v1 == v0 ? v2 : v1; }
134 int v1 = -1, v2 = -1;
137 v1 = point2vertex.
value( p1 );
144 point2vertex[p1] = v1;
149 v2 = point2vertex.
value( p2 );
156 point2vertex[p2] = v2;
167 int eIdx = g->
e.count() - 1;
168 g->
v[v1].edges << eIdx;
169 g->
v[v2].edges << eIdx;
178 if ( v1 == -1 || v2 == -1 )
183 std::priority_queue< DijkstraQueueItem, std::vector< DijkstraQueueItem >,
comp > Q;
212 for (
int i = 0; i < count; ++i )
217 if ( !F[v] && D[u] + w < D[v] )
240 if ( edgePoints[0] != g.
v[u].pt )
241 std::reverse( edgePoints.
begin(), edgePoints.
end() );
244 points << edgePoints;
248 std::reverse( path.
begin(), path.
end() );
252 std::reverse( points.
begin(), points.
end() );
261 for (
int i = 0; i < g.
v.count(); ++i )
264 if ( v.
pt == pt || ( fabs( v.
pt.
x() - pt.
x() ) < epsilon && fabs( v.
pt.
y() - pt.
y() ) < epsilon ) )
276 for (
int i = 0; i < g.
e.count(); ++i )
285 lineVertexAfter = vertexAfter;
295 int count1 = lineVertexAfter;
296 int count2 = points.
count() - lineVertexAfter;
298 for (
int i = 0; i < count1; ++i )
300 if ( points[lineVertexAfter-1] != pt )
303 if ( pt != points[lineVertexAfter] )
305 for (
int i = 0; i < count2; ++i )
306 pts2 << points[i + lineVertexAfter];
314 int eIdx =
point2edge( g, pt, lineVertexAfter );
328 int vIdx = g.
v.count();
329 int e1Idx = g.
e.count();
330 int e2Idx = e1Idx + 1;
336 v.
edges << e1Idx << e2Idx;
385 if ( eIdx >= g.
e.count() )
391 if ( v1.
edges[i] >= g.
e.count() )
399 if ( v2.
edges[i] >= g.
e.count() )
417 if ( !segmentizedGeomV2 )
422 g = segmentizedGeom.
data();
457 , mReprojectionEnabled( false )
458 , mMaxFeatureCount( 0 )
459 , mHasTopologyProblem( false )
464 bool QgsTracer::initGraph()
469 mHasTopologyProblem =
false;
478 QTime t1, t2, t2a, t3;
481 int featuresCounted = 0;
497 if ( mReprojectionEnabled && !ct.isShortCircuited() )
512 if ( mMaxFeatureCount != 0 && featuresCounted >= mMaxFeatureCount )
516 int timeExtract = t1.
elapsed();
522 int timeNodingCall = 0;
534 timeNodingCall = t2a.
elapsed();
544 catch ( GEOSException &e )
549 mHasTopologyProblem =
true;
551 QgsDebugMsg(
"Tracer Noding Exception: " + e.what() );
563 Q_UNUSED( timeExtract );
564 Q_UNUSED( timeNoding );
565 Q_UNUSED( timeNodingCall );
566 Q_UNUSED( timeMake );
568 .arg( timeExtract ).arg( timeNoding ).arg( timeNodingCall ).arg( timeMake ) );
579 if ( mLayers == layers )
605 if ( mReprojectionEnabled == enabled )
608 mReprojectionEnabled = enabled;
623 if ( mExtent == extent )
667 void QgsTracer::onLayerDestroyed(
QObject* obj )
670 mLayers.
removeAll( static_cast<QgsVectorLayer*>( obj ) );
687 int tPrep = t.elapsed();
703 int tPath = t2.elapsed();
707 QgsDebugMsg(
QString(
"path timing: prep %1 ms, path %2 ms" ).arg( tPrep ).arg( tPath ) );
727 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)
Abstract base class for all geometries.
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.
static bool isCurvedType(Type type)
Returns true if the WKB type is a curved type or can contain curved geometries.
int removeAll(const T &value)
virtual QgsAbstractGeometryV2 * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
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.