# Getting angle of point generated from DEM in Raster using Field Calculator in ArcGIS Desktop?

I am trying to calculate the angle of some specific points generated from flow direction in ArcMap 10.2. I converted the DEM to flow direction and then to points. I am trying to convert the grid_code of the generated points into specific angles with a certain condition. I tried using the below Python code in the Field Calculator but it gives an error as shown in the image attached.

Can someone explain how to do this right? ``````    ##########################
def Reclass ([grid_code]):
if ([grid_code] == 64):
return 0
elif ([grid_code] == 128) :
return 45
elif ([grid_code] == 1) :
return 90
elif ([grid_code] == 2) :
return 135
elif ([grid_code] == 4) :
return 180
elif ([grid_code] == 8) :
return 225
elif ([grid_code] == 16) :
return 270
elif ([grid_code] == 32) :
return 315
Reclass(![grid_code]!)
###########################
``````

Here is how the attribute table looks like

• what details did the geoprocessing window give you? – Paul H Mar 22 '19 at 17:34
• Please be sure to place the error message in the question as text. This makes the error legible on all devices and searchable by others with the same issue. – Vince Mar 22 '19 at 18:16

I know ArcGIS's python interpreter is weird, but I'm pretty sure your syntax is wrong. My recollection is that you don't need to use their weird escape characters within the scope of the function definition.

``````def reclass(grid_value):
if (grid_value == 64):
return 0
elif (grid_value == 128):
return 45
elif (grid_value == 1):
return 90
elif (grid_value == 2):
return 135
elif (grid_value == 4):
return 180
elif (grid_value == 8):
return 225
elif (grid_value == 16):
return 270
elif (grid_value == 32)
return 315
``````

However, I think you should save yourself some typing and use a dictionary instead of all of those `if/elif` statements:

``````def reclass(grid_value):
lookup = {
64: 0,
128: 45,
1: 90,
2: 135,
4: 180,
8: 225,
16: 270,
32: 315,
}
return lookup.get(grid_value, None)
``````

Then you'd call this function as you did (maybe -- I don't quite recall which escape characters are needed)

``````reclass(!grid_code!)
``````

As an aside, if you were going to do this in geopandas, you would do the following:

``````lookup = {
64: 0,
128: 45,
1: 90,
2: 135,
4: 180,
8: 225,
16: 270,
32: 315,
}

(
• `reclass(!grid_code!)`. Also, your indentation is correct and could've been a problem for the OP. – Andy Mar 22 '19 at 18:05