Hi
I have many tables which I need to join to a Shapefile. Each table has to be joined to the shapefile seperately and then must be exported into a file GDB.
Anyone knows how to do so with python? Is there a way that the code runs automatically through each table in the folder and joins it to the shapefile, exports it as FC in the GDB, gives it the file name of the table, then removes the join and joins the next table to the same shapefile? I work with ArcGIS 10.1
I came across this site ArcGIS Help 10.1 and also ArcGIS Help 10.1 but I have no clue how to get started to be honest..
Solved! Go to Solution.
Hi P V,
Here is an example on how you could do this:
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\tables" shapefile = r"C:\data\parcels.shp" #loopo through tables in C:\temp\tables for table in arcpy.ListTables("*"): #Create a new feature layer, this will remove previous join arcpy.MakeFeatureLayer_management(shapefile, "parcelLyr") #Join table to feature layer arcpy.AddJoin_management("parcelLyr", "PIN", table, "PIN") #Retrieve table name tableName = table.split(".")[0] #Export joined layer to new feature clas arcpy.FeatureClassToFeatureClass_conversion("parcelLyr", r"C:\data\ParcelData.gdb", tableName)
Hi P V,
Here is an example on how you could do this:
import arcpy from arcpy import env env.overwriteOutput = 1 env.workspace = r"C:\temp\tables" shapefile = r"C:\data\parcels.shp" #loopo through tables in C:\temp\tables for table in arcpy.ListTables("*"): #Create a new feature layer, this will remove previous join arcpy.MakeFeatureLayer_management(shapefile, "parcelLyr") #Join table to feature layer arcpy.AddJoin_management("parcelLyr", "PIN", table, "PIN") #Retrieve table name tableName = table.split(".")[0] #Export joined layer to new feature clas arcpy.FeatureClassToFeatureClass_conversion("parcelLyr", r"C:\data\ParcelData.gdb", tableName)
Thank you a lot! This code worked PERFECTLY!!!
I only added this line to it: env.qualifiedFieldNames = False