yooperjb

Total Elevation Gain confusion

Discussion created by yooperjb on May 30, 2012
Latest reply on May 31, 2012 by yooperjb
Greetings,

I'm having some confusion with results calculating total elevation gain/accumulation from a polylineZ file. Here's the situation, I received a gps track from a friend of a local bicycle training route. According to his gps track the total elevation gain was about 6,200'. I digitized a track based on the roads the gps track followed, and interpolated it to a 3d shape using 3d analyst and a 10m DEM. I wrote a python script to calculate the total elevation gain using the z values of this new polylineZ. The confusion is that my calculation from they python script is giving me approx 11,460', which is almost double what his gps track said. To test it more, I exported the feature to ascii, brought it into excel and wrote a VBA code which gave me the same exact calculation as the python script.

So, I decided to try something else. I then exported the file to a kml layer, and brought it into GPS visualizer (gpsvisualizer.com), and then looked at the total gain (vertical up) on EveryTrail.com. Their calculation for the KML file was really close to what his initial gps track stated, around 6,300'.

Perhaps something is wrong with my logic in calculating the total elevation gain:

Get z value, if it is larger than previous z value then add the difference to a total gain variable. Do until all z values have been cycled through.

Here is the code:
import arcpy

# Get the input feature class
infc = arcpy.GetParameterAsText(0)

# Name the output location where Total Accumulation result will go
opfl = arcpy.GetParameterAsText(1)

# Name of the file written to the above file location
filename = arcpy.GetParameterAsText(2)
outputfile = open(opfl + "/" + filename +".txt", "a")

# Identify the geometry field
#
desc = arcpy.Describe(infc)
shapefieldname = desc.ShapeFieldName

# Create search cursor
#
rows = arcpy.SearchCursor(infc)

# Enter for loop for each feature/row
#
for row in rows:
    # Create the geometry object
    # in this case Polyline Object
    feat = row.getValue(shapefieldname)

    # Print the current multipoint's ID
    #
    print "Feature %i:" % row.getValue(desc.OIDFieldName)
    partnum = 0

    # Step through each part of the feature
    #
    for part in feat:
        # Print the part number
        #
        print "Part %i:" % partnum

        # Step through each vertex in the feature
        prev_z = 10000
        tot_accum = 0
        for pnt in feat.getPart(partnum):
           
            if pnt.Z > prev_z:
                tot_accum = ((pnt.Z - prev_z) + tot_accum)
                prev_z = pnt.Z
            else:
                tot_accum = tot_accum
                prev_z = pnt.Z
        partnum += 1   

    print "Total Accumulation = %i:" % tot_accum

# Write the Total Accumulation to file and close file
outputfile.write("File Name: " + desc.Name + "\n")
outputfile.write("Total Accumulation = " + repr(tot_accum) + "\n \n")
outputfile.close()

# Add messages to tool output window
arcpy.AddMessage("Total accumulation tool is complete")
arcpy.AddMessage("File Name: " + desc.Name)
arcpy.AddMessage("Total Accumulation = " + repr(tot_accum)


Thanks for any help!

Outcomes