AnsweredAssumed Answered

How to calculate parcel frontages and put the output sum into a field in the parcel feature class?

Question asked by travislpreston on Dec 7, 2017
Latest reply on Dec 8, 2017 by jskinner-esristaff

I currently have a code that is performing most of what i want it to do but I need to associate summed values with the corresponding parcels. Right now I believe the code is giving me the sum of all frontage that falls within a buffer area. I need to figure out how to sum each of the lines that make up individual parcels, sum them and add them to a field in the parcel layer.

# Import the Arcpy Module
import arcinfo
import arcpy
from arcpy import env

# Set up the working Environment

env.workspace = r"D:\Travis\Personal\Geoff\Nantucket\Zoning\Backlots\Backlots.gdb"
env.overwriteOutput = True

#Variables
Parcels = "R40_80000sqft"
Street_Center = "ROAD_CL_2017_12"

arcpy.MakeFeatureLayer_management(Parcels,"Parcels_lyr")
arcpy.MakeFeatureLayer_management(Street_Center,"Street_Lyr")

Street_Lyr = "Street_Lyr"
Parcels_lyr = "Parcels_Lyr"

#Add a field to parcels to be populated with building area
arcpy.AddField_management(Parcels,"Frontage","DOUBLE")

# Buffer Street Center Lines
arcpy.Buffer_analysis(Street_Lyr,"Street_Buff","40 Feet","FULL","ROUND","ALL")

Street_Buff = "Street_Buff"

#Convert parcel layer polygons to lines
arcpy.PolygonToLine_management(Parcels_lyr,"R40_PolyToLine")

R40_Line = "R40_PolyToLine"

#Convert parcel lines to a layer for use in select by location
arcpy.MakeFeatureLayer_management(R40_Line,"R40_Line_Lyr")

R40_Line_Lyr = "R40_Line_Lyr"

#Create a cursor to select all parcel lines that fall within the street buffer
with arcpy.da.UpdateCursor(Parcels_lyr, ['Shape@','Frontage']) as linecursor:
    for linerow in linecursor:

     #get the geometry to use in the spatial selection
     geom = linerow[0]

     #select parcel lines from the street buffer using the geom variable
     arcpy.SelectLayerByLocation_management(R40_Line_Lyr, "COMPLETELY_WITHIN", Street_Buff, "", "NEW_SELECTION")

     #get the Length of the selected features and sum
     lengthsum = 0
     with arcpy.da.SearchCursor(R40_Line_Lyr,['SHAPE@LENGTH']) as newcursor:
        for newrow in newcursor:
            lengthsum = lengthsum + newrow[0]

     print lengthsum

     del newcursor

     parcelrow[1]= lengthsum

     if lengthsum != 0:
        parcelrow[2] = lengthsum

     else:
        parcelrow[2] = 0

     linecursor.updateRow(linerow)

del linecursor

Outcomes