4

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?

1
  • Possibly, but you may have to write some python code that reacts to an event.
    – Spacedman
    Commented Mar 1, 2018 at 16:56

2 Answers 2

3
  1. In the vector layer properties, under the field tab, open the field calculator.
  2. Set it as new and virtual field.
  3. Name it as you wish.
  4. 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.

3
  • 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 Taglia
    Commented 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 Taglia
    Commented Mar 5, 2018 at 13:31
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.