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?
2 Answers
- 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.
-
Following the steps you suggest what I get in the field is the number of vertices of each polygon, while what I need is the number of points (from another Points layer, called "Houses") that fall inside each polygon (Village).– M TagliaCommented Mar 2, 2018 at 13:59
-
Sorry, I misread your question. Will adapt the answer Commented Mar 2, 2018 at 14:01
-
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. Thank you for your help!– M TagliaCommented Mar 5, 2018 at 13:31
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.