Graphics Reference
In-Depth Information
Now that we know where the start point will be, we want to show this start point on the
map. If you remember, we previously created a memory-based map layer called
startPointLayer , to display this point. We'll need to first clear the contents of this
memory layer, deleting any existing features, and then create a new feature at the given
coordinate:
self.clearMemoryLayer(self.startPointLayer)
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromPoint(
self.curStartPt))
self.startPointLayer.dataProvider().addFeatures([feature])
self.startPointLayer.updateExtents()
Finally, we'll redraw the map canvas to show the newly added point, and switch back to
pan mode:
self.mapCanvas.refresh()
self.setPanMode()
self.adjustActions()
We'll need to implement the clearMemoryLayer() method, but before we do, let's
also define the onEndPointSelected() callback method so that we can respond
when the user clicks on the end point. The code for this is almost identical to the code for
onStartPointSelected() :
def onEndPointSelected(self, feature, vertex):
self.curEndPt = feature.geometry().vertexAt(vertex)
self.clearMemoryLayer(self.endPointLayer)
feature = QgsFeature()
feature.setGeometry(QgsGeometry.fromPoint(self.curEndPt))
self.endPointLayer.dataProvider().addFeatures([feature])
self.endPointLayer.updateExtents()
Search WWH ::




Custom Search