Select to view content in your preferred language

Is it possible to configure SA in a Python script?

2381
5
11-26-2010 12:12 PM
CedricWannaz
Emerging Contributor

Dear all,

    I have to perform map algebra operations on rasters that have different extents, and I want to obtain an output on the union of the extents. I am doing this in a Python script; is there a way to configure Spatial Analyst output extent to "Union of Inputs" by calling a geoprocessor method from my script?

Thank you and best regards,

Cedric


ArcGIS Desktop 9.3.1, ArcInfo license.

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus
Cedric
I haven't had much time to explore all the intricacies of arcpy but you could begin by exploring sa
>>> from arcpy import sa
>>> help(sa.Extent)
provides some clues, if you know the extent that you need, then you can set it
0 Kudos
CedricWannaz
Emerging Contributor
Dan,

    Thank you for your answer. Do you know how to do it with the 9.3.1 geoprocessor? I don't have ArcGIS 10 yet, and I am not sure how to access spatial analyst (dedicated-) properties when using the arcgisscripting pyd.

Thank you!

Cedric
0 Kudos
DanPatterson_Retired
MVP Emeritus
Sorry Cedric, don't have a 9.3.x installation here, acrpy does open up a whole new world which didn't exist in previous versions.
0 Kudos
RyanDeBruyn
Esri Contributor

You may need to review the environement settings for extent.

http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=2237&pid=2229&topicname=Output_extent

also for Map Algebra in 9.3
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=6311&pid=6308&topicname=Single_Output_Map_Alg...

for example:

gp = arcgisscripting.create(9.3)
gp.workspace = "C:/workspace"
gp.Extent = "MAXOF"
inExpresson = "C:\data\rasterA + C:\data\rasterB"
gp.SingleOutPutMapalgebra_sa(inExpression,"outRaster")

Good luck
Ryan

0 Kudos
curtvprice
MVP Esteemed Contributor

Here's the 10.x flavor of this:

import arcpy
from arcpy.sa import *
arcpy.env.workspace = r"C:\Workspace"
arcpy.env.extent = "MAXOF"
outRaster =  Raster(r"C:\data\rasterA") + Raster(r"C:\data\rasterB" )
outRaster.save("outRaster")

Output Extent (Environment setting)—Help | ArcGIS for Desktop

0 Kudos