Attribute expressions in Context
“Expressions offer a powerful way to manipulate attribute value, geometry and variables in order to dynamically change the geometry style.”
The content or position of the label, the value for the diagram, the height of a composer item, select some features, create a virtual field.
In this module, we explore how to construct expressions to manipulate data.
Goal: To learn how to use expressions to manipulate data
- Toggle edit the roads layer and select field calculator.
- Select update existing attribute and choose column "type".
- Enter the attr_expr and click ok.
- Save your edits and inspect the changes.
- Open field calculator and add a column road_lenght. Use the lenght_calc.
- Save your edits. Compare the new length column with the length_km column. Are they different and if so give reasons?
- Create a field length_recode (integer) and reclassify the roads into the following categories.
Lenght_km <100 = 1, length_km >=100 and length < = 150 = 2 and length >150 = 3.
Hint: Use the Case statement and length_km column.
- Open the expression editor and select all 'Federal', 'Interstate' roads in 'North America'. Use usa_roads function. NB: Rewrite the above expression in your own ways to achieve the same results.
Expressions are extensively used in QGIS. They can be used to alter existing data and producing new output and selecting a subset of the data. QGIS provides users with the ability to write custom expressions. Expressions are grouped into categories and the geometry functions are a special type which allows a user to manipulate the geometry of a feature and return new outputs.
What is the best way to describe geometry functions:
A group of functions which help to find the area of point features
Functions which only work when shapefile are used
Group of functions which are intended to exclusively operate on the geometry of layers
Which of the following can not be achieved using an expression:
Finding the current date and time
Evaluating the length of a column containing strings
Do an intersection between two layers using the geometry functions
Can a user update selected records: