A blog about life, technology & databases
from ESRI.ArcGIS import Geodatabase
A couple of years ago I tried to use ArcObjects, through IronPython. It didn’t quite work.
Last week I tried again, using the newly released IronPython 2.0. This time it worked better.
create_sde_conn_file.py is based on CreateSDEConnFile.java, from Creating ArcSDE connection files on the fly using Python and ArcObjects on ESRI’s Geoprocessing blog.
For those not already familiar, ArcGIS is by accounts the market leader for Geographic Information System (GIS) software. The core of the suite comprises ArcGIS Desktop, and ArcGIS Server.
On the desktop ArcMap is used to create map documents (.mxd file), whilst ArcCatalog is used to manage data sources. ArcGIS Server can (amongst other things) serve a map document, as a service for web client, Google Earth or remote ArcMap users.
ArcGIS may be automated to an extent, through an interface known as ArcGIS Geoprocessing. But this covers only some cases, delving deeper provides much greater opportunities.
ArcGIS is built on a COM object library named ArcObjects. Native ArcGIS files, such as an ArcSDE connection (.sde file) are the in memory COM object, serialised to disk as binary. It is difficult to edit or create such files in an automated fashion, without calling ArcObjects.
So, like the Java code CreateSDEConnFile.py calls ArcObjects directly. It can produce an ArcSDE connection file, suitable for ArcCatalog. It works by calling the .NET bindings, through Interop assemblies. Anything that can be done through VBA, or C# should be possible through IronPython.
There are a couple of rough edges. ArcObjects is verbose, and IronPython requires some boilerplate to deal with interfaces. Instead of writing
conn_props['SERVER'] = sys.argv[2]
or even
conn_props.SetProperty('SERVER', sys.argv[2])
one needs to write:
esriSystem.IPropertySet.SetProperty(conn_props, 'SERVER', sys.argv[2])
This is explained properly in IronPython bug 1506 and 4538.
To run the script call it as:
"c:Program FilesIronPythonipy.exe" create_sde_conn_file.py
filename.sde hostname 5151 username password SDE.DEFAULT ""
My intention is to take this proof of concept further. To do the same with layer files and map documents. Ultimately to create a build system, able to automatically generate a complete ArcMap document, from textual source files (e.g. json2mxd.py, mxd2xml.py). This would allow proper version control of the source material, and automatic deployment of ArcGIS Server map services.
In the wider scheme, it should be possible to create custom GIS applications with Python, using the full capabilities ArcObjects and ArcGIS.
Updated 29 Jan 2009: Added some context, for those coming to this post from a Python background. Expanded goals.
| Print article | This entry was posted by Alex Willmer on 27 January 2009 at 10:55 pm, and is filed under arcgis. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
Thank you very much for this post. Glad to see late binding in IronPython 2. I’m eager to get started on this myself and am looking forward to your further posts.
about 1 year ago
great post. I’m doing a post grad GIS project and am doing a map image generator off shapefiles in Arc, possibly using Python… and having the full ArcObjects will be a plus. Assuming my client doesn’t decide to use a different platform, I’ll let you know if I get anywhere.
about 1 year ago
I found a couple bugs in the code that needed to be fixed before this ran. I know everyone’s a critic, but I figured you’d want to know.
All bugs are in the statement:
CANDIDATE_LICENSES = [
licence_enum.esriLicenseProductCodeEngine,
licence_enum.esriLicenseProductCodeEngineGeoDB,
licence_enum.esriLicenseProductCodeArcServer,
licence_enum.esriLicenseProductCodeArcView,
licence_enum.esriLicenseProductCodeArcEditor,
licence_enum.esriLicenseProductCodeArcInfo,
]
Here license_enum is misspelled, and is reference before it is defined in a later function. Once more, thanks again. Looking forward to moving some of my ArcObjects-VB6 code over.