raster objects don't seem to work as advertised for map algebra

278
1
11-11-2011 06:23 AM
deleted-user-De598MZ4-kwO
New Contributor

This is my first attempt at converting Python from 9.3 to 10.0, and I'm having problems using the raster objects with map algebra.  I can create a raster object using Raster('pathname'), but any further use of the raster object in map-algebra expressions doesn't seem to work. 

Here is a simplified example, from my Python Idle window.  My typing is in column 1, output is indented.  When the output is 'None", then the expression didn't work properly.  Also, when the output is 'None', if I try to save the raster object using rasobj.save('path'), then I get an error message.

import arcpy
arcpy.SetProduct('ArcInfo')
     u'CheckedOut'
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension('spatial')
     u'CheckedOut'
env.workspace = 'c:/workspace'

InRas = 'slope_deg'
InRasObj = Raster(InRas)
print InRasObj.maximum
     80.2379150391

Deg2Rad = math.pi / 180.
print Deg2Rad
     0.0174532925199

r1 = InRasObj * Deg2Rad
print r1.maximum
     None

r1 = Raster(InRas) * Deg2Rad
print.maximum
    1.40041577816

r2 = Tan(r1)
print r2.maximum
     None

r2 = Tan(InRasObj * Deg2Rad)
print r2.maximum
     None

r2 = Tan(Raster(InRas) * Deg2Rad)
print r2.maximum
     5.81231069565

I can only use map-algebra expressions successfully if I don't use any raster objects to the right of the equals sign. 

I have a lot of 9.3 programs to convert to 10, and I was looking forward to using the simplified map algebra instead of the old SOMA.  It's slow going, so far.

Thanks in advance, Tim.L

Tags (2)
0 Kudos
1 Reply
deleted-user-De598MZ4-kwO
New Contributor
The problem was caused when I ran a block of initialization commands.  The offending command was:

env.mask = 'None'

At version 9.3, setting the mask to 'None' worked fine.  At version 10, there is no error generated, but any work done with raster objects results in empty or unusable output.  At version 10, the appropriate command in a Python script for removing a mask raster seems to be:

env.mask = ''

Of course the mask can be set to an existing raster (or featureclass), but apparently not to a raster object.
This works:    env.mask = 'myRasPath'
This bombs:    env.mask = myRasObj

I didn't find any of this in the documentation, but discovered it through a process of elimination.  ESRI probably could improve their documentation regarding valid/invalid usage for 'None' (such as rasterStatistics), commands that seem to return or print the string 'None', and older commands for which 'None' was an aceeptable argument.

If anyone has compiled a nice list of all the things that work differently between Python geoprocessing scripts at 10 versus 9.3, I'd love to make use of it.

Regards, Tim.L
0 Kudos