[QGIS-Developer] pyqgis QgsGeometrySnapper does not snap to a source created inside a function

Germán Carrillo carrillo.german at gmail.com
Thu Oct 19 09:03:47 PDT 2023


Hi Gabriel,

Does the result change if you first create a Python variable for storing
your new layer?
I mean:


*referenceSource = create_scratch_reference_layer()*
*snapper = QgsGeometrySnapper(referenceSource)*

instead of:

*snapper = QgsGeometrySnapper(*
*    referenceSource=create_scratch_reference_layer()*
*)*

Regards,

Germán


El jue, 19 oct 2023 a las 14:46, Gabriel De Luca via QGIS-Developer (<
qgis-developer at lists.osgeo.org>) escribió:

> Hello all,
>
>   I am working with the QgsGeometrySnapper pyqgis class, and have a
> problem to snap to a reference layer which is created inside a function
> (and returned by it).
>
>   The code shared at [1] prints:
>
> result = <QgsGeometry: Polygon ((0.10000000000000001 -0.10000000000000001,
> 10.09999999999999964 0, 9.90000000000000036 10.09999999999999964, 0 10,
> 0.10000000000000001 -0.10000000000000001))>
>
>   Which means that the geomPolygon was not snapped to the reference layer.
>   But, if uncomment the line 41, which adds the reference layer to the
> project, the code prints:
>
> result = <QgsGeometry: Polygon ((0 0, 10 0, 10 10, 0 10, 0 0))>
>
>   So, for some reason, adding the reference layer to the project makes the
> snapper to work.
>
>   I want to ask you if you know why is this happening. Maybe I need to add
> something to make it work consistently.
>
>
> Regards,
> Gabriel
>
> [1] https://pastebin.com/raw/Y9v51ZMq
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>


-- 
-----------
   |\__
(:>__)(
   |/
Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
https://twitter.com/GeoTux2 <http://twitter.com/GeoTux2>

<http://gis.stackexchange.com/users/4972/germ%c3%a1n-carrillo>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20231019/24ed614d/attachment.htm>


More information about the QGIS-Developer mailing list