I have a Point shapefile and a Polygon shapefile. Is it possible to create a field into the attribute table of the Polygon shapefile with the count of points inside each polygon, such that if I add a new point inside a polygon in a later moment the change is automatically reflected in the Count Field?
- In the vector layer properties, under the field tab, open the field calculator.
- Set it as new and virtual field.
- Name it as you wish.
- And in the expression, enter
num_points( $geometry )
The field will be automatically updated. Although, when editing, the field is updated only when you actually commit the changes to the layer.
I found out a way to do what I wanted using the plug-in refFunctions.
In the polygon layer, I created a virtual field with the expression
intersecting_geom_count('PointsLayerName'). If I add or move points inside/outside the polygon the change is now automatically reflected into the Polygons layer field.