QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
26 #include "qgsfeatureid.h"
28 #include "qgsrectangle.h"
29 #include "qgsgeometry.h"
30 
31 struct QgsTracerGraph;
32 
41 class CORE_EXPORT QgsTracer : public QObject
42 {
43  Q_OBJECT
44  public:
45 
49  QgsTracer();
50  ~QgsTracer() override;
51 
53  QList<QgsVectorLayer *> layers() const { return mLayers; }
55  void setLayers( const QList<QgsVectorLayer *> &layers );
56 
62 
67  void setDestinationCrs( const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context );
68 
70  QgsRectangle extent() const { return mExtent; }
72  void setExtent( const QgsRectangle &extent );
73 
79  double offset() const { return mOffset; }
80 
86  void setOffset( double offset );
87 
92  void offsetParameters( int &quadSegments SIP_OUT, int &joinStyle SIP_OUT, double &miterLimit SIP_OUT );
93 
98  void setOffsetParameters( int quadSegments, int joinStyle, double miterLimit );
99 
101  int maxFeatureCount() const { return mMaxFeatureCount; }
103  void setMaxFeatureCount( int count ) { mMaxFeatureCount = count; }
104 
111  bool init();
112 
114  bool isInitialized() const { return static_cast< bool >( mGraph ); }
115 
121  bool hasTopologyProblem() const { return mHasTopologyProblem; }
122 
125  {
131  };
132 
138  QVector<QgsPointXY> findShortestPath( const QgsPointXY &p1, const QgsPointXY &p2, PathError *error SIP_OUT = nullptr );
139 
141  bool isPointSnapped( const QgsPointXY &pt );
142 
143  protected:
144 
150  virtual void configure() {}
151 
152  protected slots:
154  void invalidateGraph();
155 
156  private:
157  bool initGraph();
158 
159  private slots:
160  void onFeatureAdded( QgsFeatureId fid );
161  void onFeatureDeleted( QgsFeatureId fid );
162  void onGeometryChanged( QgsFeatureId fid, const QgsGeometry &geom );
163  void onLayerDestroyed( QObject *obj );
164 
165  private:
167  std::unique_ptr< QgsTracerGraph > mGraph;
169  QList<QgsVectorLayer *> mLayers;
173  QgsCoordinateTransformContext mTransformContext;
175  QgsRectangle mExtent;
176 
178  double mOffset = 0;
180  int mOffsetSegments = 8;
182  int mOffsetJoinStyle = 2;
184  double mOffsetMiterLimit = 5.;
185 
190  int mMaxFeatureCount = 0;
191 
196  bool mHasTopologyProblem = false;
197 };
198 
199 
200 #endif // QGSTRACER_H
bool hasTopologyProblem() const
Whether there was an error during graph creation due to noding exception, indicating some input data ...
Definition: qgstracer.h:121
A rectangle specified with double values.
Definition: qgsrectangle.h:40
virtual void configure()
Allows derived classes to setup the settings just before the tracer is initialized.
Definition: qgstracer.h:150
Utility class that construct a planar graph from the input vector layers and provides shortest path s...
Definition: qgstracer.h:41
A class to represent a 2D point.
Definition: qgspointxy.h:43
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
const QgsCoordinateReferenceSystem & crs
int maxFeatureCount() const
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:101
QgsCoordinateReferenceSystem destinationCrs() const
Returns the CRS used for tracing.
Definition: qgstracer.h:61
Max feature count threshold was reached while reading features.
Definition: qgstracer.h:127
PathError
Possible errors that may happen when calling findShortestPath()
Definition: qgstracer.h:124
double offset() const
Gets offset in map units that should be applied to the traced paths returned from findShortestPath()...
Definition: qgstracer.h:79
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:129
void setMaxFeatureCount(int count)
Gets maximum possible number of features in graph. If the number is exceeded, graph is not created...
Definition: qgstracer.h:103
QList< QgsVectorLayer * > layers() const
Gets layers used for tracing.
Definition: qgstracer.h:53
#define SIP_OUT
Definition: qgis_sip.h:51
bool isInitialized() const
Whether the internal data structures have been initialized.
Definition: qgstracer.h:114
This class represents a coordinate reference system (CRS).
No error.
Definition: qgstracer.h:126
QgsRectangle extent() const
Gets extent to which graph&#39;s features will be limited (empty extent means no limit) ...
Definition: qgstracer.h:70
Represents a vector layer which manages a vector based data sets.
Points are not connected in the graph.
Definition: qgstracer.h:130
Start point cannot be joined to the graph.
Definition: qgstracer.h:128