QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgstracer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstracer.h
3  --------------------------------------
4  Date : January 2016
5  Copyright : (C) 2016 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSTRACER_H
17 #define QGSTRACER_H
18 
19 class QgsVectorLayer;
20 
21 #include <QSet>
22 #include <QVector>
23 
25 #include "qgsfeature.h"
26 #include "qgspoint.h"
27 #include "qgsrectangle.h"
28 
29 struct QgsTracerGraph;
30 
38 class CORE_EXPORT QgsTracer : public QObject
39 {
40  Q_OBJECT
41  public:
42  QgsTracer();
43  ~QgsTracer();
44 
46  QList<QgsVectorLayer*> layers() const { return mLayers; }
48  void setLayers( const QList<QgsVectorLayer*>& layers );
49 
51  bool hasCrsTransformEnabled() const { return mReprojectionEnabled; }
53  void setCrsTransformEnabled( bool enabled );
54 
58  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
59 
61  QgsRectangle extent() const { return mExtent; }
63  void setExtent( const QgsRectangle& extent );
64 
66  int maxFeatureCount() const { return mMaxFeatureCount; }
68  void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
69 
74  bool init();
75 
77  bool isInitialized() const { return mGraph != nullptr; }
78 
82  bool hasTopologyProblem() const { return mHasTopologyProblem; }
83 
85  enum PathError
86  {
92  };
93 
97  QVector<QgsPoint> findShortestPath( const QgsPoint& p1, const QgsPoint& p2, PathError* error = nullptr );
98 
100  bool isPointSnapped( const QgsPoint& pt );
101 
102  protected:
106  virtual void configure() {}
107 
108  protected slots:
110  void invalidateGraph();
111 
112  private:
113  bool initGraph();
114 
115  private slots:
116  void onFeatureAdded( QgsFeatureId fid );
117  void onFeatureDeleted( QgsFeatureId fid );
118  void onGeometryChanged( QgsFeatureId fid, QgsGeometry& geom );
119  void onLayerDestroyed( QObject* obj );
120 
121  private:
123  QgsTracerGraph* mGraph;
125  QList<QgsVectorLayer*> mLayers;
127  bool mReprojectionEnabled;
131  QgsRectangle mExtent;
134  int mMaxFeatureCount;
137  bool mHasTopologyProblem;
138 };
139 
140 
141 #endif // QGSTRACER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:77
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:106
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition: qgstracer.h:38
QgsCoordinateReferenceSystem destinationCrs() const
Get CRS used for tracing.
Definition: qgstracer.h:56
QList< QgsVectorLayer * > layers() const
Get layers used for tracing.
Definition: qgstracer.h:46
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition: qgstracer.h:82
int maxFeatureCount() const
Get maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:66
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:88
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:85
bool hasCrsTransformEnabled() const
Return true if reprojection to destination CRS is enabled.
Definition: qgstracer.h:51
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:88
A class to represent a point.
Definition: qgspoint.h:117
End point cannot be joined to the graph.
Definition: qgstracer.h:90
void setMaxFeatureCount(int count)
Get maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:68
Class for storing a coordinate reference system (CRS)
QgsRectangle extent() const
Get extent to which graph&#39;s features will be limited (empty extent means no limit) ...
Definition: qgstracer.h:61
qint64 QgsFeatureId
Definition: qgsfeature.h:31
No error.
Definition: qgstracer.h:87
Represents a vector layer which manages a vector based data sets.
Points are not connected in the graph.
Definition: qgstracer.h:91
Start point cannot be joined to the graph.
Definition: qgstracer.h:89