Buffer Analysist BUFF_DIST field

1095
2
09-23-2016 12:38 PM
CCWeedcontrol
Occasional Contributor III

The BUFF_DIST field is not being populated and i am not sure why. Can some one explain to me what i am doing wrong please?

Current code.

import arcpy, os

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "SUBJECT_PROPERTY")[0]
#lyrpath = lyr.workspacePath
arcpy.env.workspace = os.path.dirname(mxd.filePath)
wp = os.path.dirname(mxd.filePath)

try:
    SP = "SUBJECT_PROPERTY" 
    lyr.replaceDataSource(wp, "SHAPEFILE_WORKSPACE", SP, True )
except:
    pass
try:
    if arcpy.ListFields(SP, "BUFF_DIST"):  
         print "Field exists"  
    else:  
        arcpy.AddField_management("SUBJECT_PROPERTY","BUFF_DIST","Double")
except:
    pass

arcpy.RefreshActiveView()
arcpy.RefreshTOC()


distances = ["2 Mile", "1 Mile"]
for distance in distances:
    outfile = "wp%s" % distance  
    arcpy.Buffer_analysis(SP, outfile, distance, "OUTSIDE_ONLY", "ROUND", "", "BUFF_DIST")

i tried to use the arcpy.da.UpdateCursor to update the BUFF_DIST field of the new feature classes but on the the first one gets populated.

Code with arcpy.da.UpdateCursor

import arcpy, os

mxd = arcpy.mapping.MapDocument("CURRENT")
lyr = arcpy.mapping.ListLayers(mxd, "SUBJECT_PROPERTY")[0]
#lyrpath = lyr.workspacePath
arcpy.env.workspace = os.path.dirname(mxd.filePath)
wp = os.path.dirname(mxd.filePath)

try:
    SP = "SUBJECT_PROPERTY" 
    lyr.replaceDataSource(wp, "SHAPEFILE_WORKSPACE", SP, True )
except:
    pass
try:
    if arcpy.ListFields(SP, "BUFF_DIST"):  
         print "Field exists"  
    else:  
        arcpy.AddField_management("SUBJECT_PROPERTY","BUFF_DIST","Double")
except:
    pass

arcpy.RefreshActiveView()
arcpy.RefreshTOC()


distances = ["2 Mile", "1 Mile"]
for distance in distances:
    outfile = "wp%s" % distance  
    arcpy.Buffer_analysis(SP, outfile, distance, "OUTSIDE_ONLY", "ROUND", "", "BUFF_DIST")


with arcpy.da.UpdateCursor("wp%s" % distance, "ToBufDist") as cursor:
            for row in cursor:
                if row[0] in (""," ",None):
                    row[0] = '1'
                    cursor.updateRow(row)           
                else:
                    pass
with arcpy.da.UpdateCursor("wp%s" % distance, "ToBufDist") as cursor:
            for row in cursor:
                if row[0] in (""," ",None):
                    row[0] = '2'
                    cursor.updateRow(row)           
                else:
                    pass
0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor

This is a good example of why you should try running the misbehaving tool in the GUI. Try it. You need to set the "dissolve_type" to "LIST" before it will let you choose a field to dissolve upon:

arcpy.Buffer_analysis(SP, outfile, distance, "OUTSIDE_ONLY", "ROUND", "LIST", "BUFF_DIST")
0 Kudos
CCWeedcontrol
Occasional Contributor III

Before i posted i did have "LIST" for the dissolve_type. i was trying with out it to see how it behaved and with or without "LIST" as the dissolve_type. With "LIST" it still doesn't' get populated. When i run the tool it runs fine but it is with "one" distance not two.

When i ran the tool i used 1 linear unit as miles and i did not use the dissolve type and the field BUFF_LIST got populated with 5280 ft.

0 Kudos