HOW TO

Create polygons to visualize the survey area of an observation with Python

Last Published: October 13, 2022

Summary

Point features represent specific coordinates when added to a map. These coordinates can also represent the exact location of a vantage point, such as watch towers or lighthouses. Polygons can be created from the direction of the point feature to visualize the angle of the survey area on the map.

This article describes the workflow on how to create polygon features representing the survey area of an observation using Python.

Procedure

  1. In ArcGIS Pro, add the table into the Contents pane.
  2. Right-click the table and select Display XY Data.
Display the XY data of the desired table
  1. In the Display XY Data window, for Input Table, select the table. For this workflow, the 'Observations' table as shown in the sample below is used.
Note:
The table used must contain the following five data: longitude, latitude, left bearing, right bearing, and distance.
Sample table used to generate X Y points on the map
  1. Select the fields with longitude and latitude values for both X Field and Y Field.
  2. Specify the appropriate Coordinate System. In this example, ETRS_1989_UTM_Zone_32N is used. Click OK.
Select the parameters for Display XY Data
  1. Navigate to the top ribbon, click Analysis > Python.
  2. Click the drop-down and click Python Window to show the Python window.
Open the Python window
  1. In the Python window, enter the following scripts.
    1. Define the functions to create the polygon features representing the viewing area.
def circle_section(x, y, start, end, radius, wkid):
    """Creates a circle section.
        x, y: float, coordinates of the center
        start, end: int, start and end of the section in degrees, Nort=0°, East=90°
        radius: float, radius of the section
        wkid: int, well-known id of the coordinate system

        returns an arcpy.Polygon in the chosen coordinate system
    """
    start = int(start)
    end = int(end)
    center = arcpy.Point(x, y)
    center_geo = arcpy.PointGeometry(center, wkid)
    angles = range(start, end, 1)
    if start > end:
        angles = list(range(start, 360, 1)) + list(range(0, end, 1))
    arc_geos = [center_geo.pointFromAngleAndDistance(angle, radius, "PLANAR") for angle in angles]
    points = [center] +  [ag.firstPoint for ag in arc_geos] + [center]
    return arcpy.Polygon(arcpy.Array(points), spatial_reference=wkid)


def create_view_sheds(in_table, out_features, x_field, y_field, bearing_left_field, bearing_right_field, distance_field, wkid):
    """Creates a polygon feature class with circle sections.

    in_table: str, path to the input table or name of the table in the active map
    out_features: str, path to the output feature class
    *_field: str, names of the fields in the input table
    wkid: int, well-known id of the coordinate system
    """
    # create output feature class
    from pathlib import Path
    folder = str(Path(out_features).parent)
    name = str(Path(out_features).name)
    arcpy.management.CreateFeatureclass(folder, name, "POLYGON", spatial_reference=wkid)
    arcpy.management.AddField(out_features, "FID", "LONG")

    with arcpy.da.InsertCursor(out_features, ["SHAPE@", "FID"]) as i_cursor:
        with arcpy.da.SearchCursor(in_table, ["OID@", x_field, y_field, bearing_left_field, bearing_right_field, distance_field]) as s_cursor:
            # for each table row
            for oid, x, y, bearing_left, bearing_right, distance in s_cursor:
                # create a circle section 
                poly = circle_section(x, y, bearing_left, bearing_right, distance, wkid)
                # write the polygon and the table row's objectid into the feature class
                i_cursor.insertRow([poly, oid])
  1. Call the defined function from the code above and provide the parameters to be used.
create_view_sheds("table_name", "memory/polygon_name", "X", "Y", "left_bearing_field", "right_bearing_field", "distance_field", <wkid>)
Sample function call in the Python console

The image below shows the polygons are created from the direction of the point feature to visualize the angle of the survey area on the map.

Polygons are created from the direction of the point feature

Article ID: 000028473

Software:
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 8 x
  • ArcGIS Pro 2 x

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