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:
-
That looks like a data issue. What is the full text that starts "This handsome, tall"?PolyGeo– PolyGeo ♦2017年01月25日 00:30:00 +00:00Commented Jan 25, 2017 at 0:30
2 Answers 2
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.
-
Thanks for the advice. I ended up taking a different route, but I will test your method out in the future.saoirse– saoirse2017年01月25日 07:21:19 +00:00Commented Jan 25, 2017 at 7:21
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.
Explore related questions
See similar questions with these tags.