I am using the following script in ArcGIS 10.3 to calculate Quadrant (in the format angle/NE/SE/SW/NW) from azimuth.
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def quadrant(NorthAzimuth):
if ((NorthAzimuth>=0) & (NorthAzimuth<90)):
quad = 'N '+str(NorthAzimuth)+' E'
elif ((NorthAzimuth>=90) & (NorthAzimuth<180)):
quad = 'S '+str(180-NorthAzimuth)+' E'
elif ((NorthAzimuth>=180) & (NorthAzimuth<270)):
quad = 'S '+str(NorthAzimuth-180)+' W'
else:
quad = 'N '+str(360-NorthAzimuth)+' W'
return quad
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The box Show Codeblock is cheked. This script is copied in the box Pre-logic Script Code. In the box below - "Quadrant = " is typed quadrant (!NorthAzimuth!).
My polyline shape file contains the followings fields: Start_X (double), Start_Y (double), End_X (double), End_Y (Double), Compriment (double) - polyline lenght, and NorthAzimu (double) - azimuth in degrees.
I already replace the term NorthAzimuth of script with NorthAzimu, but without sucess.
The script always returns an error message.
Please, where is the error?
format the code would be useful
Code formatting ... the Community Version - Esri Community
as would the error message and a screengrab of the calculate field dialog
You should also see this thread and solution
Solved: Python script/expression for field calculator for ... - Esri Community
your code still isn't formatted properly in window1.jpg. Why not copy and format the code you are using here, using Wednesday's link.
A screen grab of it won't solve code formatting issues
Hello DanPatterson
Fields: NorthAzimu (Double), Quadrant (Text), Start_X (Double), Start_Y (Double), End_X (Double), End_Y (Double)
Box Pre -logic script code:
def quadrant(NorthAzimu):
if ((NorthAzimu>=0) & (NorthAzimu<90)):
quad = 'N '+str(NorthAzimu)+' E'
elif ((NorthAzimu>=90) & (NorthAzimu<180)):
quad = 'S '+str(180-NorthAzimu)+' E'
elif ((NorthAzimu>=180) & (NorthAzimu<270)):
quad = 'S '+str(NorthAzimu-180)+' W'
else: quad = 'N '+str(360-NorthAzimu)+' W'
return quad
Box Quadrant =
quadrant (!NorthAzimuth!)
Thank You
def quadrant(NorthAzimu):
if ((NorthAzimu >= 0) & (NorthAzimu < 90)):
quad = 'N ' + str(NorthAzimu) + ' E'
elif ((NorthAzimu >= 90) & (NorthAzimu < 180)):
quad = 'S ' + str(180 - NorthAzimu) + ' E'
elif ((NorthAzimu >= 180) & (NorthAzimu < 270)):
quad = 'S ' + str(NorthAzimu - 180) + ' W'
else:
quad = 'N ' +s tr(360 - NorthAzimu) + ' W'
return quad
is how it should be formatted
show code block
paste my copy of the code and check to see if it is ok
Quadrant (Text) is the field name, you currently are using a lower case
quadrant =
Hello Dan
thank you for the code, it worked correctly. But I made a small change to include Azimuth =0 or Azimuth=90 or Azimuth=180 or Azimuth=270 or Amimuth = 360. In this case, should I include 'str' in the line Quad= 'N'?
Thank You for help
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
def Quadrant(NorthAzimu):
if (NorthAzimu = 0):
Quad = 'N'
elif (NorthAzimu = 90):
Quad = 'E'
elif (NorthAzimu = 180):
Quad = 'S'
elif (NorthAzimu = 270):
Quad = 'W'
elif (NorthAzimu = 360):
Quad = 'N'
elif ((NorthAzimu > 0) & (NorthAzimu < 90)):
Quad = str(NorthAzimu) + 'NE'
elif ((NorthAzimu > 90) & (NorthAzimu < 180)):
Quad = str(180 - NorthAzimu) + 'SE'
elif ((NorthAzimu > 180) & (NorthAzimu < 270)):
Quad = str(NorthAzimu - 180) + ' SW'
else:
Quad = str(360 - NorthAzimu) + ' NW'
return Quad