<div dir="ltr"><div dir="ltr"><div>Hi,</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le jeu. 11 févr. 2021 à 23:49, Nyall Dawson <<a href="mailto:nyall.dawson@gmail.com">nyall.dawson@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, 12 Feb 2021 at 05:13, Andrea Giudiceandrea<br>
<<a href="mailto:andreaerdna@libero.it" target="_blank">andreaerdna@libero.it</a>> wrote:<br>
><br>
> Hi all,<br>
> is it expected that QgsGeometry constGet() and constParts() in PyQGIS return<br>
> modifiable objects?<br>
<br>
Yes -- python doesn't have any concept of "const", so ALL objects are<br>
modifiable as a result.<br>
<br></blockquote><div>So should we not pythonify the pyqgis docs (<a href="https://qgis.org/pyqgis/master/core/QgsGeometry.html#qgis.core.QgsGeometry.constParts">https://qgis.org/pyqgis/master/core/QgsGeometry.html#qgis.core.QgsGeometry.constParts</a>) and avoid misleading beginners (like me in the docs PR previously mentioned)?</div><div><br></div><div>Regards,</div><div>Harrissou<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> In the Python Console:<br>
><br>
> >>> geom=QgsGeometry.fromWkt( 'Point(16 41)' )<br>
> >>> geom_const=geom.constGet()<br>
> >>> geom_const.transform(QgsCoordinateTransform(QgsCoordinateReferenceSystem("EPSG:4326"),<br>
> >>> QgsCoordinateReferenceSystem("EPSG:25833"), QgsProject.instance()))<br>
><br>
> >>> geom_const<br>
> <QgsPoint: Point (584102.13444570498540998 4539238.58925933390855789)><br>
> >>> geom<br>
> <QgsGeometry: Point (584102.13444570498540998 4539238.58925933390855789)><br>
><br>
><br>
> >>> geom=QgsGeometry.fromWkt( 'MultiPoint((16 41))' )<br>
> >>> for part in geom.constParts():<br>
><br>
> part.transform(QgsCoordinateTransform(QgsCoordinateReferenceSystem("EPSG:4326"),<br>
> QgsCoordinateReferenceSystem("EPSG:25833"), QgsProject.instance()))<br>
><br>
> >>> geom<br>
> <QgsGeometry: MultiPoint ((584102.13444570498540998<br>
> 4539238.58925933390855789))><br>
<br>
Those results are as expected, but somewhat of a trap! I'd usually<br>
only recommend that developers who are well aware of the dangers here<br>
use the constGet method, and only do so in performance critical code<br>
where they know they aren't changing the object.<br>
<br>
Nyall<br>
<br>
<br>
><br>
><br>
> Regards.<br>
><br>
> Andrea Giudiceandrea<br>
><br>
><br>
><br>
> --<br>
> Sent from: <a href="http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html" rel="noreferrer" target="_blank">http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html</a><br>
> _______________________________________________<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>
_______________________________________________<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></div>