Friday, 15 May 2015

arcgis 10.3 - Set workspace to SDE version using ArcPy?


My company uses a versioned SDE database to perform edits, update features, etc.


I am working on a script that would inevitably update features and would like to set the environment to a specific version.


The environment set to the SDE would look like this:


arcpy.env.workspace = "C:\\Users\\MyName.CENTRAL\\AppData\\Roaming\\ESRI\\Desktop10.3\\ArcCatalog\\Production.sde

My version is called "SY.TEST"


How do I define this version (only) as the workspace?




Answer



You can set your .sde database connection to a specific version in ArcCatalog so that any access to the gdb using that connection will use that version.


In the Catalog window, create a new connection to your database (or copy/paste your existing connection). Right-click on the new connection and select Geodatabase Connection Properties...


enter image description here


In the dialog that opens you can specify which Version to use with that connection file


enter image description here


Now any layers added to ArcMap from that connection will automatically be using the specified version. Using Arcpy with this connection will work the same way.


Alternatively, most interactions with versioned feature classes using arcpy will require an edit session, at which time you can specify a version to use. See arcpy.ChangeVersion_management() and arcpy.da.Editor()


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...