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.

import win32com.client

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

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.


Matthew said...

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

import arcgisscripting
gp = arcgisscripting.create()
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.

Corey Tucker 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

Mercedes Verastegui 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. said...

kate spade
tory burch handbags
ray bans
christian louboutin outlet
tiffany outlet
ray ban sunglasses
pandora jewelry
polo ralph shirts
jordan 3
longchamp handbags
gucci outlet
michael kors purses
adidas trainers
air jordan retro
louis vuitton outlet
louis vuitton outlet online
coach outlet store online
toms shoes
adidas nmd
mont blanc pens
coach outlet store online clearances
ralph lauren outlet
coach outlet store online
michael kors uk
nike air jordan
ray ban sunglasses
jordan 13
louis vuitton outlet
cheap oakleys
michael kors outlet online sale
ray-ban sunglasses
jordan retro 3
michael kors outlet clearance
oakley sunglasses wholesale
hermes birkin bag
jordan 8
louis vuitton outlet
cheap oakley sunglasses
rolex watches
coach factory outlet