I have a series of locations stored within a Vector layer and want to write a query to understand which of these locations fall within the polygons from another layer using the QGIS Python console.
So far I have got this code - however it returns all locations, some of them several times.
canvas = qgis.utils.iface.mapCanvas()layer1 = canvas.layer(0) #layer 1 is the polygonslayer2 = canvas.layer(1) #layer 2 is the locationsfeaturesloc = layer2.getFeatures()for feature in featuresloc: geomloc = feature.geometry() featurespol = layer2.getFeatures() for featurep in featurespol: if featurep.geometry().within(geomloc): attributes = feature.attributes() print attributes
Can anyone provide any pointers as to how I can correct this?
أكثر...
So far I have got this code - however it returns all locations, some of them several times.
canvas = qgis.utils.iface.mapCanvas()layer1 = canvas.layer(0) #layer 1 is the polygonslayer2 = canvas.layer(1) #layer 2 is the locationsfeaturesloc = layer2.getFeatures()for feature in featuresloc: geomloc = feature.geometry() featurespol = layer2.getFeatures() for featurep in featurespol: if featurep.geometry().within(geomloc): attributes = feature.attributes() print attributes
Can anyone provide any pointers as to how I can correct this?
أكثر...