Thursday, May 8, 2014

ArcGIS 10.1 - Geoprocessing Quirks and Solutions

Well, this one stumped me for a good week, so I figured time to return to the blog!


At long last, my colleagues at the City all upgraded to ArcGIS 10.1 SP1.  So I figured it was high time I follow suit.


Unbeknownst to me at the time, the 10.1 upgrade apparently did some small tweaks to the geoprocessor's background processing.  As a result, certain tools no longer worked when run synchronously - most notably for me, the Dissolve and Erase tools.  I had to call ESRI support before we figured out this one - see my StackExchange post on the subject.  Long story short, this was a known bug (presumably fixed at 10.2, which we won't be upgrading to for a LOOOONG time), and the support technician suggested running the tools Asynchronously rather than synchronously - and poof! problem solved.  Kind of.


So I went about my merry way completely and totally restructuring my code to support the asynchronous calls to the geoprocessor.  I did the minimal restructuring, creating the geoprocessing tools as I went along.  When I finally finished this rather monumental task, I discovered that I could no longer establish a schema lock on my feature classes, and once I just did away with the schema locks, that I could no longer call insert and update cursors, and finally once I switched those to select cursors, that I could no longer create a feature on a new feature class.  It was this last one that presented no workarounds that I could find and finally broke me down into a full day of testing and attempting to isolate the cause of my woes.


After extensive testing, it appears that my nemesis the Dissolve tool was somewhat to blame.  I'm still not sure entirely why...but if the Dissolve tool ran, all the processes I just listed would not.  If I used an existing file and did not run Dissolve, all the processes would run just fine.
After hours and hours of experimentation and googling, I finally ran across this one ever-so-important comment in the code listing here


To run multiple GP tools asynchronously, all tool inputs must exist before ExecuteAsync is called.




As I mentioned before, I was just creating the tools as I needed them as the code progressed.  I had read this line so many times and it didn't trigger anything in my brain...but finally, after everything else had been exhausted, I paid attention.  I moved all my tool declarations (Clip, Dissolve, and Intersect) to my main method and set them up immediately after I declared the geoprocessor.  As I created them, I stored them in a Queue as suggested by the code sample.  Then to run the tools, I called the geoprocessor with the dequeued processes as I needed them.


Poof!  Problem solved.  I was able to re-enable my schema locks, insert cursors, update cursors, and ... most importantly... my feature creation. 


And the moral of the story is....read all the comments in ESRI's code samples, no matter how minor... 



No comments:

Post a Comment