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://lists.osgeo.org/mailman/listinfo/qgis-developer
> > Unsubscribe: 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