0

I have selected some polylines on my map. Now I would like to know the total lengh of those. I've found great explanation about "calculate geometry" tool. Which do exactly that BUT modifying your table (adding or updating a field). I would like only to see the result not to store it somewhere.

Is this possible?

3
  • 3
    Do you have an existing field with length stored in it, like Shape_Length or similar? If so, you can open the attribute table and right-click that column select 'Statistics' and it will generate stats for the field, including sum of length for all selected features.
    – bixb0012
    Sep 23 at 15:26
  • For most database storage types (file geodatabase, enterprise geodatabase) the length of features is automatically included as as extra field already ('Shape_Length'). So the "calculate geometry" is unnecessary for these data stores. If you are using Shapefiles, then you would need to manually add a field and run "calculate geometry" on that field, OR use the "add geometry attributes" field (which does a similar thing). What type of data store are these features in? Do they already have such an attribute? 2 days ago
  • I do not have a field of that type, and this database is shared between multiple users. Therefore I can't add a specific new row. I would like only to see the result once, not permanently store it.
    – Arthur
    yesterday

1 Answer 1

1

You can run this snippet of Python in the Python window. Just update the lines to point at your actual layer in the Contents page. Note the code /1000, assuming your distances are in Meters and you want KMs. You may need to update this to more accurately reflect your data.

with arcpy.da.SearchCursor("lines", ["SHAPE@LENGTH"]) as c:
    total = 0
    for r in c:
        seg = r[0] /1000
        print("distance: {:0.2f}".format(seg))
        total += seg
    print("Total distance: {:0.2f}".format(total))
2
  • This is the perfect answer. Thank you. Just for the other, no special character for the alias of your layer otherwise you will get an error.
    – Arthur
    21 hours ago
  • @Arthur, if you are only interested in the total and not printing out the segment values, the code can be collapsed to a single line after defining the cursor by using Python's built-in Sum function: print(f"Total distance: {sum(len for len, in c)/1000:0.2f}")
    – bixb0012
    13 hours ago

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.