Hi,
I'm doing my "once a year need to do something in python with QGIS" :-/
Using QGIS 3.38 and PyCharm.

I have a SHP file with 28000 polygons.
Another SHP file with 22000 Points
Both in EPSG:4326

Without using QGIS processing, what is the quickest way to, for each point 1 by 1, find the underlying polygon and read the attribute field values of that polygon? The code snippet below is far too inefficient - but I cannot find code that selects at XY and benefits from any spatial index on the polygons.

        lyr_poly = QgsVectorLayer(polygon_shp, '', 'Ogr')       point =
   QgsPointXY(lon, lat)       request =
   QgsFeatureRequest().setFilterRect(lyr_poly.extent())       for
   feature in lyr_poly.getFeatures(request):           geom =
   feature.geometry()           if
   geom.contains(QgsGeometry.fromPointXY(point)):           
   lyr_poly.select(feature.id())               print(f"Feature with ID
   {feature.id()} is selected.")               break

Thanks in advance,
Zoltan

_______________________________________________
QGIS-User mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to