I have one polygon and onde shp of points (some within and others without the polygon). I have tried the following code:
layers = QgsProject.instance().mapLayers()
for feature in layers['poly_teste_1'].getFeatures():
geom_poly=feature.geometry()
for feature2 in layers['points_test2_2'].getFeatures():
geom_point=feature2.geometry()
i=0
for points in layers['pointo_test2_2'].getFeatures():
if geom_poly.contains(geom_point):
i=i+1
print(i)
The problem is that the code a printing the total number of points, and not only the ones that are within the polygon.