3

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.

4
  • 1
    To save a few lines perhaps try Select_analysis() with an SQL expression of something like OBJECTID = -1 to make empty feature classes that inherit the schema of the original.
    – PolyGeo
    Oct 26, 2016 at 21:36
  • 1
    Would it be worthwhile creating an XML Workspace document on the entire GDB and creating a File GDB with that? Then delete the feature classes that don't match your criteria?
    – Fezter
    Oct 26, 2016 at 22:27
  • @Fezter that was something I considered, however there are several thousand feature classes in the enterprise GDB and I'm only trying to copy out about 60
    – Midavalo
    Oct 26, 2016 at 22:59
  • @PolyGeo that actually sounds promising, so I'll have a play with that
    – Midavalo
    Oct 26, 2016 at 23:00

1 Answer 1

3

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

1
  • Thanks for that - excellent and quick option. It does leave a couple things out, such as no domains taken across but those aren't essential and I can probably work those into my script I think.
    – Midavalo
    Oct 31, 2016 at 21:28

Your Answer

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

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