3

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?

  • Possibly, but you may have to write some python code that reacts to an event. – Spacedman Mar 1 '18 at 16:56
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.

  • 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 Mar 2 '18 at 13:59
  • Sorry, I misread your question. Will adapt the answer – Denis Rouzaud Mar 2 '18 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 Mar 5 '18 at 13:31
1

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, privacy policy and cookie policy

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