Introduction Video I made for Penn State's MGIS Program
Over the past weeks, I have written several server-side tools to support web mapping applications as part of my capstone project for Penn State's MGIS Program. The following is a general overview of what I've found to be the strengths and weaknesses of Geoprocessing Services in Python and Server Object Extensions in C#.
Over the coming weeks, I will be releasing the code and discussions of the individual tools in separate posts.
Geoprocessing Services (Python)
For developers of web-based geoprocessing tools for ArcGIS Server 10, the arcpy Python library is now a popular alternative to the more complex ArcObjects library. With arcpy, you can access a decent percent of the ArcGIS tools with a clear syntax for linking them together. Knowledge of object-oriented programming is not required, and you can integrate GIS with an entire world of Python third-party libraries. To web-enable arcpy, scripts are added to toolboxes which get published to the server.
- Accelerated development time
- ArcGIS includes many Python code samples
- Easy to debug business logic
In spite of their ease of development and clear syntax, aspects of python geoprocessing services limit their power. First is that they execute slower that the equivalent code written in .NET ArcObjects. For desktop tools that may not be a problem, but for the web this can negatively impacts user experience.
Even if speed was not an issue, geoprocessing services are more cumbersome to move from one environment to another (e.g. staging -> production) because access to required source data is more tightly coupled with the tool. Take the example of a server-side point clusterer. To access the point feature class containing un-clustered points, a python script may use either of the following logic:
This first example uses a hard-coded absolute path that will need to be changed if the tool moves to an environment with a different directory structure. A better choice would be the relative path example, but there is still hard-coding of the dataset's geodatabase and name. With either choice, the tool suffers from a lack of true encapsulation which ends up making it harder to move and reuse on other point layers.
An aspect of the ArcGIS workflow for creating scripting tools which hinders a tool's flexibility is the need for explicit registration of input and output parameters in a properties dialog.
- Slower execution speed when compared to C#
- Tighter coupling with source data
- Double managing of service input/output parameters
C# Server Object Extensions (ArcObjects 10 .NET SDK)
- Faster code execution
- Loose coupling with tool source data
- Easy to deploy across environments
The idea of the Server Object Extension is that instead of publishing a service on top of the server, you extend the server itself. This extended functionality can then be enabled for any service along with other out-of-the-box capabilities (e.g. Export Map, Identify, Find, Query, Generate KML, WMS).
The beautiful thing about Server Object Extensions is that ArcObjects has hooks into the source data within a map service. These hooks give C# access to datasets using map service layer indexes instead of directory paths allowing for looser coupling with the server environment. ESRI Web APIs also use map service layer indexes which makes client-server communication easier.
- Large and complex library
- Not Cross-Platform (won't run on AGS Java version).
- Steeper learning curve
An example of this would be getting a geometry object, passed in as JSON from the client, into a feature class which can be used by a Spatial Analyst tool. The solution I used took 80 lines of not fun code to write. The image below is meant to give an impression of the complexity.
Another area of trouble is .NET and inability to run outside of a Window's environment. Being that ESRI offer's a Java version of the ArcGIS Server, choosing C# means limiting a tool to Window's and the .NET version of ArcGIS Server. This hasn't been a major issue for me yet, but I want as many options in hosting environments as possible.
Overall I have found the benefits of Server Object Extensions outweigh the ease of development offered by Python when performance and reusablilty are important. Initially, I found the complexity of working in ArcObjects discouraging, but slowly I wrote function to deal this data type conversions and development got easier. I now consider arcpy as a solution only on the desktop.