# 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[0]
firstRun = False
else:
if oldValue < row[0]:
row[1] = row[1]
else:
row[1] = (-1)*row[1]
oldValue = row[0]
cursor.updateRow(row)
del row
del cursor
``````

You don't need to be updating `row[1]` 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[0]
firstRun = False
else:
#We don't need to check less than since we aren't negating it.
if oldValue > row[0]:
row[1] *= -1
cursor.updateRow(row)
oldValue = row[0]
``````

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. Commented Jul 13, 2015 at 19:17
• @SilvanD, you're essentially checking to see if the current feature value is greater than the previous one, correct?
– Paul
Commented Jul 13, 2015 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. Commented Jul 13, 2015 at 19:41
• @SilvanD, please update your post to include a picture of the sample data.
– Paul
Commented Jul 13, 2015 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). Commented Jul 13, 2015 at 20:03