Summary
In ArcGIS Pro, line directions are used to locate points of interest and to determine directions in a map. Using the Field Calculator, the direction of the lines can be determined from the coordinates of the starting and ending positions.
This article describes the workflow to batch calculate line directions from north azimuth to quadrant bearing using the Field Calculator in ArcGIS Pro.
Procedure
- Open the project containing the line feature class in ArcGIS Pro.
- In the attribute table of the line features, add four new fields to calculate the x,y coordinates of the line's start and end position. In this example, the fields are named as 'START_X', 'START_Y', 'END_X' and 'END_Y' respectively. Set the Data Type for these fields to Double. Refer to ArcGIS Pro: Add Fields (multiple) (Data Management) for more information to add fields.
- Use the Calculate Geometry Attributes tool to calculate the x,y coordinates of the line's start and end position into the four new fields.
- For Input Features, select the line feature in the drop-down list.
- Under Geometry Attributes, from the drop-down list, select START_X for Field and Line start x-coordinate for Property.
- Select START_Y for Field and Line start y-coordinate for Property.
- Select END_X for Field and Line end x-coordinate for Property.
- Select END_Y for Field and Line end y-coordinate for Property.
- Click Run.
- Add another new field to the attribute table and specify the Field Name. In this example, 'NorthAzimu' is used. Set the Data Type to Double.
- Open the Calculate Field tool on the attribute table of the line feature to calculate the north azimuth angles. Refer to ArcGIS Pro: Access the Field Calculator for more information.
- For Input Table, ensure the line layer is selected in the drop-down list.
- Select the field created in Step 4 in the Field Name drop-down list. In this example, the field is ‘NorthAzimu’.
- For Expression Type, select Python 3 in the drop-down list.
- Specify the 'NorthAzimu' field with the following Python expression in the Expression text box, and click OK.
90-math.degrees(math.atan2(( !END_Y! - !START_Y! ),( !END_X! - !START_X! )))
- Create another new field and set the Data Type to Text. Specify a name for Field Name. In this example 'Quadrant' is used.
- Open the Calculate Field tool on the attribute table of the line feature to convert the north azimuth angle to quadrant bearing.
- For Input Table, ensure the line layer is selected in the drop-down list.
- Select the field created in Step 6 in the Field Name drop-down list. In this example, the field is ‘Quadrant’
- For Expression Type, select Python 3 in the drop-down list.
- Specify the 'Quadrant' field with the following Python expression in the Expression text box. Replace <FieldName> with the field name from Step 4.
quadrant(!<FieldName>!)
- Specify the Code Block box with the following Python expression, and click OK.
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(-1*(0+NorthAzimuth))+" W"
return quad
The image below shows the line directions in quadrant bearing.