HOW TO

Determine the cardinal compass direction of line features

Last Published: April 25, 2020

Summary

The following instructions describe how to determine the cardinal compass direction of line features. In this article, the below feature class of a downtown city is used.

User-added image

Procedure

  1. Use the Linear Directional Mean tool output to obtain the compass angle of the line features.
    1. In the Catalog window, navigate to System Toolboxes > Spatial Statistics Tools > Measuring Geographic Distributions > Linear Directional Mean. Open the tool.
    2. Select the line feature as the input feature class.
    3. Select a field from the attribute table as the case field.
      Note:
      The Case Field is used to group features for separate linear directional mean computations. When a Case Field is specified, the input line features are first grouped according to case field values, then an output line feature is created for each group. The case field can be of integer, date, or string type. Records with NULL values for the Case Field are excluded from analysis.
    4. Click OK.
    Linear Directional Mean Compass angle values
  2. Convert the compass angle value to a direction.
    1. Add a new Text field to the attribute table.

      Add a new field
    2. Use the Field Calculator to create a Python function to convert the angle values to text direction.
      1. Start an edit session on the feature layer.
      2. Right-click the field header > Field Calculator.
      3. In the Field Calculator, select Python as the parser.
      4. Check the Show Codeblock checkbox.
      5. Type the following script in the Pre-Logic Script Code text box.
        def direction(var):
           if var < 22.5:
              return "North"
           if var >= 22.5 and var < 67.5:
              return "Northeast"
           if var >= 67.5 and var < 112.5:
              return "East"
           if var >= 112.5 and var < 157.5:
              return "Southeast"
           if var >= 157.5 and var < 202.5:
              return "South"
           if var >= 202.5 and var < 247.5:
              return "Southwest"
           if var >= 247.5 and var < 292.5:
              return "West"
           if var >= 292.5 and var < 337.5:
              return "Northwest"
           if var >= 337.5:
              return "North"
      6. Type the following expression in the Direction = text box.
        direction(!CompassA!)
        Field Calculator
      7. Click OK. The direction of the line features are displayed in the attribute table. Note the difference in cardinal direction for the northwest-most line feature in the downtown city image, labeled as "Northeast" and shown in blue.

        Direction of line features is displayed.

        User-added image

Article ID: 000014483

Software:
  • ArcMap

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options