[Qgis-developer] Python Snapping
Martin Dobias
wonder.sk at gmail.com
Sat Nov 14 10:16:04 EST 2009
2009/11/12 Maurício de Paulo <mauricio.dev at gmail.com>:
> Hi,
> I've been working on the QgsAzimuth plugin and recently some users told me
> of a limitation on the code I wrote.
> The snapping is not with enough precision.
> The following code is the event that I wrote that tries to use snap and if
> not possible, use the captured pixel as coordinate. Is it the right way of
> implementing a snap tool?
>
> def canvasPressEvent(self,event):
> pixels=event.pos()
> snapper=QgsMapCanvasSnapper(self.canvas)
> snapped=snapper.snapToBackgroundLayers(pixels)
> if len(snapped[1])>0:
> xy=snapped[1][0].afterVertex
> else:
> #transforming pixels to x,y
> transform = self.canvas.getCoordinateTransform()
> xy = transform.toMapCoordinates(pixels) #captures the clicked
> coordinate and transform
> self.emit(SIGNAL("finished(PyQt_PyObject)"),xy) #return QgsPoint in
> a signal
Hi,
could you quantify how big is the loss of precision (expected vs.
obtained coordinates)?
>From a quick look the code for snapping should be fine.
Martin
More information about the Qgis-developer
mailing list