I am wondering how I can get the distance between consecutive GPS locations in ArcMap 10 (i.e. the distance between consecutive GPS locations sent in during a wildlife telemetry study).

  • What unit does that python script generate the distance in? – Molly Levy Sep 21 '16 at 17:31
  • This is not an answer - please don't use an answer to ask questions or make comments – Midavalo Sep 21 '16 at 18:03
  • My apologies, I wasn't able to comment above as my account is new and I didn't have the "50 reputation" necessary to comment. That being said, I am still very interested in what unit the distances are being generated in. – Molly Levy Sep 21 '16 at 18:18
  • This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review – rcs Sep 21 '16 at 18:41

Assuming that your points are in order, and that this works at 10.0 (I'm using 10.2):

Field Calculator Expression:

dist( !Shape! )

Field Calculator Code Block:

count = 0
def dist(shape):
    global prev
    global count
    point = arcpy.PointGeometry(shape.getPart(0))
    if count > 0:
        distance = point.distanceTo(prev)
        distance = 0
    prev = point
    count = count+1
    return distance

Parser: Python

enter image description here

  • Thanks for your help! This is to go in the field calculator? – user37544 Oct 16 '14 at 23:27
  • Yes, make sure to switch to Python parser. – phloem Oct 16 '14 at 23:30
  • It works! Perfect thank you so much I really appreciate it! – user37544 Oct 16 '14 at 23:52
  • thanks for the answer this is great. What if I want to check a condition when calculating the value, such that the value of the current record in one field is different than the value of the previous record's field? Can I do this in the field calculator or do I need to use a cursor? If the values are the same I want to do the calculation, if they are different, return 0. – kflaw Aug 2 '15 at 16:41
  • Sure, you would add the field to the expression (e.g. dist(!Shape!, !myField!)), create a new variable in the function definition (e.g. def dist(shape, myfield)), and then reference the new variable in an 'if' statement. – phloem Aug 4 '15 at 18:35

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.