Select to view content in your preferred language

code python for azimuth and quadrant

2428
13
06-07-2023 12:38 PM
Labels (3)
New Contributor

I am using the following script in ArcGIS 10.3 to calculate Quadrant (in the format angle/NE/SE/SW/NW) from azimuth.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

if ((NorthAzimuth>=0) & (NorthAzimuth<90)):

elif ((NorthAzimuth>=90) & (NorthAzimuth<180)):

elif ((NorthAzimuth>=180) & (NorthAzimuth<270)):

else:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

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.

13 Replies
MVP Esteemed Contributor

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

... sort of retired...
MVP Esteemed Contributor

You should also see this thread and solution

Solved: Python script/expression for field calculator for ... - Esri Community

... sort of retired...
New Contributor

Sorry, I still didn't get the expected results

MVP Esteemed Contributor

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

... sort of retired...
New Contributor

Hello DanPatterson

Fields: NorthAzimu (Double), Quadrant (Text), Start_X (Double), Start_Y (Double), End_X (Double), End_Y (Double)

Box Pre -logic script code:

if ((NorthAzimu>=0) & (NorthAzimu<90)):
elif ((NorthAzimu>=90) & (NorthAzimu<180)):
elif ((NorthAzimu>=180) & (NorthAzimu<270)):
else: quad = 'N '+str(360-NorthAzimu)+' W'

Thank You

MVP Esteemed Contributor

``````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'

is how it should be formatted

... sort of retired...
New Contributor

Hello Dan

Sorry my insistence but I still get error with tthe scipt. The code was copied exactly was sent in the window "quadrant = " .  The box Show Codeblock was not checked. If the box is checked  I also get error.

Thank You

MVP Esteemed Contributor

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

... sort of retired...
New Contributor

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

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

if (NorthAzimu = 0):
elif (NorthAzimu = 90):
elif (NorthAzimu = 180):
elif (NorthAzimu = 270):