0

I am a beginner at Python and for my current project I am expected to list all polyline feature classes within a dataset, find the length, and then perform a buffer analysis based on it's length. This is what I have currently:

import arcpy
from arcpy import env
env.workspace = "X:/Oil_Project.gdb"
#setting workspace
fc=arcpy.ListFeatureClasses("","Polyline","Well_Data")
#create variable to find polyline features within well data
for features in fc:
    fcdescribe=arcpy.Describe(features)
    print "Name: " + fcdescribe.name
    #prints name for each class
    for length in arcpy.da.SearchCursor(features, ["SHAPE@LENGTH"]):
        print("Length in feet = {0}".format(length[0]))
        #finds length
        if length < 3000:
            buffer_width= 75
        elif length < 4000:
            buffer_width= 300
        else:
            buffer_width= 175

I really have no idea how to perform the buffer analysis on each individual polyline feature automatically. I'm also not sure if I can do anything with the buffer_width variable.

1

You will need to add a Buffer_Width field to any feature classes you want to perform buffers on. Then use an Update cursor to assign the buffer values to that field. You can then use the Buffer_Width field as the input for the Buffer analysis. I've edited your code block to add the extra field and attribute it. You just need to add in an extra line to perform the Buffer analysis.

for features in fc:
    fcdescribe=arcpy.Describe(features)
    print "Name: " + fcdescribe.name
    #prints name for each class

    # Add new field to store the Buffer Width
    arcpy.AddField_management(features, "Buffer_Width", "DOUBLE")

    with arcpy.da.UpdateCursor(features, ["SHAPE@LENGTH", "Buffer_Width"]) as aRows:
        for length in aRows:
            print("Length in feet = {0}".format(length[0]))
            #finds length
            if length[0] < 3000:
                length[1] = 75
            elif length[0] < 4000:
                length[1] = 300
            else:
                length[1] = 175
            aRows.updateRow(length)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.