13.9.10

Find Watershed SOE

 The Find Watershed Server Object Extension (SOE) plugs into ArcGIS Server 10 and adds functionality for generating watersheds over REST.  The SOE takes two parameters: hydroshed id and a pour point location.  Proper flow accumulation and flow direction rasters are retrieved by hydroshed id from a file geodatabase.  The location parameter is the pour point.  The goal of the tool is to generate a polygon representing the area of water which flows into a point. 

I like the motto, "if you can't do in on desktop, you won't be able to do it on server."  Keeping this idea in mind, I first wrote the tool as a add-in for ArcMap. This allowed me to debug core business logic for the tool without the complications of the server.

The main difference between a 'desktop tool' and Server Object Extension is the ability to deserialize requests and serialize responses over http.  Since I was new to C# and Server Object Extensions, I first published a sample SOE called SimpleRESTSOE from the samples folder of the ArcGIS 10 install directory. This tool was simply an echo service (i.e. pass a string in, and get the string back).   Requests declare 'text' and 'f' (output format) parameters as part of a url request:

 /echo?text=helloWorld&f=json

and they SOE responds:

{"text":"helloWorld"} 


I got the sample SOE registered with Windows using the command:

RegAsm SimpleRESTSOE.dll /codebase

I then registered the SOE with ArcCatalog and the Server Manager using the companion file located in the samples folder (RegisterSimpleRESTSOE.dll).

Once I verified the sample SOE was running, I simply started modifing the rest schema to take my custom parameters.  To do this, I modified the CreateRestSchema method of the COM class for the tool.  I also added some additional variables to support my business logic:

After modifying the CreateRestSchema method the tool was wired to take the following request:

/echo?hydroshed_id=sa7&location={"x"=-54,"y"=-24}&f=json

I wrapped my business logic in a function and called it from the REST operation's handler EchoInput. THe EchoInput method parses the incoming request, calculates the watershed, and serialize the output.

There is a block of 3 lines towards the bottom that comprise the business logic from my ArcMap tool.  The first two are helper functions (CreateInMemoryWorkspace / CreateFCFromGeometry), and the third is the actual watershed operation:


Global Hydrosheds Lookup

I built a small client application to test Find Watershed over the web. In the app, the user first supplies the location by clicking on the map.  The click location is passes to the server into a query against the lookup map to determine the hydroshed id then :










building a client

1 comment:

  1. Hi BCDCSpatial,
    I have posted a version for 10.1
    http://studioat.maps.arcgis.com/home/item.html?id=7b79eea8286e462bba9b2891b42d223a

    ReplyDelete