<div dir="ltr"><div><div><div>Hi Casper,<br></div>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.<br><br></div>Thanks,<br></div>Harrissou<br></div><div class="gmail_extra"><br><div class="gmail_quote">2016-08-12 14:26 GMT+02:00 Casper Børgesen (CABO) <span dir="ltr"><<a href="mailto:CABO@niras.dk" target="_blank">CABO@niras.dk</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Martin<br>
<br>
Going through the layer object works much better, thanks yet again :)<br>
<br>
Since I cannot remember all the syntaxes and ways to do stuff I found this page, which I have found so many times now:<br>
<br>
<a href="http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html" rel="noreferrer" target="_blank">http://docs.qgis.org/testing/<wbr>en/docs/pyqgis_developer_<wbr>cookbook/vector.html</a><br>
<br>
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?<br>
<span class="im HOEnZb"><br>
<br>
Regards, Casper<br>
<br>
-----Original Message-----<br>
From: Martin Dobias [mailto:<a href="mailto:wonder.sk@gmail.com">wonder.sk@gmail.com</a>]<br>
</span><span class="im HOEnZb">Sent: 12. august 2016 13:21<br>
To: Casper Børgesen (CABO)<br>
Cc: <a href="mailto:qgis-developer@lists.osgeo.org">qgis-developer@lists.osgeo.org</a><br>
Subject: Re: [Qgis-developer] Python: How to allow for more results using QgsSnapper.snapMapPoint(...)<br>
<br>
</span><div class="HOEnZb"><div class="h5">Hi Casper<br>
<br>
On Fri, Aug 12, 2016 at 12:56 PM, Casper Børgesen (CABO) <<a href="mailto:CABO@niras.dk">CABO@niras.dk</a>> wrote:<br>
> 1. I have enabled snapping<br>
> 2. The user snaps to an edge.<br>
> 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.<br>
> 4. Snapping now only works on the geometry which weren't changed and part of the changed geometry.<br>
><br>
> Cut pseudo code:<br>
>     geometry = QgsGeometry(f.geometry())<br>
>     (result, other, pts) = geometry.splitGeometry([p1, ..., pn])<br>
><br>
>     # Update feature.<br>
>     layer.startEditing()<br>
>     layer.dataProvider().<wbr>changeGeometryValues({<a href="http://f.id" rel="noreferrer" target="_blank">f.id</a>() : geometry})<br>
>     # Insert new feature.<br>
>     f2 = QgsFeature(layer.<wbr>pendingFields())<br>
>     f2.setAttributes(f.attributes(<wbr>))<br>
>     f2.setGeometry(other[0])<br>
>     layer().dataProvider().<wbr>addFeatures([f2])<br>
>     layer.commitChanges()<br>
><br>
> I can think of two reasons here. Either I do the cutting in an impropriate way or I need to update an index somewhere.<br>
<br>
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.<br>
<br>
Maybe even better you can use QgsVectorLayerEditUtils.<wbr>splitFeatures()<br>
to cut features (it will do the splitGeometry calls, change geometries and add features).<br>
<br>
Cheers<br>
Martin<br>
______________________________<wbr>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br>
List info: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
Unsubscribe: <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a></div></div></blockquote></div><br></div>