<div dir="ltr">Try calling layer.commitChanges() after changing the geometry.<br><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div></div><div><table cellpadding="0" cellspacing="0" style="border-spacing:0px;border-collapse:collapse;color:rgb(68,68,68);width:480px;font-size:10pt;font-family:Arial,sans-serif;line-height:normal"><tbody><tr><td valign="top" style="padding:10px 0px 12px;width:160px;vertical-align:top"><a href="https://spatialthoughts.com/" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img border="0" alt="Logo" width="141" src="https://spatialthoughts685850346.files.wordpress.com/2019/12/spatial_thoughts_logo.png" style="border:0px;vertical-align:middle;width:141px;height:auto"></a></td><td style="padding:6px 0px;width:320px"><table cellpadding="0" cellspacing="0" style="border-spacing:0px;border-collapse:collapse;background-color:transparent"><tbody><tr><td style="padding:0px;font-size:12pt;font-family:Arial,sans-serif;font-weight:bold;color:rgb(61,60,63)"><span style="color:rgb(0,175,239)">Ujaval Gandhi</span></td></tr><tr><td style="padding:0px 0px 11px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(61,60,63)"><span style="color:rgb(0,175,239)">Spatial Thoughts</span></td></tr><tr><td style="padding:0px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(155,155,155)"><span>mobile: +91-8095684687</span></td></tr><tr><td style="padding:0px;font-size:10pt;font-family:Arial,sans-serif;color:rgb(155,155,155)"><span>email: </span><span style="color:rgb(23,147,210)"><a href="mailto:ujaval@spatialthoughts.com" target="_blank">ujaval@spatialthoughts.com</a></span></td></tr><tr><td style="padding:6px 0px 0px"><span style="display:inline-block;height:22px"><span><a href="https://www.linkedin.com/in/spatialthoughts/" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img alt="LinkedIn icon" border="0" width="23" height="23" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator/elegant-logo/ln.png" style="border:0px;vertical-align:middle;height:20px;width:20px"></a> </span><span><a href="https://twitter.com/spatialthoughts" style="background-color:transparent;color:rgb(51,122,183)" target="_blank"><img alt="Twitter icon" border="0" width="23" height="23" src="https://codetwocdn.azureedge.net/images/mail-signatures/generator/elegant-logo/tt.png" style="border:0px;vertical-align:middle;height:20px;width:20px"></a> </span></span></td></tr></tbody></table></td></tr><tr><td colspan="2" style="padding:8px 0px 0px;border-top:1px solid rgb(23,147,210);width:480px;font-family:Arial,sans-serif;color:rgb(155,155,155);text-align:justify"></td></tr></tbody></table><br></div></div></div></div></div></div></div></div></div></div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Dec 11, 2021 at 6:55 PM Erik Polzin <<a href="mailto:eriktpol@gmail.com">eriktpol@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>Noticed some strange behaviour in QGIS' Python API the other day.</div><div>I needed to get a subset of points from a memory layer of point features, and had previously done so by calling <font face="monospace">getFeatures()</font>, and then filtering this iterable in Python. I thought I could speed it up by using a filter expression directly to let c++ do the filtering instead, but was surprised to see that now the geometry wasn't up to date with the memory layer's edit buffer.</div><div><br></div><div>I've replicated the behaviour it in a small script here:</div><div><br></div><div><font face="monospace">from qgis.core import QgsVectorLayer, QgsField, QgsGeometry, QgsPointXY, QgsFeature<br>from PyQt5.QtCore import QVariant<br><br>layer = QgsVectorLayer("Point", "test", "memory")<br>pr = layer.dataProvider()<br>pr.addAttributes([QgsField("name", QVariant.String)])<br>layer.updateFields()<br><br>initialGeom = QgsGeometry.fromPointXY(QgsPointXY(0, 0))<br>f = QgsFeature()<br>f.setGeometry(initialGeom)<br>f.setAttributes(["Tom"])<br>added, (f,) = layer.dataProvider().addFeatures([f])<br><br>layer.startEditing()<br>editedGeom = QgsGeometry.fromPointXY(QgsPointXY(1, 1))<br>layer.changeGeometry(<a href="http://f.id" target="_blank">f.id</a>(), editedGeom)<br>layer.changeAttributeValues(<a href="http://f.id" target="_blank">f.id</a>(), {0: "Harry"})<br><br>for f in layer.getFeatures():<br> print(<a href="http://f.id" target="_blank">f.id</a>(), f.attributes(), f.geometry())<br><br>for f in layer.getFeatures("name = 'Harry'"):<br> print(<a href="http://f.id" target="_blank">f.id</a>(), f.attributes(), f.geometry())<br><br># >>> Prints different results!</font><br></div><div><br></div><div>This only seems to happen with both calls to <font face="monospace">changeGeometry</font> and <font face="monospace">changeAttributeValues</font>.</div><div>Is there some way of getting around this? Would it be classified as a bug in the API?</div><div><br></div><div>Cheers,</div><div>Erik</div></div>
_______________________________________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org" target="_blank">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div>