[GIS] Calculating length of polygon in ArcGIS Desktop

arcgis-10.2arcgis-desktoplengthlinepolygon

I am using ArcGIS 10.2.1 Desktop with an Advanced license.

My company has electric lines that go through people's yards. The areas around these lines require trimming occasionally, which necessitates acquiring easements on some properties. See attached image for an example of a work area.

I am trying to automate a process to measure a polygon or polyline (the main electric line) that crosses multiple polygons (parcels) so we can request a specific length of easement when necessary. Our current process involves creating a new polyline layer and making a new segment for the frontage of each property so the length is automatically calculated. However, this is a very slow and tedious process, as we have tens of thousands of parcels with main line.

I've tried converting the parcels polygon to lines (Feature to Line tool) and labeling based on length. However, the parcels layer is from the county, and it's pretty messy, especially in rural/non-regular areas (not visible on my attached screenshot). There are a lot of extra vertices and line segments that get pulled into the new line layer which confound the length measurements with this method. I've tried simplifying polygons to reduce/remove these extras, but simplifying too much will alter the shape of the parcel and many extraneous portions still seem to transfer over.

I've also tried buffering around the main electric line to create a polygon, then using the Identity tool with the parcels layer to split it based on property divisions. My thought was to create polygons that spanned the front of peoples' properties, then measure the length of those new polygons (we aren't concerned about width here, since that varies based on local ordinances, so it's calculated later). This produced a length field, but its values aren't even close to the actual length of each polygon.

However, I've been unable to find a way to automate the measuring of polygon length. Minimum Bounding Geometry hasn't been helpful.

Is there a script I could use or a tool that I'm missing that could simplify this process of finding the length of a polygon?

Example of main electric lines on properties

Best Answer

I am assuming that you only need an easement when a powerline crosses a parcel, and that the length of that easement is equal to the length of the line that crosses the parcel. If that's the case, you can use an intersect, based on the parcel polygons and the electric line polyline. An intersect with a polygon and polyline with result in a polyline feature class, with the attributes from the polygon copied to the polyline. Assuming each parcel has an ID field, which we will call parcel_id, you can use a script like this to automate the process:

import arcpy
import collections as c

# Define variables
parcel_fc = r"C:\easements.gdb\parcels"
powerline_fc = r"C:\easements.gdb\powerlines"
result = r"C:\easements.gdb\easement_lengths"
result_table = r"C:\easement_lengths.csv"
result_dict = c.defaultdict(float)  # a special type of dictionary in which values don't need to be initialized

#  Do the intersect, keeping only sections of line that cross parcels
arcpy.Intersect_analysis([parcel_fc, powerline_fc], result)

#  Get lengths from intersected lines
with arcpy.da.SearchCursor(result, ["parcel_id", "SHAPE@"]) as cursor:
    for row in cursor:
        result_dict[row[0]] += row[1].length  # Using a default dict here in case there are times when more than one line crosses the same parcel
        #  Note that .length is a property of the arcpy geometry class

# Write lengths to a file that can be opened in excel
with open(result_table, 'w') as f:
    for parcel in result_dict:
        f.write("{}, {}\r\n".format(str(parcel), str(result_dict[parcel])))

NOTE: This will only work as intended if electric line feature class is a polyline. If the result of the intersect is a polygon, the .length will return the perimeter, not the length.

I would recommend setting the result of the intersect to go into a geodatabase (make a feature class rather than a shapefile) before calculating lengths, though I don't think it's absolutely necessary.

Related Question