Sunday, February 25, 2007

Native Support for Geoprocessor in ArcGIS 9.2...Doh!

OK, so finally re-installed ArcGIS 9.2 after my rash initial installation went awry. Now experiencing first-hand that all of the Python scripts I developed in for ArcGIS 9.0 & 9.1 do not work in ArcGIS 9.2.

Why? As the ESRI documentation states here, "At ArcGIS 9.2, there is native Python support for geoprocessing scripting."

What does this mean in practical terms? Replace the COM connection code at the tippety-top of your scripts.


Replace:
import win32com.client

gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")


With:
import arcgisscripting
gp = arcgisscripting.create()

Now, how to make a single script that will work with either ArcGIS 9.1 or 9.2? I really do not know. The only method that I am aware of to detect the version number is to pull that info from the registry. For me, that is way, way not worth it. Until a nice solution comes along, I will create different scripts for different versions.

While I am discussing Python scripting differences, there is still an unresolved issue (for me) using the searchcursor to access the geometry object for points between 9.0 and 9.1/9.2. Sent a query a while back to the ArcView-L list, but no one was able to help. Which is a shame because the last time I posted a scripting query (about constructing multipart polygons and inner circles) I received a fantastic answer within a couple of days from Nathan Warmer (ESRI).

Anyway, here is a snippet that highlights the difference:

rows = gp.SearchCursor(inputFC)
row = rows.Next()
# For each row
while row:

feat = row.shape
LUArray = feat.GetPart()
# Following line is required for 9.1 & 9.2
pnt = LUArray
# Following 2 lines must be removed for version 9.1 & 9.2 They are essential for 9.0.
# LUArray.Reset()
# pnt = LUArray.Next()
row = rows.Next()
...

I do see that it is no longer necessary to store point features in object arrays, but I have been unable to devise a solution that would work seamlessly across all ArcGIS versions.

Anyway, just thought I would post this difference here while I had it in my mind.

9 comments:

perrygeo said...

To initialize the gp object in a way that will work between versions, you might try something like the following:


try:
import arcgisscripting
gp = arcgisscripting.create()
except:
import win32com.client
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

mapz said...

That is a fantastic idea. Wonderfully simple. I will give it a shot tomorrow and post back here how it worked for me.

Sincerely thanks!

mapz said...

Fantastic. Works like a charm. Thanks again so much.

I just love fixes that can be implemented in under 30 seconds...

mapz said...

Works so well that I updated my ArcMap2GMap script.

Anonymous said...

The difficulties you were experiencing were due to the fact ArcGIS 9.2 does not install PythonWin automatically, which causes your 9.1 scripts to fail. ESRI chose not to install PythonWin as it is not technically required at 9.2 and there are bugs in its install that prevent it from working correctly in some install scenarios. ESRI would not have been able to update the supported version of Python at 9.2 to 2.4.1 if Pythonwon was a part of the ArcGIS installation. Instead, the Pythonwin install exe was distributed on an ArcGIS install DVD and it was left to our users to install it so their existing scripts would work, or make the changes you pointed out so the native ArcGIS python module is used. We regret the confusion and stress this has caused for some of our users and ESRI will continue to improve its support and documented use of Python in future releases. We are glad to see you have found a good workaround to the problem and appreciate you posting your comments about using Python with ArcGIS.

Corey Tucker
ESRI

Anonymous said...

I am running ArcGIS 9.2 and have tried the suggested changes for running your batch viewshed python script. I have not been able to make it work. It works on a machine running 9.0 great, but not on mine even with the changes. Can you suggest any other modification necessary for your batch viewshed script to work?

Mamta Singh said...

pirate kings hack Thanks a lot, that's exactly what i needed. I was looking from a lot of time but could find it. But finally i did.

tunethi said...

vérifiez ce lien ici maintenant répliques de sacs de haute qualité regardez ce que j'ai trouvé Dolabuy Goyard cliquer pour la source https://www .dolabuy.co

bistee said...

official statement b9d75i8b58 replica louis vuitton replica bags in london f5p55e0u86 replica bags koh samui look at this site d4v95k8p03 replica bags london replica bags new york replica hermes a2h82z9q47 replica bags korea