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)
Is there a particular reason you set the prev_z value to 10000 instead of the z value of the first geometry part?
That works well enough I would say. I just wanted to make sure it was high enough that it wouldn't be throwing a wrench in things on the first iteration. I assume since you keep overwriting your tot_accum under your cursor that there is only one feature in the feature class you are running this script on? I can't find any errors in your logic really. If you post the track you are processing it on that might help track down the issue.
Your tool is calculating the Z values correctly. There may have been a problem with the DEM you used to create the Zpolyline or with the DEM the reference systems you are using calculate on. The only other thing I can imagine being wrong is some meter/feet conversion problem, but I can't find any evidence of that.
This tool calculates it the exact same.
http://resources.arcgis.com/gallery/file/Geoprocessing-Model-and-Script-Tool-Gallery/details?entryID...