Thursday, 13 August 2015

Automatic calculation field based on line modification within QGIS



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



Answer





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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...