0

I have a script that runs perfectly with shapefiles and GDB feature classes but I need to change it to run on feature classes stored on an SDE. However I cannot figure out how to reference them correctly via ArcPy and I haven't been able to find a good resource. Here is what I have so far:

C:/Users/cbunn/AppData/Roaming/ESRI/Desktop10.5/ArcCatalog/my.sde//FeatureDataset//FeatureClass

How should I change this path so it is correct and I can access it via ArcPy?

2

If you navigate to the feature class in question in the catalog window of ArcMap or in ArcCatalog, the "Location:" field should contain the valid full path for the feature class that you can copy and paste into your script. But in general for data stored in an SDE database, Feature Datasets and Feature Classes will have a full name of Database.Schema.Dataset

Example:

If you had a database called MyDatabase and it used the SDE schema, the path may look like

fc = r'C:\Folder\Subfolder\MyDatabase.sde\MyDatabase.OwnerSchema.FeatureDatasetName\MyDatabase.OwnerSchema.FeatureClassName'

or, since the database is a property of the connection,

fc = r'C:\Folder\Subfolder\MyDatabase.sde\OwnerSchema.FeatureDatasetName\OwnerSchema.FeatureClassName'

Feature classes outside a feature dataset would be one of:

fc1 = r'C:\Folder\Subfolder\MyDatabase.sde\MyDatabase.OwnerSchema.FeatureClassName'
fc2 = r'C:\Folder\Subfolder\MyDatabase.sde\OwnerSchema.FeatureClassName'
fc3 = r'C:\Folder\Subfolder\MyDatabase.sde\FeatureClassName'

(the last only valid if the connection user is the owning schema)

Similarly, if you used the DBO schema with SQL Server, it may look like:

fc1 = r'C:\Folder\Subfolder\MyDatabase.sde\MyDatabase.DBO.FeatureDatasetName\MyDatabase.DBO.FeatureClassName'
fc2 = r'C:\Folder\Subfolder\MyDatabase.sde\DBO.FeatureDatasetName\DBO.FeatureClassName'
fc3 = r'C:\Folder\Subfolder\MyDatabase.sde\MyDatabase.DBO.FeatureClassName'
fc4 = r'C:\Folder\Subfolder\MyDatabase.sde\DBO.FeatureClassName'

Also, when using a file path in Python, you have a few options for how you format the path.

  • You can flip the slash one for one (change \ to / ) as you appear to have done in your example. Except, after my.sde you doubled them up, and they should still be single forward slashes.
  • You can double up backslashes (ex: C:\\Folder\\Subfolder\\File.txt)
  • Or you can use the full path, exactly as is, and just denote it as a raw string by preceding it with r. Ex: r'C\Folder\Subfolder\File.txt'
  • How do I navigate to the "Location:" field? – cbunn Jul 13 '18 at 21:24
  • On desktop.arcgis.com/en/arcmap/10.3/manage-data/using-arccatalog/… scroll down and find where it discusses "Location toolbar". – John Jul 13 '18 at 21:36
  • 1
    The SDE schema shouldn't ever own spatial data, which makes for a suboptimal example. – Vince Jul 13 '18 at 22:43
  • @Vince sorry for the bad example, my office only uses DBO schema, so I'm not really familiar with specifics of SDE schema. Feel free to edit as needed. – John Jul 16 '18 at 14:21
  • SInce DBO schema is the exception rather than the rule, I fleshed out a few more examples, and included the raw formatting tag in the examples – Vince Jul 17 '18 at 2:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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