|
POST
|
I would prefer not to have the outRaster name as a parameter, but rather would like all the rasters saved as Weight_%Name% and have the output location as a parameter. Does setting the input workspace take care of the location Yes, if you do a raster save without specifying a full path, the current workspace is used. How can I save all the rasters like this automatically? You not only want to save using a generated name, but also have the output appear when the script is run in ArcMap or in ModelBuilder appear as an output to link to further processes. (Just like a regular tool.) This is done using a derived script parameter with the SetParameterAsText method. In the toolbox script tool properties, set the fourth parameter as data type "Raster" and parameter type "Derived". Be careful with your raster naming, grids can only have 13 characters!
import os
arcpy.CheckOutExtension("spatial")
from arcpy.sa import *
wks = arcpy.GetParameterAsText(0) # input workspace
Risk1 = arcpy.GetParameterAsText(1) # input raster layer
Weight1 = arcpy.GetParameterAsText(2) # input raster layer
arcpy.env.workspace = wks
out1 = Raster(Risk1) * Raster(Weight1)
outRaster1 = "Wt_" + os.path.basename(Risk1)
out1.save(outRaster1).
arcpy.SetParameterAsText(3,outRaster1)
... View more
09-20-2012
03:49 PM
|
0
|
0
|
1775
|
|
POST
|
%f seems to force it to understand the points as a string? So I'll need to play around with it a bit more. %f is a Python string substitution code that formats a number into a text representation of floating point numbers.
>>> "%f %f" % (1,2)
'1.000000 2.000000'
Python is moving toward a new method for substituting strings in situations like this. This new method was implemented at 2.4 and future versions of 3.x will stop supporting the old C-style string substitution, so we might as well start using it, especially since the new method is a bit less cryptic.
originCoordinate = "{0} {1}".format(pxy.X,pxy.Y)
... View more
09-20-2012
03:19 PM
|
0
|
0
|
2717
|
|
POST
|
Some positive feedback... I was just messing with with 10.1 background GP and really like how when you double click on the background icon the results window opens up and shows you the current processing there. Some tools simply can't give you a percent because the process doesn't lend itself to estimates - but this is a nice improvement. Would be nice if more tools provided an estimate even if it's an inaccurate one, just so we know it's working. Followers of this thread may want to know that Esri plans to add 64 bit background processing as an optional additional install for Desktop 10.1 SP 1, which will let you run models and scripts in 64 bit. This could be pretty useful, especially for big geospatial data processes that can crash 32-bit geoprocessing because of memory requirements.
... View more
09-20-2012
03:04 PM
|
0
|
0
|
1796
|
|
POST
|
Robert has pretty much covered it, but I just wanted to point out it's not false advertising - the help page you linked to is not for the raster calculator. It's for map algebra in the arcpy Spatial Analyst module. The 10.x functional equilvalent of MOMA is to simply type the statements in the Python window. In some ways this is vastly superior to MOMA because you get integrated intellsense and tool help as you type. In ModelBuilder, you can place multiple Raster Calculator tools in a single model, which is a similar workflow to what MOMA provided in 9.x.
... View more
09-20-2012
02:05 PM
|
0
|
0
|
2019
|
|
POST
|
This is a great example of a case where building a process in modelbuilder and exporting to Python is not the optimal approach. The code you get is just too convoluted and does not take advantage of Python map algebra. The translation may have gone (a little) easier if you had used the Raster Calculator tool instead of many Times tools, but not much. Rather than fix the code, I recommend a rewrite. I'll do it here with just two rasters input and you can expand it from there.
arcpy.CheckOutExtension("spatial")
from arcpy.sa import *
wks = arcpy.GetParameterAsText(0) # input workspace
Risk1 = arcpy.GetParameterAsText(1) # input raster layer
Weight1 = arcpy.GetParameterAsText(2) # input raster layer
outRaster1 = arcpy.GetParameterAsText(3) # output raster
arcpy.env.workspace = wks
out1 = Raster(Risk1) * Raster(Weight1)
out1.save(outRaster1)
... View more
09-20-2012
01:47 PM
|
0
|
0
|
1775
|