vlPolygons = QgsVectorLayer("C:\\Users\Windows\\Documents\\python_code\\test_contains\\us.shp", "poligono", "ogr")
featPoly = QgsFeature()
vlPoints = QgsVectorLayer("C:\\Users\\Windows\\Documents\python_code\\test_contains\\quote.shp", "punto", "ogr")
featPoints = QgsFeature()
if not vlPolygons.isValid():
print "Layer failed to load!"
if not vlPoints.isValid():
print "Layer failed to load!"
iterPoly = vlPolygons.getFeatures()
iterPoints = vlPoints.getFeatures()
vlPoints.select( [] )
list_poly = []
for i in iterPoly:
list_poly.append(i)
results_true = []
results_false = []
for feature in list_poly:
iterPoints = vlPoints.getFeatures()
geom = feature.geometry()
bbox = feature.geometry().boundingBox()
pointBBox = vlPoints.select( feature.geometry().boundingBox(), True)
#print "geom is %d" % feature.id()
for points in iterPoints:
#print "geom is %d" % feature.id()
if geom.contains( points.geometry()) == True:
results_true.append('US%d contains Quota %d' % (feature.id(),points.id()))
print results_true