Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm wondering if anyone has any insight into the potential to auto-calculate the value of a field, either area or distance (ideally) or a formula (based on the values of say 2 other fields, or an existing field and another value).

Perhaps this is a plugin that presents a dialogue asking to what layer you want the auto-calculation to apply, and what formula or combination of fields you would like included in the calculation.

These tools are of great use to planners who are using a GIS as a drawing/design tool.

Thoughts?

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Automatically calculating fields have been discussed on the QGIS mailing list a few months back. They are definitely on the wish list. I don't think anyone is currently working on this feature though.

For now, you can use database views to achieve something similar, as Devdatta suggested. Spatialite or PostGIS will do just fine.

share|improve this answer

Here is an extended solution for the problem of automagically labelling a polygon with the area as it is created. In the labelling dialog, use the Expression Based Labelling Engine (credit to Nathan) to implement this line

"Field ID" || '\n' || toint( $area / 10000) || ' ha'

The layer has a UTM (metres) CRS and so calculates the hectares on the fly. There is a concatenation to add in

\n

which is a line break to make the label appear on two lines, also another to add the text of ha. Field ID is the name or label for the polygon.

You can simplify the expression to calculate distance and display that. However it only displays once the feature has been completed, not whilst it is still being created which I think is the OP's interest. For me it is not much trouble to trial and error the editing of the feature to get the desired length.

(I'll have to admit I don't know any more than this, Otto showed me how to do it....)

This is for Lisboa 1.8, it will be different in trunk or older versions.

also

Where are the Expression-based Labeling options in QGIS?

share|improve this answer
    
I very much like this "workaround". Postgres\Postgis solution by using triggers is more definitive, but it will only update values after edits been saved. For some cases the conjunction of both method might be the best approach. –  Alexandre Neto Mar 25 '13 at 12:11

You could have your data in a PostGIS database, and then create a View containing the data from your table, along with a virtual auto-populated field.

Another option is to have triggers on the table, which inserts this field on inserts.

share|improve this answer
    
This triggers option sounds promising, as this would allow for other functions besides simply calculating area to be executed... Any idea as to how to create/execute a trigger? –  mapBaker Jan 29 '13 at 18:58
    
@mapBaker This article goes into the details of triggers: postgresql.org/docs/9.2/static/plpgsql-trigger.html –  Devdatta Tengshe Jan 30 '13 at 3:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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