[QGIS-Developer] use of clone

Antonio Locandro antoniolocandro at hotmail.com
Tue Jul 8 16:41:53 PDT 2025


True! Sorry I was just eager to get some help. The code is probably not so good, we are just learning with my dev which makes it a bit more interesting the questions. This used to work a few weeks ago maybe 2-3 weeks.

    for feat in point_layer.getFeatures():
        geom = feat.geometry()
        if point_crs != project_crs:
            geom = geom.clone()
            geom.transform(transform_point_to_project)
        if surface_geom.intersects(geom):
            new_feat = QgsFeature(feat)
            new_feat.setGeometry(geom)
            provider.addFeatures([new_feat])
            result['features'].append(new_feat)
            result['count'] += 1


Then I tried this and I get that clone() is not available

geom = QgsGeometry.fromWkt("POINT(0 0)")
try:
cloned = geom.clone()
print("clone() is available:", type(cloned))
except AttributeError:
print("clone() is NOT available on QgsGeometry")
clone() is NOT available on QgsGeometry

So we have found an alternative but still wondering what we had wrong to avoid in the future.
________________________________
From: Nyall Dawson <nyall.dawson at gmail.com>
Sent: Sunday, June 29, 2025 7:44 PM
To: Antonio Locandro <antoniolocandro at hotmail.com>
Cc: qgis-developer at lists.osgeo.org <qgis-developer at lists.osgeo.org>
Subject: Re: [QGIS-Developer] use of clone



On Sun, 29 Jun 2025 at 03:08, Antonio Locandro via QGIS-Developer <qgis-developer at lists.osgeo.org<mailto:qgis-developer at lists.osgeo.org>> wrote:
>
> Hello all!
>
> I had a script that used copy_geom = geom.clone() and worked until today that I updated QGIS.

> Any thoughts?

Yes  -- "it used to work" is not useful information at all! 🤪

Describe the actual error, including exception messages if appropriate. Include sample code so that we actually have some idea of what you're talking about. And never, EVER just tell developers "it doesn't work" without providing an excessive level of detail. 😜

Nyall



> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org<mailto: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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20250708/3ba3e6fe/attachment.htm>


More information about the QGIS-Developer mailing list