2

I need the correct length of a edge between to points(yellow line in the picture below) in the unit [m] for validation of an equation. I just found the possbility to add geometry (length) to the attribute table of the tracks, but the lengths which I get by adding this column to the attribute table doesn't make sense.

enter image description here

3
  • Doesn't make sense as in ... ?
    – Erik
    Jul 2, 2019 at 13:05
  • 4
    Is your line layer in a projected coordinate system which uses meters as units? You can check this by accessing the layer's properties and looking for the CRS.
    – Joseph
    Jul 2, 2019 at 13:05
  • Its in WGS 84. Where can I check which unit is in this CRS used? Or even where can I found the unit for WGS 84 ?
    – Martina
    Jul 2, 2019 at 15:39

1 Answer 1

4

You can find out the units of a layer's CRS by looking at the Information tab in the layer properties window. The CRS WGS84 Geographic (EPSG:4326) has degrees as its unit.

enter image description here

To make length calculations in units that make sense, do the calculation in a CRS that uses the length unit you want to use. In the Field Calculator, you can do this in two ways:

Method One:

Set your project units to the units you want. Project menu > Properties > General. For example, you can see that my project is set to measure distance in miles, and area in acres.

enter image description here

In the Field Calculator, use the $length function to calculate line length using the units you just set in the project settings. Notice that the description for the $length function says:

The length calculated by this function respects both the current project's ellipsoid setting and distance unit settings.

Method Two:

In the Field Calculator, use the transform() and length() functions to calculate length in a different CRS. Substitute the EPSG code of an appropriate equidistant CRS into the following expression:

length(transform($geometry, 'EPSG:4326', 'insert target EPSG code here')

Notice that the description for the length() function says:

Calculations are always planimetric in the Spatial Reference System (SRS) of this geometry, and the units of the returned length will match the units for the SRS.

So if you use this expression in the Field Calculator, `length($geometry), it will calculate length in whatever units the layer's CRS uses.

Notes:

  • Spatial Reference System (SRS) and Coordinate Reference System (CRS) mean basically the same thing.
  • Method one is easier than method two. Use method two if you want to compare the length differences between different CRS, or if you don't want to change your project settings. Otherwise use method one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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