Environment settings ignored when set through Python?

767
3
06-03-2012 05:19 AM
MarcoBoeringa
MVP Regular Contributor
Hi all,

I am trying to set some environment settings through Python. When I look in Debug mode in the PyScripter IDE at all environment variables (launched from ArcMap by right clicking the script and choosing "Debug"), I see my Extent and Mask setting correctly being applied to the GPEnvironment "env" object, the correct coordinates and path to the mask file are visible.

However, when I look at the final result of a Spatial Analyst "Con" conditional operation, the resulting raster doesn't honor the Mask set for the environment in the script in which the Con command is used. According to the Desktop Help, the Con command should honor the Mask setting... In addition, the extent, when viewed in PyScripter debugging mode, of the resulting raster, is incorrect too. The extent is the extent of the original raster, not the extent set dynamically in the Python code of the script.

Any clues as to why this is happening?

ArcGIS 10 SP4 by the way.

Marco
Tags (2)
0 Kudos
3 Replies
MarcoBoeringa
MVP Regular Contributor
I don't know if it has anything to do with it, but I now noticed that only when I specifically write the mask file to disk, it is properly used as a Mask environment setting. I had been using the "in_memory" option for storing the polygon representing the mask instead of physically writing it to disk. Maybe there is an undocumented limitation with using "in_memory" datasets as environment settings for analysis, and you can't use them for that directly...? Anyone else experience this issue?
0 Kudos
MathewCoyle
Frequent Contributor
Some geoprocessing tools cannot take in_memory datasets as inputs/outputs.
0 Kudos
MarcoBoeringa
MVP Regular Contributor
Some geoprocessing tools cannot take in_memory datasets as inputs/outputs.


Yes, I was aware of that possibility. However, I still can not get the Con (conditional) tool of Spatial Analyst to accept the set extent on the "env" environment object, despite it being listed among the accepted "Environments" in the ArcGIS Desktop 10 Help. I clearly see it being set while debugging, as the correct extent with correct XMin, YMin, XMax, YMax is visible in PyScripter, but as soon as I use the Con tool in the script, the output is using the input raster extent instead of the set extent of the environment settings. The mask setting is properly used as long as the dataset is physically written to disk, as I wrote before.
0 Kudos