AnsweredAssumed Answered

Accessing shapefiles/dbfs within a geodatabase with python

Question asked by Carusot42 on Dec 30, 2014
Latest reply on Dec 30, 2014 by curtvprice

Hi folks,


I feel like there's a very simple answer to this because no matter how much I searched I couldn't find one, however I'm pretty much brand new to gdb's, have mostly just used shapefiles up until now and I'm having trouble getting python to access the table of/a shapefile within a geodatabase. Here is the script I'm writing currently, can someone give me some direction here?


import arcpy
# Set workspace
arcpy.env.workspace = "C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb"

# Define input feature layer & wells
orps09 = "C:\Users\tmc18\Desktop\comp_orps\centroids\madirps_point_Layer.lyr"
wells = "C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb\Madison_DEC_Well_Logs_3_14_14_MASTER_COPY.dbf"
wellshp = "C:\Users\tmc18\Desktop\comp_orps\NYS_Wells.gdb\Madison_DEC_Well_Logs_3_14_14_MASTER_COPY.shp"

# Define fields cursors will require
county = "County"

# Create search cursor
with arcpy.da.SearchCursor(wells, [county]) as cursor:
        for row in cursor:
                if county == "MADISON":
                        arcpy.SelectLayerByLocation_management(orps09, [within_a_distance, "1 km", add_to_selection])


I'm getting errors because within the gdb, the dbf and shapefiles don't exist. Since I see them there in ArcCatalog I thought it might work anyways, but obviously that is not the case.


Many thanks in advance for your help,