Python alternative for sdelayer command

11-10-2016 12:11 AM
New Contributor


We are using the ArcSDE command tool set at the moment but in time when we upgrade to ArcGIS 10.4 the command toolset will not be available and we need to figure out a way to solve certain tasks in Python instead. For example, today we do like this:

1. Create a table with column SHAPE using the SDE_ST_GEOMETRY type. 

  (In user schema uno)

Label VARCHAR2(100) NULL ,
lastUpdate DATE NOT NULL ,

2. Using SDE command tool sdelayer to "register" the table/column in SDE:

sdelayer -o add -l uno.TEST_SPACE,shape -e nac+ -R 1 -k DEFAULTS -E 220000,6000000,1000000,7700000 -t ST_GEOMETRY -C OID,USER -s server1 -i sde:oracle11g:VNUTVTD_SERVER1 -u uno -p uno

So far so good. But how should this be done with Python when sdelayer is gone? I have searched the internet for examples but can't find any solutions that solves the same problem.

I have tried to use arcpy.CreateFeatureclass_management but that creates the table, in my test from a template table which hade exactly the same appearence as TEST_SPACE. But then I ran into other problems like that the column OID was renamed to OBJECTID with data type "Object ID".

I would like to have a solution that replaces just the "sdelayer" command. 

Any suggestions? Tips of any kind would be of great value. 


0 Kudos
7 Replies
MVP Esteemed Contributor

The OBJECTID is the correct fieldname for a featureclass object id field (hence the type name).  Conversions will be to the types of fields required by a featureclass.  Python offers

Make Feature Layer—Help | ArcGIS for Desktop 

Save To Layer File—Help | ArcGIS for Desktop 

Copy Features—Help | ArcGIS for Desktop 

Or are you looking for .Migrate from ArcSDE administration commands—Help | ArcGIS for Desktop 

New Contributor

Thanks Dan for your answer. I checked your links but I can't find any solution to what I want to do. 

Still I would prefer to exchange the sdelayer-command with something similar in Python. We're scripting the database creation and uses output from Erwin together with our own Python scripts. If that's impossible I could think of a second solution which includes a call to arcpy.CreateFeatureclass_management.

About the column OBJECTID. I know that this is the default name for this kind of field. Nevertheless we have the option "-C" in sdelayer to assign our own named column to have the same behaviour (featureclass object id field). This means we dont need to go with the default name if we don't like. We have a number of tables created over the years where we use OID instead of OBJECTID and we'ld like to continue with that. Otherwise we got some other problems to deal with. 

"-C OID,USER"   says that row_id_column to use is OID and that we want to keep the sequence user maintained. That is SDE doesn't have to do it for us which is the default. If it's possible to do with sdelayer it should be possible with arcpy package or am I missing something here?

0 Kudos
MVP Esteemed Contributor

I haven't seen any ability to over-ride the object id field name, in fact the property in arcpy is read-only

Migrate from ArcSDE administration commands—Help | ArcGIS for Desktop but you can use it to read the object id name... see the code snippets throughout the arcpy section .... for example, from the help, to obtain information about any input (in this case a layer in a geodatabase), a 'describe' object is created and queries to see if it has an object id field.  If it does, then the name is printed.  If the input were a pure table or some other non-spatial object, there would be no such field and nothing would be printed.

desc = arcpy.Describe("C:/data/chesapeake.gdb/munich")
if desc.hasOID:
    print("OIDFieldName: " + desc.OIDFieldName)

Arcpy for arcmap    What is ArcPy?—Help | ArcGIS for Desktop 

Tools in arcmap      A quick tour of geoprocessing tool references—Help | ArcGIS for Desktop 

arcpy for Pro            ArcGIS Pro ArcPy Reference—ArcGIS Pro | ArcGIS for Desktop 

Tools in Pro              ArcGIS Pro tool reference—ArcGIS Pro | ArcGIS for Desktop 

Is pretty well what I use to navigate around

0 Kudos
New Contributor

I just tested to create the table as I described above (in SqlDeveloper). Then in ArcCatalog 10.3.1, right-click on the table name, and select "Manage/Register with geodatabase". Now what happens is that ArcCat discovers that I have two columns in the table that can serve has Object Id - OID and OwnerDID. Then I select OID and that makes that column to change data type to "Object Id". This is the same as the sdelayer option "-C OID" and exactly what I want. 

But, the sequence is still maintained by SDE and not by me, i.e. USER. That becomes the next problem. 

Anyway, this discovery makes me think that there's still hope for making this possible in Python. If ArcCatalog allows it here i ArcCatalog, why shouldn't it be possible in Python? Hopefully it's possible to achieve the same thing as the whole sdelayer-command. The only question now is HOW?

0 Kudos
MVP Esteemed Contributor

Prior to ArcGIS 10.5, when calling the Register With Geodatabase tool from Python, a user could only pass the dataset, nothing else.  With 10.5, they are adding functionality from Python that has existed through the GUI for a little while.  That said, I don't think there is anyway around the geodatabase taking over management of the ID field.

0 Kudos
MVP Esteemed Contributor

If you can wait a little longer, the Register With Geodatabase tool is being expanded in ArcGIS 10.5.  I don't believe you will be able to manage your own numbering after registering, but you will be able to identify different ObjectID and shape fields.  Also, users will be able to register views with the geodatabase. 

What's new in ArcGIS Server 10.5

Regular Contributor

Does anyone know if the 10.4.1 ArcGIS Desktop will work with SDE (I know it's not called that anymore) 10.5?  We are rolling out Desktop 10.4.1 but we are hating the way views are done in 10.4.1 SDE.  If possible I'd like to skip upgrading SDE and leave it at version 10.2.2 then go straight to 10.5 when it comes out.  I realize that the Desktop rarely is able to work with a newer version of SDE but the loss of SDE views two steps backwards imo.

0 Kudos