[GIS] Copy multiple feature-class schemas to new geodatabase

arcgis-10.3arcpyfile-geodatabase

I am trying to write a script that copies the schema (no data) for multiple feature classes from one geodatabase to another (in this case SDE to File Geodatabse). I'm not copying all feature classes, but a list of them.

The only way I've been able to find that will allow me to copy the schema to another database is using arcpy.ExportXMLWorkspace_management() and then arcpy.ImportXMLWorkspace_management() for each feature class.

import arcpy, os
workspace = r"D:\Processing\myGDB"
myGDB = os.path.join(workspace, "TempGDB.gdb")
sdeDB = r"Database Connections\Geodatabase.sde"

fcList = [['Layerone'], ['LayerTwo'], ['LayerThree'], ['LayerFour']] # See note below!

for x in fcList:
    fc = x[0]
    xmlFile = os.path.join(workspace, "{}.xml".format(fc))
    arcpy.ExportXMLWorkspaceDocument_management(os.path.join(sdeDB, fc), xmlFile, "SCHEMA_ONLY", "BINARY", "METADATA")
    arcpy.ImportXMLWorkspaceDocument_management(myGDB, xmlFile, "SCHEMA_ONLY", "")
    arcpy.Delete_management(xmlFile)

This process is quite long-winded, as it has to step through each feature class, export the schema from geodatabase 1 to an XML file, import from that XML into geodatabase 2, and then delete the XML file.

Is there a tool or function within ArcGIS Desktop that will allow me to copy the schema to another geodatabase for selected feature classes without having to loop through them one at a time?


Note: The fcList is a list of lists as in the actual script it performs a SQL query to get the list of feature classes, and this is returned as a list of lists.

Best Answer

You can use the Create Feature Class where you create new feature classes using templates:

CreateFeatureclass_management (out_path, out_name, {geometry_type}, {template}, {has_m}, {has_z}, {spatial_reference}, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})

For full explanation of the feature, check the below code: http://desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/create-feature-class.htm

Another way that you use the GeoProcessing tool to add your files and then generate Python script from the results. (in case you want python script to add files dynamically and automate the process)

enter image description here