3

I am trying to join a csv file to a shapefile based on an ID field that keeps giving me this error:

ExecuteError: ERROR 000210: Cannot create output C:\Users\geo.gdb\2010reg
Failed to execute (CopyFeatures).

Here is my code:

import arcpy
env.workspace = r"C:\Users\geo.gdb"
arcpy.env.qualifiedFieldNames = False

# Set local variables for join  
inFeatures = r'C:\Users\shapefile1.shp'
layerName = "ID"
joinTable = r"C:\Users\csv1.csv"
joinField = "ID"
outFeature = r"C:\Users\geo.gdb\successJoined.shp"

arcpy.MakeFeatureLayer_management (inFeatures,  layerName)

# Join the feature layer to a table
AddJoin_management(layerName, joinField, joinTable, joinField)

# Select desired features from veg_layer#
arcpy.SelectLayerByAttribute_management(layerName, "NEW_SELECTION")

# Copy the layer to a new permanent feature class
arcpy.CopyFeatures_management(layerName, outFeature)

I would like to copy all matched rows to a new output feature class. I do not want it to contain non-matching rows. The key "ID" is the same in both the csv and the shapefile. I am getting the error above that will not allow the final copy to work.

5

Within your Join function, you can set the join type to "Keep Common". This will only join features where ID = ID.

If you are trying to do a "Select By Attribute" function to find where ID = ID, this is not needed if you use the join type mentioned above.

The reason why the Copy Features tool doesn't work, is because you have set your workspace as a GDB, and then trying to export the final joined dataset as a shapefile. If you want the final output to be a shapefile, you need to set your workspace to a folder, rather than GDB.

If you want our output as a shapefile, use:

env.workspace = r"path/to/folder"

outFeature = r"C:\Users\geo.gdb\successJoined.shp"

If you want it to be a feature class, use:

env.workspace = r"C:\Users\geo.gdb"

outFeature = "successJoined"

Dependant on which output you want, you should input the above into:

import arcpy
env.workspace = 
arcpy.env.qualifiedFieldNames = False

# Set local variables for join  
inFeatures = r'C:\Users\shapefile1.shp'
layerName = "ID"
joinTable = r"C:\Users\csv1.csv"
joinField = "ID"
outFeature = 

arcpy.MakeFeatureLayer_management (inFeatures,  layerName)

# Join the feature layer to a table
AddJoin_management(layerName, joinField, joinTable, joinField, "KEEP_COMMON")

# Copy the layer to a new permanent feature class
arcpy.CopyFeatures_management(layerName, outFeature)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.