1

I am new to learning Python for GIS. I am currently trying to create a script which creates a new geodatabase, then using a list, iterates through the features of an existing geodatabase and exports these features to the new geodatabase I just created earlier in the script. I have ended up receiving the error "TEST_GDB (the new created geodatabase) does not exist or is not supported" multiple times. I researched my problem, and got the closest to a solution at this link Using geodatabase feature dataset created in ArcPy script as output/input location later on in same script? however I am still receiving the same error. It is worth noting that existing geodatabase from which I am exporting the data from is a default geodatabase for an ArcGIS Pro project.

import arcpy
# set initial environments
arcpy.env.workspace = r"C:\Users\My_Name\Documents\GIS\ODU_Home\PYTHON_ODU\Python_Script_Tool_Test\Python_Script_Tool_Test.gdb"
arcpy.env.OverwriteOutput = True
# create a list for all feature classes within old or existing geodatabase
OldData = arcpy.ListFeatureClasses()
print("Features Listed")
#Initialize variables to use in CreateFileGDB tool
out_folder_path = r"C:\Users\My_Name\Documents\GIS\ODU_Home\PYTHON_ODU"
out_name = "Test_GDB"
# create a new geodatabase & set as new workspace
GDB = arcpy.CreateFileGDB_management(out_folder_path, out_name,)
print("New .gdb created")
ws = str(str(GDB) + "\\")
arcpy.env.workspace = ws
print("New Workspace")
exportList = []
print("New list initialized")
#export feature classes from old gdb to new gdb
for Old in OldData:
 arcpy.FeatureClassToGeodatabase_conversion(Old, r"C:\Users\My_Name\Documents\GIS\ODU_Home\PYTHON_ODU\Test_GDB")
 exportlist.append(Old + "_NEW")
print("Existing Feature Classes Exported")
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jun 25, 2020 at 23:03
1
  • A file geodatabase name must end in .gdb. You're just giving a directory, not a geodatabase. Commented Jun 26, 2020 at 1:55

1 Answer 1

1

You haven't specified the correct Geodatabase name in this line

arcpy.FeatureClassToGeodatabase_conversion(Old, r"C:\Users\My_Name\Documents\GIS\ODU_Home\PYTHON_ODU\Test_GDB")

The Geodatabase will have a .gdb suffix on the end which you've left off.

arcpy.FeatureClassToGeodatabase_conversion(Old, r"C:\Users\My_Name\Documents\GIS\ODU_Home\PYTHON_ODU\Test_GDB.gdb")

But since you've already got a variable for your new Geodatabase you could just specify that instead

arcpy.FeatureClassToGeodatabase_conversion(Old, GDB)

As an aside, I don't think you need the following line:

ws = str(str(GDB) + "\\")

There is no need to add the trailing slash into the path for arcgis.env.workspace or any other arcpy tool.

GDB = arcpy.CreateFileGDB_management(out_folder_path, out_name,)
print("New .gdb created")
arcpy.env.workspace = GDB
print("New Workspace")

If you need to join a filename to a path use os.path.join() to do it automatically for you.

answered Jun 25, 2020 at 23:38
2
  • Thanks @midavalo, this actually helped fix my problem. I'm surprised I missed such an obvious error. Thank you! Commented Jun 26, 2020 at 0:30
  • 1
    @MANUELSOLANO I suspect that removing the _GDB from the geodatabase name would make it easier to spot Commented Jun 26, 2020 at 0:36

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.