0

I have a polygon layer with every cities in my region. One of the field of this layer is the population of the city.

I also have a line layer which represents some bus route

I would like to automaticaly calculate the population concerned by the bus route (which means the sum of population of the polygon intersect by each bus line).

First of all how to calculate this in a new field on the line layer?

Second how to get this result to be update if the route change?

enter image description here

1 Answer 1

6

First of all how to calculate this in a new field on the line layer?

Install the RefFunctions plugin.

Use the Field Calculator to add a field to the bus route layer with this expression (substitute your actual field and layer names):

 intersecting_geom_sum('city_polygons','population')

enter image description here

Second how to get this result to be update if the route change?

Make it a virtual field if you only need the values in the current project.

If you need the values saved as a permanent part of the layer's attributes, make it a regular field with a default field value. Check the box for "Apply default value on update." Note that the field won't update if the layer isn't in edit mode; you may also need to make some sort of change to trigger the update.

enter image description here

2
  • Excellent and nicely explained method. Can I abuse and ask you the expression for the intersection of mylines and some flow arrow between cities? Of should i make it another question for more context?
    – Arthur
    Jan 21, 2019 at 9:45
  • Here the new question for better comprehension gis.stackexchange.com/q/309344/20802
    – Arthur
    Jan 21, 2019 at 10:18

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