matt_msuk

Problems with buffering selected featureclasses from multiple geodatabases

Discussion created by matt_msuk on Oct 5, 2012
Good afternoon,
I have a large number of featureclasses which are stored in different geodatabases in different locations. I would like to buffer a large number of these featureclasses. I am new to python but have had a go at a script and cant seem to get it to work for more than one geodatabase. Can anyone point out what I am doing wrong or suggest a different approach I should try. Thank you.


# imports arcpy and os
import arcpy
import os.path
import tempfile
from arcpy import env

# Output workspace and temp location is defined
output_workspace = "C:/GIS Home/project_1"
temp_workspace = tempfile.mkdtemp()

#create empty lists for output
l_250 = []
l_500 = []
l_750 = []

gdbs = {r"\\Msukserver\gis\geodatabase BACKUP\BRIAN\Mining Features (BRIAN).gdb":["Adit_Metalliferous", "Shaft_Metalliferous"],
        r"\\Msukserver\gis\geodatabase BACKUP\GEORGE\Mining Features (GEORGE).gdb":["Adit_Metalliferous", "Shaft_Metalliferous"],
        r"C:\GIS Home\Data\QUARRY.gdb":["Active", "Close", "Dormant"]}

for gdb, fcList in gdbs.iteritems():
    arcpy.env.workspace = gdb
    if gdb == "Mining Features (BRIAN).gdb":
        for featureClass in fcList:
            bb250 = os.path.join(temp_workspace, featureClass + "brian_b250.shp")  # make temp output file
            bb500 = os.path.join(temp_workspace, featureClass + "brian_b500.shp")  # make temp output file
            bb750 = os.path.join(temp_workspace, featureClass + "brian_b750.shp")  # make temp output file
            arcpy.Buffer_analysis(featureClass, bb250, 250, "", "", "ALL")   # carry out buffer
            arcpy.Buffer_analysis(featureClass, bb500, 500, "", "", "ALL")   # carry out buffer
            arcpy.Buffer_analysis(featureClass, bb750, 750, "", "", "ALL")   # carry out buffer
            l_250.append(bb250)  # append the buffer to the l_250 list
            l_500.append(bb500)  # append the buffer to the l_500 list
            l_750.append(bb750)  # append the buffer to the l_750 list
    elif gdb == "Mining Features (GEORGE).gdb":
        for featureClass in fcList:
            gb250 = os.path.join(temp_workspace, featureClass + "geo_b250.shp")  # make temp output file
            gb500 = os.path.join(temp_workspace, featureClass + "geo_b500.shp")  # make temp output file
            gb750 = os.path.join(temp_workspace, featureClass + "geo_b750.shp")  # make temp output file
            arcpy.Buffer_analysis(featureClass, gb250, 250, "", "", "ALL")   # carry out buffer
            arcpy.Buffer_analysis(featureClass, gb500, 500, "", "", "ALL")   # carry out buffer
            arcpy.Buffer_analysis(featureClass, gb750, 750, "", "", "ALL")   # carry out buffer
            l_250.append(gb250)  # append the buffer to the l_250 list
            l_500.append(gb500)  # append the buffer to the l_500 list
            l_750.append(gb750)  # append the buffer to the l_750 list
    elif gdb == "BGS BritPITS.gdb":
        for featureClass in fcList:
            ab250 = os.path.join(temp_workspace, featureClass + "arup_b250.shp")  # make temp output file
            ab500 = os.path.join(temp_workspace, featureClass + "arup_b500.shp")  # make temp output file
            ab750 = os.path.join(temp_workspace, featureClass + "arup_b750.shp")  # make temp output file
            arcpy.Buffer_analysis(featureClass, ab250, 250, "", "", "ALL")   # carry out buffer
            arcpy.Buffer_analysis(featureClass, ab500, 500, "", "", "ALL")   # carry out buffer
            arcpy.Buffer_analysis(featureClass, ab750, 750, "", "", "ALL")   # carry out buffer
            l_250.append(ab250)  # append the buffer to the l_250 list
            l_500.append(ab500)  # append the buffer to the l_500 list
            l_750.append(ab750)  # append the buffer to the l_750 list

merge_250 = os.path.join(temp_workspace, "250_merge.shp")
arcpy.Merge_management(l_250, merge_250)
merge_500 = os.path.join(temp_workspace, "500_merge.shp")
arcpy.Merge_management(l_500, merge_500)
merge_750 = os.path.join(temp_workspace, "750_merge.shp")
arcpy.Merge_management(l_750, merge_750)

dissolve_250 = os.path.join(output_workspace, "250_dissolve.shp") # create 250_dissolve.shp for final output
arcpy.Dissolve_management(merge_250, dissolve_250)
dissolve_500 = os.path.join(output_workspace, "500_dissolve.shp") # create 500_dissolve.shp for final output
arcpy.Dissolve_management(merge_500, dissolve_500)
dissolve_750 = os.path.join(output_workspace, "750_dissolve.shp") # create 750_dissolve.shp for final output
arcpy.Dissolve_management(merge_750, dissolve_750)

Outcomes