Class: QgsTracer¶
Utility class that construct a planar graph from the input vector layers and provides shortest path search for tracing of existing features.
Class Hierarchy¶
Base classes¶
Subclasses¶
Extension of   | 
Methods
Returns whether the shortest path's straight segments will include vertices where the input layers intersect, even if no such vertex existed on the input layers  | 
|
Allows derived classes to setup the settings just before the tracer is initialized.  | 
|
Returns the CRS used for tracing.  | 
|
Gets extent to which graph's features will be limited (empty extent means no limit)  | 
|
Given two points, find the shortest path and return points on the way.  | 
|
Whether there was an error during graph creation due to noding exception, indicating some input data topology problems  | 
|
Build the internal data structures.  | 
|
Destroy the existing graph structure if any (de-initialize)  | 
|
Whether the internal data structures have been initialized  | 
|
Find out whether the point is snapped to a vertex or edge (i.e. it can be used for tracing start/stop).  | 
|
Gets layers used for tracing  | 
|
Gets maximum possible number of features in graph.  | 
|
Gets offset in map units that should be applied to the traced paths returned from   | 
|
Gets extra parameters for offset curve algorithm (used when offset is non-zero)  | 
|
When enable is   | 
|
Sets the crs and transform context used for tracing.  | 
|
Sets extent to which graph's features will be limited (empty extent means no limit)  | 
|
Sets layers used for tracing  | 
|
Gets maximum possible number of features in graph.  | 
|
Set offset in map units that should be applied to the traced paths returned from   | 
|
Set extra parameters for offset curve algorithm (used when offset is non-zero)  | 
|
Sets the renderContext used for tracing only on visible features.  | 
Attributes
- class qgis.core.QgsTracer[source]¶
 Bases:
QObject- __init__()
 Constructor for QgsTracer.
- ErrNoPath = 4¶
 
- ErrNone = 0¶
 
- ErrPoint1 = 2¶
 
- ErrPoint2 = 3¶
 
- ErrTooManyFeatures = 1¶
 
- class PathError¶
 Bases:
int
- addPointsOnIntersectionsEnabled(self) bool[source]¶
 Returns whether the shortest path’s straight segments will include vertices where the input layers intersect, even if no such vertex existed on the input layers
Added in version 3.40.
- Return type:
 bool
- configure(self)[source]¶
 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.
- destinationCrs(self) QgsCoordinateReferenceSystem[source]¶
 Returns the CRS used for tracing.
See also
- Return type:
 
- extent(self) QgsRectangle[source]¶
 Gets extent to which graph’s features will be limited (empty extent means no limit)
- Return type:
 
- findShortestPath(self, p1: QgsPointXY, p2: QgsPointXY)¶
 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
None- Returns:
 array of points - trace of linestrings of other features (empty array one error)
- Parameters:
 p1 (QgsPointXY)
p2 (
QgsPointXY) -> (List[QgsPointXY])
- hasTopologyProblem(self) bool[source]¶
 Whether there was an error during graph creation due to noding exception, indicating some input data topology problems
- Return type:
 bool
- init(self) bool[source]¶
 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.- Return type:
 bool
- isInitialized(self) bool[source]¶
 Whether the internal data structures have been initialized
- Return type:
 bool
- isPointSnapped(self, pt: QgsPointXY) bool[source]¶
 Find out whether the point is snapped to a vertex or edge (i.e. it can be used for tracing start/stop)
- Parameters:
 pt (QgsPointXY)
- Return type:
 bool
- layers(self) List[QgsVectorLayer]¶
 Gets layers used for tracing
- Return type:
 List[QgsVectorLayer]
- maxFeatureCount(self) int[source]¶
 Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
- Return type:
 int
- offset(self) float[source]¶
 Gets offset in map units that should be applied to the traced paths returned from
findShortestPath(). Positive offset for right side, negative offset for left side.- Return type:
 float
- offsetParameters(self)[source]¶
 Gets extra parameters for offset curve algorithm (used when offset is non-zero)
- setAddPointsOnIntersectionsEnabled(self, enable: bool)[source]¶
 When
enableisTrue, the shortest path’s straight segments will include vertices where the input layers intersect, even if no such vertex existed on the input layersAdded in version 3.40.
- Parameters:
 enable (bool)
- setDestinationCrs(self, crs: QgsCoordinateReferenceSystem, context: QgsCoordinateTransformContext)[source]¶
 Sets the
crsand transformcontextused for tracing.See also
- Parameters:
 context (QgsCoordinateTransformContext)
- setExtent(self, extent: QgsRectangle)[source]¶
 Sets extent to which graph’s features will be limited (empty extent means no limit)
- Parameters:
 extent (QgsRectangle)
- setLayers(self, layers: Iterable[QgsVectorLayer])[source]¶
 Sets layers used for tracing
- Parameters:
 layers (Iterable[QgsVectorLayer])
- setMaxFeatureCount(self, count: int)[source]¶
 Gets maximum possible number of features in graph. If the number is exceeded, graph is not created.
- Parameters:
 count (int)
- setOffset(self, offset: float)[source]¶
 Set offset in map units that should be applied to the traced paths returned from
findShortestPath(). Positive offset for right side, negative offset for left side.- Parameters:
 offset (float)
- setOffsetParameters(self, quadSegments: int, joinStyle: int, miterLimit: float)[source]¶
 Set extra parameters for offset curve algorithm (used when offset is non-zero)
- Parameters:
 quadSegments (int)
joinStyle (int)
miterLimit (float)
- setRenderContext(self, renderContext: QgsRenderContext | None)[source]¶
 Sets the
renderContextused for tracing only on visible features.Added in version 3.4.
- Parameters:
 renderContext (Optional[QgsRenderContext])