[Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)

DelazJ delazj at gmail.com
Fri Aug 12 05:36:07 PDT 2016


Hi Casper,
this page may need some update. Not many pythonistas are currently
available to improve the PyQGIS Cookbook pages so once you went through the
process and are aware of the best practices on this side, a couple of code
sample or hints would be very welcome.

Thanks,
Harrissou

2016-08-12 14:26 GMT+02:00 Casper Børgesen (CABO) <CABO at niras.dk>:

> Hi Martin
>
> Going through the layer object works much better, thanks yet again :)
>
> Since I cannot remember all the syntaxes and ways to do stuff I found this
> page, which I have found so many times now:
>
> http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html
>
> The page suggest that you go through the data provider. Perhaps that is
> not the best way to go anymore, or does it depend on what you want to do?
>
>
> Regards, Casper
>
> -----Original Message-----
> From: Martin Dobias [mailto:wonder.sk at gmail.com]
> Sent: 12. august 2016 13:21
> To: Casper Børgesen (CABO)
> Cc: qgis-developer at lists.osgeo.org
> Subject: Re: [Qgis-developer] Python: How to allow for more results using
> QgsSnapper.snapMapPoint(...)
>
> Hi Casper
>
> On Fri, Aug 12, 2016 at 12:56 PM, Casper Børgesen (CABO) <CABO at niras.dk>
> wrote:
> > 1. I have enabled snapping
> > 2. The user snaps to an edge.
> > 3. I then cut up a geometry (the one the user snapped to), replacing the
> geometry of the snapped feature and insert new features for the remaining
> geometries from the cut.
> > 4. Snapping now only works on the geometry which weren't changed and
> part of the changed geometry.
> >
> > Cut pseudo code:
> >     geometry = QgsGeometry(f.geometry())
> >     (result, other, pts) = geometry.splitGeometry([p1, ..., pn])
> >
> >     # Update feature.
> >     layer.startEditing()
> >     layer.dataProvider().changeGeometryValues({f.id() : geometry})
> >     # Insert new feature.
> >     f2 = QgsFeature(layer.pendingFields())
> >     f2.setAttributes(f.attributes())
> >     f2.setGeometry(other[0])
> >     layer().dataProvider().addFeatures([f2])
> >     layer.commitChanges()
> >
> > I can think of two reasons here. Either I do the cutting in an
> impropriate way or I need to update an index somewhere.
>
> Use layer.changeGeometry() and layer.addFeatures() instead of the methods
> from data provider. They do not notify the rest of the app about the
> changes, so the index does not get updated.
>
> Maybe even better you can use QgsVectorLayerEditUtils.splitFeatures()
> to cut features (it will do the splitGeometry calls, change geometries and
> add features).
>
> Cheers
> Martin
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> List info: http://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20160812/061bf690/attachment-0001.html>


More information about the Qgis-developer mailing list