Calculating slope for points with downhill slopes rendered as negatives in ArcGIS

I have a DEM and a series of points. I'd like to measure the change in slope along the series of points. Distinguishing between uphill and downhill slopes matter to me, and ArcGIS' slope function renders all slopes as absolute values.

I'm working with ArcGIS' Spatial Analyst and 3D Analyst toolkits.

This is what I've done so far.

1. Created points
2. Run the "interpolate shape" tool
3. Run the "slope" tool
4. Run the "extract multi values to points" tool to add two fields Elevation and Slope to the points feature class.

I have followed the advice here (http://blogs.esri.com/esri/supportcenter/2012/03/09/calculating-the-slope-of-a-hiking-trail/) to change the downhill slope values into negatives, but have not succeeded. When I run the code (below), nothing happens.

fc = r"C:\Points\Test.gdb\Points_3d"
cursor = arcpy.da.UpdateCursor (fc, ["Elevation","Slope"])

firstRun = True

for row in cursor:
if firstRun:
oldValue = row
firstRun = False
else:
if oldValue < row:
row = row
else:
row = (-1)*row
oldValue = row
cursor.updateRow(row)
del row
del cursor You don't need to be updating row for every feature, so cursor.updateRow(row) should be under the final else statement. Also, I'd suggest using with statements as closing is better supported:

fc = r"C:\Points\Test.gdb\Points_3d"
with arcpy.da.UpdateCursor (fc, ["Elevation","Slope"]) as cursor:
firstRun = True

for row in cursor:
if firstRun:
oldValue = row
firstRun = False
else:
#We don't need to check less than since we aren't negating it.
if oldValue > row:
row *= -1
cursor.updateRow(row)
oldValue = row

I checked similar code on a sample dataset (see below) and it correctly negated the features based on the if statement. If this still isn't working, I'd check to see if your if statement ever evaluates to True. • Thanks for your help, but hmmm -- that's still not working. Any ideas of how I might approach this problem a totally different way? I've scoured the archives of SE, but can't seem to find a good solution. – SilvanD Jul 13 '15 at 19:17
• @SilvanD, you're essentially checking to see if the current feature value is greater than the previous one, correct? – Paul Jul 13 '15 at 19:21
• Precisely. To distinguish a 30 degree uphill slope from a 30 degree downhill slope, let's say. Very simple, but I'm a neophyte python coder, so I'm not managing to understand why that code isn't working for me. – SilvanD Jul 13 '15 at 19:41
• @SilvanD, please update your post to include a picture of the sample data. – Paul Jul 13 '15 at 19:45
• just updated my post with a picture of the sample data. The slope column remains the same after running your code (i.e. no negative signs where they should be). – SilvanD Jul 13 '15 at 20:03