QGIS API Documentation  2.99.0-Master (a18066b)
Public Types | Public Member Functions | Protected Slots | Protected Member Functions | List of all members
QgsTracer Class Reference

Utility class that construct a planar graph from the input vector layers and provides shortest path search for tracing of existing features. More...

#include <qgstracer.h>

Inheritance diagram for QgsTracer:
Inheritance graph
[legend]

Public Types

enum  PathError {
  ErrNone, ErrTooManyFeatures, ErrPoint1, ErrPoint2,
  ErrNoPath
}
 Possible errors that may happen when calling findShortestPath() More...
 

Public Member Functions

 QgsTracer ()
 
 ~QgsTracer ()
 
QgsCoordinateReferenceSystem destinationCrs () const
 Get CRS used for tracing. More...
 
QgsRectangle extent () const
 Get extent to which graph's features will be limited (empty extent means no limit) More...
 
QVector< QgsPointfindShortestPath (const QgsPoint &p1, const QgsPoint &p2, PathError *error=nullptr)
 Given two points, find the shortest path and return points on the way. More...
 
bool hasCrsTransformEnabled () const
 Return true if reprojection to destination CRS is enabled. More...
 
bool hasTopologyProblem () const
 Whether there was an error during graph creation due to noding exception, indicating some input data topology problems. More...
 
bool init ()
 Build the internal data structures. More...
 
bool isInitialized () const
 Whether the internal data structures have been initialized. More...
 
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) More...
 
QList< QgsVectorLayer * > layers () const
 Get layers used for tracing. More...
 
int maxFeatureCount () const
 Get maximum possible number of features in graph. If the number is exceeded, graph is not created. More...
 
void setCrsTransformEnabled (bool enabled)
 Set whether to do reprojection to destination CRS. More...
 
void setDestinationCrs (const QgsCoordinateReferenceSystem &crs)
 Set CRS used for tracing. More...
 
void setExtent (const QgsRectangle &extent)
 Set extent to which graph's features will be limited (empty extent means no limit) More...
 
void setLayers (const QList< QgsVectorLayer *> &layers)
 Set layers used for tracing. More...
 
void setMaxFeatureCount (int count)
 Get maximum possible number of features in graph. If the number is exceeded, graph is not created. More...
 

Protected Slots

void invalidateGraph ()
 Destroy the existing graph structure if any (de-initialize) More...
 

Protected Member Functions

virtual void configure ()
 Allows derived classes to setup the settings just before the tracer is initialized. More...
 

Detailed Description

Utility class that construct a planar graph from the input vector layers and provides shortest path search for tracing of existing features.

Note
added in QGIS 2.14

Definition at line 39 of file qgstracer.h.

Member Enumeration Documentation

◆ PathError

Possible errors that may happen when calling findShortestPath()

Enumerator
ErrNone 

No error.

ErrTooManyFeatures 

Max feature count threshold was reached while reading features.

ErrPoint1 

Start point cannot be joined to the graph.

ErrPoint2 

End point cannot be joined to the graph.

ErrNoPath 

Points are not connected in the graph.

Definition at line 86 of file qgstracer.h.

Constructor & Destructor Documentation

◆ QgsTracer()

QgsTracer::QgsTracer ( )

Definition at line 456 of file qgstracer.cpp.

◆ ~QgsTracer()

QgsTracer::~QgsTracer ( )

Definition at line 575 of file qgstracer.cpp.

Member Function Documentation

◆ configure()

virtual void QgsTracer::configure ( )
inlineprotectedvirtual

Allows derived classes to setup the settings just before the tracer is initialized.

This allows the configuration to be set in a lazy way only when it is really necessary. Default implementation does nothing.

Reimplemented in QgsMapCanvasTracer.

Definition at line 107 of file qgstracer.h.

◆ destinationCrs()

QgsCoordinateReferenceSystem QgsTracer::destinationCrs ( ) const
inline

Get CRS used for tracing.

Definition at line 57 of file qgstracer.h.

◆ extent()

QgsRectangle QgsTracer::extent ( ) const
inline

Get extent to which graph's features will be limited (empty extent means no limit)

Definition at line 62 of file qgstracer.h.

◆ findShortestPath()

QVector< QgsPoint > QgsTracer::findShortestPath ( const QgsPoint p1,
const QgsPoint p2,
PathError error = nullptr 
)

Given two points, find the shortest path and return points on the way.

The optional "error" argument may receive error code (PathError enum) if it is not null

Returns
array of points - trace of linestrings of other features (empty array one error)

Definition at line 676 of file qgstracer.cpp.

◆ hasCrsTransformEnabled()

bool QgsTracer::hasCrsTransformEnabled ( ) const
inline

Return true if reprojection to destination CRS is enabled.

Definition at line 52 of file qgstracer.h.

◆ hasTopologyProblem()

bool QgsTracer::hasTopologyProblem ( ) const
inline

Whether there was an error during graph creation due to noding exception, indicating some input data topology problems.

Note
added in QGIS 2.16

Definition at line 83 of file qgstracer.h.

◆ init()

bool QgsTracer::init ( )

Build the internal data structures.

This may take some time depending on how big the input layers are. It is not necessary to call this method explicitly - it will be called by findShortestPath() if necessary.

Definition at line 633 of file qgstracer.cpp.

◆ invalidateGraph

void QgsTracer::invalidateGraph ( )
protectedslot

Destroy the existing graph structure if any (de-initialize)

Definition at line 645 of file qgstracer.cpp.

◆ isInitialized()

bool QgsTracer::isInitialized ( ) const
inline

Whether the internal data structures have been initialized.

Definition at line 78 of file qgstracer.h.

◆ isPointSnapped()

bool QgsTracer::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)

Definition at line 719 of file qgstracer.cpp.

◆ layers()

QList<QgsVectorLayer*> QgsTracer::layers ( ) const
inline

Get layers used for tracing.

Definition at line 47 of file qgstracer.h.

◆ maxFeatureCount()

int QgsTracer::maxFeatureCount ( ) const
inline

Get maximum possible number of features in graph. If the number is exceeded, graph is not created.

Definition at line 67 of file qgstracer.h.

◆ setCrsTransformEnabled()

void QgsTracer::setCrsTransformEnabled ( bool  enabled)

Set whether to do reprojection to destination CRS.

Definition at line 606 of file qgstracer.cpp.

◆ setDestinationCrs()

void QgsTracer::setDestinationCrs ( const QgsCoordinateReferenceSystem crs)

Set CRS used for tracing.

Definition at line 615 of file qgstracer.cpp.

◆ setExtent()

void QgsTracer::setExtent ( const QgsRectangle extent)

Set extent to which graph's features will be limited (empty extent means no limit)

Definition at line 624 of file qgstracer.cpp.

◆ setLayers()

void QgsTracer::setLayers ( const QList< QgsVectorLayer *> &  layers)

Set layers used for tracing.

Definition at line 580 of file qgstracer.cpp.

◆ setMaxFeatureCount()

void QgsTracer::setMaxFeatureCount ( int  count)
inline

Get maximum possible number of features in graph. If the number is exceeded, graph is not created.

Definition at line 69 of file qgstracer.h.


The documentation for this class was generated from the following files: