Compute coordinates of vector line?

I have a set of vector lines (which represent translation vectors for georeferencing). Based on the layer CRS, how can I compute the coordinates of each line in an attribute table ?

i.e (Xmax-Xmin; Ymax-Ymin) for each line.

I have managed to get the line length with \$length in the expression editor but I am struggling with other geometrical parameters.

Edit: I am looking to "store the formula" within the layer. The idea is to keep these values automatically updated with the geometry. (Auto)update should happen if a new line is added or modification of the current geometry is done.

• About your recent edition, look at virtual fields (stores the formula but not within the layer). About the `\$length()` function, it calculates the ellipsoidal length, use `length( \$geometry)` instead if you want the planimetric one (probably not so). About the `(Xmax-Xmin; Ymax-Ymin)` example, it is assumed to be a string of characters because a pair of values can not be attributed to a single numeric field. Commented Feb 11, 2019 at 1:45

You can use the Field Calculator. Open the attribute table of your line layer and select the Open Filed Calculator icon from the toolbar. I use an OSM road layer.

In the Field Calculator window create a new column of decimal type, in the Geometry group of functions you can find x_min, x_max, y_min, y_max functions. To create a column with x_range of features use the next screenshot:

You can create a column for y_range in a similar way.

• Thanks: that is the method I was after but I was missing \$geometry to call the proper entity.
– kFly
Commented Feb 10, 2019 at 20:18
• Is there a method to automatically compute these parameters for each line created within this layer as soon as they are created ?
– kFly
Commented Feb 11, 2019 at 0:23
• or update automatically when the geometry is modified ?
– kFly
Commented Feb 11, 2019 at 0:35
• See this post gis.stackexchange.com/questions/178355/… or user virtual fields (virtual fields are calculated when you open the attribute table) which is technically simpler but slower. Commented Feb 11, 2019 at 14:15

For QGIS 3.x, the formula in the field calculator is :

``````'(' || x_max(\$geometry) || '-' || x_min(\$geometry) || '; ' || y_max(\$geometry) || '-' || y_min(\$geometry) || ')'
``````

Following J.Monticolo's answer, yet another expression is:

``````'(' || bounds_width(\$geometry) || '; ' || bounds_height(\$geometry) ||')'
``````
• kFly didn't say if (s)he want (Xmax-Xmin) as text or the result of subtraction (q.e.d. width or height). In case of text result, my solution is the good one, in the case of substraction, it's the Kazuhito's one. Commented Feb 10, 2019 at 19:26
• I want actually the numerical value, but thanks for underlining up this difference
– kFly
Commented Feb 10, 2019 at 20:08