Graphics Reference
In-Depth Information
director = QgsLineVectorLayerDirector(
self.trackLayer, directionField,
TRACK_DIRECTION_FORWARD,
TRACK_DIRECTION_BACKWARD,
TRACK_DIRECTION_BOTH, 3)
This piece of code creates an object which converts a set of LineString features into an ab-
stract graph of the layer's features. The various parameters specify which of the track's at-
tributes will be used to define the various directions in which a track can be followed. Bi-
directional tracks can be followed in either direction, while forward and reverse direction-
al tracks can be followed in only one direction.
Note
The final parameter, with the value 3 , tells the director to treat any track without a valid
direction value as bidirectional.
Once we have the set of points that define the shortest path, it's easy to display those
points as a LineString in the memory layer and make the resulting path visible on the
map:
self.clearMemoryLayer(self.shortestPathLayer)
provider = self.shortestPathLayer.dataProvider()
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromPolyline(points))
provider.addFeatures([feature])
self.shortestPathLayer.updateExtents()
self.mapCanvas.refresh()
If you define the starting and ending points, and then click on the Find Shortest Path
toolbar action, the resulting path will be displayed as a blue line on the map, as shown in
the following screenshot:
Search WWH ::




Custom Search