Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to use Arcpy to run the CopyFeatures_management script so that I can copy a featurelayer in SDE.

What do I use for the input (and output, for that matter, since I'll be copying the layer back to SDE) to access the layer?

share|improve this question
up vote 8 down vote accepted

You'll use the path to the SDE file plus the feature class name, so something like

CopyFeatures_management(r'c:\connections\my.sde\fc1', r'c:\connections\my.sde\newfc')

share|improve this answer
And the 'r' in front of the text does the same thing in Python as '@' in C#, i.e. treats the string as a literal so the '\' aren't misconstrued as control characters? – Michael Todd Jan 26 '11 at 23:45
Correct. Marks string as literal without control characters. – Jason Scheirer Jan 27 '11 at 0:00

Two ways that I can think of, both involve having a Database Connection already set up in ArcCatalog. If the Database Connection file does not already exist, you can use CreateArcSDEConnectionFile_management in your script to create it.

1) Set the current workspace to the database connection, and then refer to the feature class by name.

arcpy.env.workspace = r"Database Connections\MySDEDatabaseConnection.sde"
fc = "SDE.myFeatureClass"

If the feature class is in a feature dataset, tack on the the feature dataset name to the workspace like so:

arcpy.env.workspace = r"Database Connections\MySDEDatabaseConnection.sde\SDE.MyFeatureDataset"

2) Supply the full path to the feature class including the database connection:

fc = r"Database Connections\MySDEDatabaseConnection.sde\SDE.MyFeatureDataset\SDE.MyFeatureClass"

Some tools require the first method, others require the second.

Also "Database Connections" is actually just a shortcut to %APPDATA%\ESRI\Desktop10.0\ArcCatalog (for ArcGIS 10 on Windows XP). You can just as easily supply the full path to .sde files that are stored in that folder or other folders.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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