[GIS] field calculator syntax error

arcgis-10.0field-calculator

I'm trying to calculate the direction the 'generate near table' function gives me into actual directions, N, NW etc. Azimuth would be a start too.
I tried this script in the field calculator but it doesn't run.

This was the original we tried:

if([Direction]>0,
    if([Direction]<22.5,"W",
    if([Direction]<67.5,"SW",
    if([Direction]<112.5,"S",
    if([Direction]<157.5,"SE",
    if([Direction]<180,"E",""))))),

if([Direction]>-22.5,"W",
    if([Direction]>-67.5,"NW",
    if([Direction]>-112.5,"N",
    if([Direction]>-157.5,"NE",
    if([Direction]>-180,"E",""))))))

I tried it with and without "then output=" and "Else, output =0".
I'm using ArcGIS 10, have tried with with python and vb ticked.

Best Answer

Try this. Set Parser to VBScript and tick the Show Codeblock option. Add this to the Pre-Logic Script Code field.

Dim output As String

If [Direction] > -22.5 And [Direction] < 22.5 Then
    output = "W"
ElseIf [Direction] >= 22.5 And [Direction] < 67.5 Then
    output = "SW"
ElseIf [Direction] >= 67.5 And [Direction] < 112.5 Then
    output = "S"
ElseIf [Direction] >= 112.5 And [Direction] < 157.5 Then
    output = "SE"
ElseIf [Direction] >= 157.5 And [Direction] <= 180 Then
    output = "E"
ElseIf [Direction] <= -22.5 And [Direction] > -67.5 Then
    output = "NW"
ElseIf [Direction] <= -67.5 And [Direction] > -112.5 Then
    output = "N"
ElseIf [Direction] <= -112.5 And [Direction] > -157.5 Then
    output = "NE"
ElseIf [Direction] <= -157.5 And [Direction] >= -180 Then
    output = "E"
Else ' Some error
    output = "?"
End If

Add this single line to the [fieldname] = field.

output

Note: I have not tried this in ArcMap. If it doesn't work try turning all instances of "ELSEIF" to "ELSE IF".

Related Question