Arcpy create a new geodatabase
To create a new geodatabase using ArcPy, you can use the CreateFileGDB
function. Here's an example:
import arcpy
# Set the path and name of the new geodatabase
gdb_path = "C:/Path/To/NewGDB.gdb"
gdb_name = "NewGDB"
# Create the new geodatabase
arcpy.CreateFileGDB_management(gdb_path, gdb_name)
This code creates a new file geodatabase named "NewGDB" in the specified path "C:/Path/To/NewGDB.gdb".
If you want to create a new personal geodatabase (.mdb
file), you can use the CreatePersonalGDB
function instead:
arcpy.CreatePersonalGDB_management("C:/Path/To/NewGDB.mdb", "NewGDB")
Note that the CreateFileGDB
function is only available in ArcGIS 10.0 and later, while the CreatePersonalGDB
function is available in ArcGIS 9.3 and later.
You can also specify additional options when creating a new geodatabase, such as the compression type or the maximum size of the geodatabase. For example:
arcpy.CreateFileGDB_management(gdb_path, gdb_name, compression="LZ77", max_size="1000 MB")
This code creates a new file geodatabase with LZ77 compression and a maximum size of 1000 MB.
Make sure to check the ArcPy documentation for the most up-to-date information on creating new geodatabases using ArcPy.