6

I have 150+ feature classes in SDE for which I need to create an empty feature class in a file geodatabase. For these feature classes I need to import the attributes and the name of the feature class as in SDE. I tried to export to an XML workspace document but it is not working because of some error on the SDE and I'm not an SDE administrator, so I am unable to modify the things on the SDE.

An alternative to this that I tried was creating a script in Python for creating the feature class. I get the names of the feature class from the SDE but am unable to create them on the local SDE.

Also how can I read the geometry type for the feature class in arcpy?

Here is the code I've written:

import arcpy
arcpy.env.workspace= r"C:\Users\088927\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\ENT-QA @ sample.sde"
fcList = arcpy.ListFeatureClasses('sde."ENT-QA".*',"","")
output = "C:/Users/088927/Desktop/Schema.gdb"
for fc in fcList:
    fullName = arcpy.ParseTableName(fc)
    #fcTemplate = fc.
    finallist = []
    nameList = fullName.split(",")
    databaseName=nameList[0]
    ownerName = nameList[1]
    fcName = nameList [2]
    fcStr = str(fcName)
    print fcStr
    arcpy.CreateFeatureclass_management(r"C:\Users\abc\Desktop\Schema.gdb",fcstr)
4
  • What error did you get when you attempted to export to an XML workspace document, and what options did you set on the export dialog?
    – blah238
    Apr 27, 2012 at 21:33
  • How would I accept answers. What should I do I didnt know anything about. Thanks for letting me know @blah238 Apr 27, 2012 at 21:33
  • Hi @blah238 I'm getting an error for unable to create an XML because of some layers got corrupted on the SDE. As you asked me to accept the previous answers I did go checked dthe button for the answer it is not there on my quesitions. Do I need to activate anything before I see that button on my questions. Thanks. Apr 27, 2012 at 21:42
  • The accept button is on other users' answers to your questions. You are accepting their answers as the best solution to your questions.
    – blah238
    Apr 27, 2012 at 21:44

2 Answers 2

9

Just use the CreateFeatureClass tool, passing the original feature class as the template argument. Grab the shape type from the Describe object of the input feature class.

Unlike the other answer, this won't copy a bunch of unnecessary records only to delete them right away.

import arcpy
arcpy.env.workspace= 'MyGDB.gdb'
fcs = arcpy.ListFeatureClasses()
output = "OutGDB.gdb"
for fc in fcs:
    geom = arcpy.Describe(fc).shapeType
    arcpy.CreateFeatureclass_management(output, fc, geom, fc, spatial_reference=fc)

UPDATE:

If you need to preserve domains/subtypes, then run Select_analysis using a generic where clause that will capture none of the records, like OBJECTID < 0:

import os, arcpy
arcpy.env.workspace= 'MyGDB.gdb'
fcs = arcpy.ListFeatureClasses()
output = "OutGDB.gdb"
wc = 'OBJECTID < 0'
for fc in fcs:
    fc_out = os.path.join(output, fc)
    arcpy.Select_analysis(fc, fc_out, wc)

This is far more efficient than copying all the records and then deleting them. I've yet to find an approach that will preserve editor tracking.

5
  • Unfortunately this method does not also export domains and subtypes only the fieldname schema Mar 2, 2018 at 19:03
  • @TristanForward, if retaining domains, etc. is a requirement, then it would be far more efficient than GetSpatial's answer to run arcpy.Select_analysis with a where clause like OBJECTID < 0
    – Tom
    Mar 5, 2018 at 16:00
  • @Tom I've noticed that this technique only copies domains that are currently being used, and not all possible domains. For instance, if I have a subtype/domain defined that does not yet have any features associated with it, the subtype/domain will not be copied.
    – Barbarossa
    Oct 15, 2018 at 14:37
  • @Barbarossa, that's because domains belong to the database and not to the table/feature class. If it's not being used by the table, then why would you want to copy it anyway? You can use DomainToTable and TableToDomain to copy a domain between databases, but that's for a different question.
    – Tom
    Oct 15, 2018 at 17:37
  • @Tom I have a standardized schema that is used across an entire organization. Someone who comes behind me may wish to add a subtype/domain that is no longer there. I just want to point out to those in my particular situation that this may not be the best solution for them.
    – Barbarossa
    Oct 15, 2018 at 18:35
6

Short of being able to figure out why you cannot export an XML schema from SDE, there is a quick and dirty method you might try. This will depend on if you have enough space and privileges.

  1. Create an empty file geodatabase.
  2. Use the copy featureclass tool with the batch option to copy all 150 featureclasses from the SDE geodatabase to your empty file geodatabase.
  3. Set up a python script to cycle through all the featureclasses and run the delete features tool on each of them.

Assuming this works, it should leave you with a file geodatabase that contains all of the empty featureclasses from SDE with all the attribute fields and even the domains and relationship classes if they were defined.

It is definitely clunky, but I've also run across a schema that would not export to an xml workspace due to errors in the schema.

As for your other question, you might check out this help topic on working with geometries It should at least get you on the right track. It may also help to post that as a separate question, or search to see if it has already been asked.

Good luck!

2
  • 3
    To speed things up, and make it slightly less clunky, select just one feature before making a copy. This way the copy and the delete should go a lot faster if your feature class has a lot of data in it.
    – dvdhns
    Sep 11, 2015 at 21:24
  • 1
    If you're going to copy all the records, you could at least use Truncate instead of DeleteFeatures; it's much more efficient.
    – Tom
    Mar 5, 2018 at 16:08

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.