Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using QGIS.

I would like to know if there is any way during the editing phase of a vector (line or polygon) to know the length of the line (total and partial) that is being created?

share|improve this question
I think this link can answer all your questions: – user2086860 Jul 15 '14 at 15:15
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Evil Genius Jul 15 '14 at 15:44

There is one option available in the Attribute toolbar (named measure line). I hope with that you can get what you want.

QGIS menu screen shot

share|improve this answer
Not really an option for a complex polyline – Damien Feb 7 '13 at 23:17

I don't know of any built-in tools that track the length of lines as you are editing.

Assuming you are already Editing a layer, one work-around would be (in qGIS 2.0.x):

  1. Open the Layer's Attribute Table.
  2. Open the Field Calculator (Ctrl-I)
  3. Create a new field, name it something like "Length", set the type to decimal width 18, precision 10, or whatever level works for you.
  4. In the Function List, Click on Geometry, and double-click on $length to add it to the Expression box.
  5. Click OK and qGIS will calculate the current line length for all features. (Or only selected features, if you check that box).

This will give you the length of the line as it is in your current edit session.
Warning: The value of the field will not update live. So, if you undo your edits, or make additional edits, the Length value will be wrong.

If you keep the attribute table window open while editing, you can recalculate the column whenever you want.

You could also just run code in the python console to recalculate the attribute values whenever you want to update them. I was hoping to find some python code for qGIS to do this faster than the Attribute Table window UI, but couldn't find any. So I dug a bit and figured out one way to do it.

A script I came up with using this tutorial and the Developer Cookbook is below. I assumes that you are currently in an Editing session with the polyline layer you are editing (and want the lengths for) selected. No features are selected.

aLayer = qgis.utils.iface.activeLayer()
idx = aLayer.fieldNameIndex('Length')
caps = aLayer.dataProvider().capabilities()
features = aLayer.getFeatures()
for feature in features:
    if caps & QgsVectorDataProvider.ChangeAttributeValues:
        fid =
        flen = feature.geometry().length()
        aLayer.changeAttributeValue(fid, idx, flen)


In QGIS 2.6+ when creating a new field, you can now check the option "create virtual field". When you do this, QGIS will automatically update the field based on the expression. In this case, updating the calculated length. You can keep the attribute table open while editing and see the updates instantly.

share|improve this answer

You can determine the length of a line/segment with the Improved Polygon Capturing plugin.

share|improve this answer

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

unfortunately does not help me. my need is to know how long the line I am creating, but not to create a line of length defined by me first – user4756 Nov 8 '11 at 19:38

Your Answer


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.