AnsweredAssumed Answered

Buffer Analysist BUFF_DIST field

Question asked by CCweedcontrol on Sep 23, 2016
Latest reply on Sep 26, 2016 by CCweedcontrol

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

Outcomes