0

I'm interested in generating a dbf from a feature class in a gdb. I am also interested in selecting only 6 out of the many fields, which is why I added steps to keep only wanted fields. I am using python on ArcMap and ArcCatalog 10.3.1. Here is the code:

fc = r"C:\Users\migrate\Desktop\SFBG_GIN_Test\gdb\SFBG_GIN_Test.gdb\PlantCenter_Test"
dbfLocation = r"C:\Users\migrate\Desktop\SFBG_GIN_Test\dbf"
dbfOutputName = "Plants_GIS"
dbfPath = dbfLocation + '\\' + dbfOutputName + '.dbf'

if arcpy.Exists(dbfPath): # This line exists to overwrite any existing dbfs
    dm.Delete(dbfPath)

arcpy.TableToTable_conversion (fc, dbfLocation, dbfOutputName)

# Get all fields in dbf and remove unwanted fields
fields = arcpy.ListFields("fc_temp") 
keepFields = ['GIS_2016_08_25', 'SourceAcce', 'AccessionC', 'SectionNam', 'Longitude', 'Latitude']
dropFields = [x.name for x in fields if x.name not in keepFields]
dm.DeleteField (dbfPath, dropFields)
print "DBF created"

I get the following error:

enter image description here

1
  • That looks like a data issue. What is the full text that starts "This handsome, tall"?
    – PolyGeo
    Commented Jan 25, 2017 at 0:30

2 Answers 2

1

It appears that TableToTable is having problems converting all of the fields in the featureclass to an equivalent field type for the DBF. Try using MakeTableView_management to create a table view with only the fields you want (those in the keepFields list) before using TableToTable.

Note that the DBF format doesn't allow a text field with over 255 characters.

1
  • Thanks for the advice. I ended up taking a different route, but I will test your method out in the future.
    – saoirse
    Commented Jan 25, 2017 at 7:21
0

I worked around the error by converting the gdb feature class to an excel file (TableToExcel), then from excel to dbf (ExceltoTable). I then deleted the unnecessary fields. Not quite certain why this works however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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