QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgis_core.h"
22 #include <QSet>
23 #include <QVector>
24 #include <memory>
25 
27 #include "qgsfeature.h"
28 #include "qgsrectangle.h"
29 
30 struct QgsTracerGraph;
31 
40 class CORE_EXPORT QgsTracer : public QObject
41 {
42  Q_OBJECT
43  public:
44 
48  QgsTracer();
49  ~QgsTracer() override;
50 
52  QList<QgsVectorLayer *> layers() const { return mLayers; }
54  void setLayers( const QList<QgsVectorLayer *> &layers );
55 
61 
66  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
67 
69  QgsRectangle extent() const { return mExtent; }
71  void setExtent( const QgsRectangle &extent );
72 
78  double offset() const { return mOffset; }
79 
85  void setOffset( double offset );
86 
91  void offsetParameters( int &quadSegments SIP_OUT, int &joinStyle SIP_OUT, double &miterLimit SIP_OUT );
92 
97  void setOffsetParameters( int quadSegments, int joinStyle, double miterLimit );
98 
100  int maxFeatureCount() const { return mMaxFeatureCount; }
102  void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
103 
110  bool init();
111 
113  bool isInitialized() const { return static_cast< bool >( mGraph ); }
114 
120  bool hasTopologyProblem() const { return mHasTopologyProblem; }
121 
124  {
130  };
131 
137  QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
138 
140  bool isPointSnapped( const QgsPointXY &pt );
141 
142  protected:
143 
149  virtual void configure() {}
150 
151  protected slots:
153  void invalidateGraph();
154 
155  private:
156  bool initGraph();
157 
158  private slots:
159  void onFeatureAdded( QgsFeatureId fid );
160  void onFeatureDeleted( QgsFeatureId fid );
161  void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
162  void onLayerDestroyed( QObject *obj );
163 
164  private:
166  std::unique_ptr< QgsTracerGraph > mGraph;
168  QList<QgsVectorLayer *> mLayers;
172  QgsCoordinateTransformContext mTransformContext;
174  QgsRectangle mExtent;
175 
177  double mOffset = 0;
179  int mOffsetSegments = 8;
181  int mOffsetJoinStyle = 2;
183  double mOffsetMiterLimit = 5.;
184 
189  int mMaxFeatureCount = 0;
190 
195  bool mHasTopologyProblem = false;
196 };
197 
198 
199 #endif // QGSTRACER_H
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition: qgstracer.h:52
A rectangle specified with double values.
Definition: qgsrectangle.h:40
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:113
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:149
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition: qgstracer.h:40
A class to represent a 2D point.
Definition: qgspointxy.h:43
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition: qgstracer.h:60
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:104
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition: qgstracer.h:120
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath()...
Definition: qgstracer.h:78
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:100
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:126
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:123
Simple graph structure for shortest path search.
Definition: qgstracer.cpp:91
Contains information about the context in which a coordinate transform is executed.
End point cannot be joined to the graph.
Definition: qgstracer.h:128
void setMaxFeatureCount(int count)
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:102
#define SIP_OUT
Definition: qgis_sip.h:51
This class represents a coordinate reference system (CRS).
QgsRectangle extent() const
Gets extent to which graph&#39;s features will be limited (empty extent means no limit) ...
Definition: qgstracer.h:69
qint64 QgsFeatureId
Definition: qgsfeature.h:37
No error.
Definition: qgstracer.h:125
Represents a vector layer which manages a vector based data sets.
Points are not connected in the graph.
Definition: qgstracer.h:129
Start point cannot be joined to the graph.
Definition: qgstracer.h:127