I have just started working with PyQGIS and I would like to ask this question. I have a rather big dataset (cell phone towers) and I want to narrow it in the towers that exist inside a certain country and I want to do it with PyQGIS. I used that piece of code:
lyrPts = QgsVectorLayer("/path/Cell-tower.shp", "CellTowers", "ogr")
lyrPoly =QgsVectorLayer("/path/GRC_adm0.shp", "GRC", "ogr")
QgsProject.instance().addMapLayers([lyrPts,lyrPoly])
ftsPoly = lyrPoly.getFeatures()
for feat in ftsPoly:
geomPoly = feat.geometry()
bbox = geomPoly.boundingBox()
req = QgsFeatureRequest()
filterRect = req.setFilterRect(bbox)
featsPnt = lyrPts.getFeatures(filterRect)
for featPnt in featsPnt:
if featPnt.geometry().within(geomPoly):
lyrPts.select(featPnt.id())
iface.setActiveLayer(lyrPoly)
iface.zoomToActiveLayer()
Although when I run it I don't get any errors I also don't get any results even when I left it running all night.
Can anyone help me and tell me if the code is good?
For reference the cell tower data I got them from mylnikov.org as a .csv file and made it to .shp file and the polygon from diva-gis.org.