That would probably be the correct issue. I wrote some "working" code for the 
developer to have as starting basis so probably the AI as you mentioned added 
some garbage to it. Unfortunately, I tested it on my local machine, and it 
seemed to work for me but maybe I was not paying too much attention to it. Will 
try as you describe and make sure to check thoroughly the docs.

Thanks for the quick reply.
________________________________
From: Nyall Dawson <[email protected]>
Sent: Tuesday, July 8, 2025 6:06 PM
To: Antonio Locandro <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [QGIS-Developer] use of clone

On Wed, 9 Jul 2025 at 09:41, Antonio Locandro
<[email protected]> wrote:
>
> 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

This code, as it's written, would NEVER have worked. Maybe you use an
AI at some stage to fix something and it broke the code?

Try:

     for feat in point_layer.getFeatures():
         geom = feat.geometry()
         if point_crs != project_crs:
             # no need to 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

Or:

     request = QgsFeatureRequest()
     request.setDestinationCrs(project_crs,
QgsProject.instance().transformContext())
     for feat in point_layer.getFeatures(request):
         geom = feat.geometry()
         # no need to transform, it's now done for us!
         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 <[email protected]>
> Sent: Sunday, June 29, 2025 7:44 PM
> To: Antonio Locandro <[email protected]>
> Cc: [email protected] <[email protected]>
> Subject: Re: [QGIS-Developer] use of clone
>
>
>
> On Sun, 29 Jun 2025 at 03:08, Antonio Locandro via QGIS-Developer 
> <[email protected]> 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
> > [email protected]
> > List info: 
> > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-developer&data=05%7C02%7C%7Ceb6d0ae355d3475e0e3408ddbe7c7159%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638876163860459589%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=Ft%2FcBkeyrGso1xQnDqTTCI3W3yo287SxPUICBhzsGRY%3D&reserved=0<https://lists.osgeo.org/mailman/listinfo/qgis-developer>
> > Unsubscribe: 
> > https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.osgeo.org%2Fmailman%2Flistinfo%2Fqgis-developer&data=05%7C02%7C%7Ceb6d0ae355d3475e0e3408ddbe7c7159%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638876163860482370%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=VpmW9G%2B9pSMY%2BhiewpwQE70ZiBPSBzYotkIHq1wgTKU%3D&reserved=0<https://lists.osgeo.org/mailman/listinfo/qgis-developer>
_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to