AW: [Qgis-user] getting QgsMapCanvasSnapper to work
Hugentobler Marco
marco.hugentobler at karto.baug.ethz.ch
Tue Nov 18 14:00:19 PST 2008
Hi Cedric
I used your code lines and started the debugger. It seems that the QgsMapCanvasSnapper works correctly. I think the problem has to do with the QList reference in the binding:
int snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results, QgsSnapper::SnappingType snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() );
I tried to change that to:
int snapToCurrentLayer( const QPoint& p, QList<QgsSnappingResult>& results /Out/, QgsSnapper::SnappingType snap_to, double snappingTol = -1, const QList<QgsPoint>& excludePoints = QList<QgsPoint>() );
But then Python complains about a wrong type of the results parameter with your code. I tried to use a 'QList' instead of '[]', but it seems there is no QList in PyQt?
Python experts: How can we deal with QList in PyQGIS?
Regards,
Marco
-----Ursprüngliche Nachricht-----
Von: qgis-user-bounces at lists.osgeo.org im Auftrag von Möri Cedric
Gesendet: Di 18.11.2008 18:43
An: qgis-user at lists.osgeo.org
Betreff: [Qgis-user] getting QgsMapCanvasSnapper to work
Hi all!
I'm trying to snap a vertex with my python plugin. (Many thanks to Martin for the quick work with the bindings!)
My code looks like this:
def canvasReleaseEvent(self,event):
x = event.pos().x()
y = event.pos().y()
startingPoint = QPoint(x,y)
result = []
excludePoints = []
snapper = QgsMapCanvasSnapper(self.canvas)
snapper.snapToCurrentLayer (startingPoint,result,QgsSnapper.SnapToVertex, 10000, excludePoints)
print "result: ",result
The problem is, whatever I do, the result keeps empty. I tried to play with tolerance and scale and I'm quite sure it has to find a vertex but without any success (the layer unit is meter).
So I thought about using QgsSnapper directly. But I'm not able to set it up properly. Doing the following snippet always leads to a attribut error on the snapLayer struct.
snapLayer = QgsSnapper.SnapLayer
snapLayer.mLayer = self.iface.mapCanvas().currentLayer()
snapLayer.mTolerance = 1000
snapLayer.mSnapTo = QgsSnapper.SnapToVertex
So, if anyone has a hint why the QgsMapCanvasSnapper doesn't want to give me a result or how I set up the struct correctly, it would be wonderful to share it with me :-)
Best regards and kudos to all the helping people here on the list!
Cédric
mit freundlichen Grüssen
Cédric Möri
GIS-Informatiker
--
Kanton Solothurn
Bau- und Justizdepartement
Amt für Geoinformation
Rötistrasse 4
4501 Solothurn
Telefon: +41 (0)32 627 24 75
Telefax: +41 (0)32 627 22 14
mailto:cedric.moeri at bd.so.ch
http://www.agi.so.ch
_______________________________________________
Qgis-user mailing list
Qgis-user at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/qgis-user
More information about the Qgis-user
mailing list