Just trying to do some map algebra, but get extent and cellsize errors.

2171
4
11-01-2011 01:05 PM
PaulHuffman
Occasional Contributor III
I wanted to generate a few flow accumulation grids for alternative pour point inputs.  The docs more map algebra made it seem like it would be simple to do this in the python window.  But I can't get my env set up correctly.  Why isn't easy like: http://forums.arcgis.com/threads/32283-set-extent

I've been trying stuff like:

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "c:/avdata/topsim/utm/accumtest"
env.cellSize = 10
# env.extent = "c:/avdata/topsim/utm/accumtest/accum"
mxd = arcpy.mapping.MapDocument("CURRENT")
env.cellSize = 10
df = arcpy.mapping.ListDataFrames(mxd,mxd.activeView)
env.extent = df[0].extent
accum9M = Con("accum">9000000,1)

but when the line setting the extent to an existing file env.extent = "c:/avdata/topsim/utm/accumtest/accum" was followed by the map algebra line, ArcMap 10, sp3, crashed hard to the "ArcMap has encountered a serious problem" reporting window.  So I tried to set it to the extent of the current dataframe, lines 7,9,10. But only get a "No CellSize and Extent set" run time error.  But when I try to print out the extent, it looks valid, and the cellSize seems to be set to MAXOF.

Tags (2)
0 Kudos
4 Replies
PaulHuffman
Occasional Contributor III
Is there a difference? Both cellSize and Cellsize are in the env. autocomplete. But after setting cellSize = 10,  Cellsize also was found to be set to 10.  But when I tried to run "accum9M = Con("accum">9000000,1)" again, python tried, then I got back to:
0 Kudos
DanPatterson_Retired
MVP Emeritus
What did the error report say?
Also, check your Con statement syntax for your access environment
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z00000005000000.htm
0 Kudos
PaulHuffman
Occasional Contributor III
Now I see in the docs for con that there are two different syntax constructions for con, one with a where clause and one without, but the one without a where clause requires the Raster function. And this is different than in other map algebra environments. I tried the line in python without Raster, and I got ArcMap to crash again. 

if I set the input to a variable name I don't need to enclose it in quotes again:
>>> accum = "accum"
>>> accum9M = Con(Raster(accum) > 9000000, 1, 0)

This ran to completion, creating a new accumulation raster, with values set to 1 for true and 0 for false.

Then I tried it without the false condition:

accum10M = Con(Raster(accum) > 10000000, 1)

This ran, creating a raster with only the data that tested true, the rest nodata.

It was also confusing to me that even though I had set the env.workspace, these new rasters were written to some default directory until I added a save line like
accum9M.save("c:/avdata/topsim/utm/accumtest/accum9M")
0 Kudos