2

We have a river network which doesn’t correspond to the reality shown by the orthoimage. Each river has the same route number (see attribute table). Every route number has several segments (see attribute table). We know the mileage point of each segment (start and end; see attribute table “vonkm” and “zukm”). Mileage 0 is always at the river section.

We will manually adjust the geometry of the river network. As you can see on the image the length of each segment will probably change due to the adjustment of the geometry. Is there a way to automatically calculate the mileage of each segment?

enter image description here

  • Do u mean calculate the mileage or each segment AND put the information in the attribute table (in a new column) ? – snaileater May 3 '18 at 11:41
  • Basically I want to update the two attributs "vonkm" and "zukm" with the new mileage which I will gain due to the geometry adjustments. – AICH May 3 '18 at 15:31
  • Well in that case I gave you way more detail than you needed in my answer. Method three will do what you need. – csk May 3 '18 at 15:56
  • Thank you very much. Unfortunately, this is only enables me to calculate the length of each line segment. What I need is to know the starting and endpoint of each segment. So if you look at the attribute table; there are 8 features that belong to the same route number (last field). In this example the 1st segment starts at km0.381 and ends at km0.566, the 2nd segment starts at km 0.566 and ends at km 0.711 and so on (this means the 1st segment is 185m long; the 2nd 145m). – AICH May 4 '18 at 11:18
  • When I change the geometry the 1st is maybe only 170m long. That means it would start at km0.381 but already ends at km0.551. I can easily adjust this manually but would prefere an automatic solution because I have a lot of data. – AICH May 4 '18 at 11:18
1

Four ways to find the length of a line in QGIS

Method One: Identify tool

Click on segment using Identify tool. Open the "Derived" section in the Identify results window. enter image description here Tips:

  • Select the button "Expand New Results by Default" (circled in red) -- now the "Derived" section is open by default every time you identify a feature.
  • Drag and drop the Identify window on top of an open panel (such as the Layers panel) to dock it.
  • Right clicking on any attribute in the Identify window (including derived attributes) gives you the option to copy the attribute value. This is useful if you need to enter the length in another program or document.
  • Change the units used in the Identify tool under

    Project menu > Project properties > General > Measurements

Pros: This method is quick and easy. It always displays the current length value.

Cons: You can only see the length of one segment at a time. The lengths aren't saved in the attribute table.


Method Two: Virtual Field

Use the Field calculator to add a virtual field to the layer, with the formula:

$length

Length is calculated in the units of the layer. It's a good idea to include the units in the field title, so anyone using the table will know the units.

enter image description here

Pros: This always displays the current length value. You can see the lengths of all the segments in one place.

Cons: A virtual field is saved in the project, not in the layer. So if you open the same layer in a different project, the length field won't be there. In QGIS 3.0, virtual fields are buggy, and can cause error messages and occasional crashes.


Method Three: Static Field

Use the Field Calculator to add or modify a regular field. Exactly the same method as option two, except un-check the "Create virtual field" box.

Pros: You can see the lengths of all the segments in one place. The length values are permanently saved to the layer file. Won't cause error messages or crash the program if using QGIS 3.0.

Cons: This field is calculated once, and not updated automatically.


Method Four: Labels

Label the line layer using the $length function. Optional: concatenate units to label

$length || ' meters'

Use round() function to limit number of decimal places displayed:

round($length, 2) || ' meters'

enter image description here

Pros: Easy to see segment length at a glance. Can see the lengths of multiple segments at once.

Cons: Length isn't saved in a table anywhere. Can't copy the length value to another document.


Note: all methods are described in QGIS 3.0, but should be similar in earlier versions.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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