Wednesday, June 10, 2009

Using SDE commands through python

I have a problem, and it has to do with SDE. The ArcToolbox Make Table View does not make a permanent table. For this I need to use the SDE commands that come with ArcSDE.

sdetable -o create_view -T view_name -t table1,table2...tablen
-c table_col1,table_col2...table_coln
[-a view_col1,view_col2...view_coln] [-w "where_clause"]
[-i service] [-s server_name] [-D database]
-u db_user_name [-p db_user_password] [-N] [-q]

The command abode will allow a person to create a temporary or permanent table view within the SDE database. In ArcCatalog, you can see the view as a table, which makes it helpful to query. To make this command work in python, you need to create a script that will call the sdetable.exe file and pass in all the parameters.

The general concept of this is quite simple:

# Run the command
stdout_handle = os.popen(commandStr, "r")
# Read the commands output into a variable from the standard output handle
text =

Here you use the os.popoen(<.exe file>, "r") which returns acknowledgement message once the script completes sucessfully or not.