|
POST
|
Thank you. BTW; is there a way (perhaps a setting) that will force the output raster name to be the one used in the command? At this moment I have to follow each command with myRaster.save("myRaster") to force it to have a name I want it to have. See also thread: http://forums.arcgis.com/threads/42427-Define-the-output-name-of-a-raster-using-SA-and-Python see my reply to the respective thread. -R
... View more
11-04-2011
08:50 AM
|
0
|
0
|
1683
|
|
POST
|
Xander, thank you for you post. One of the key features of the scripting with the arcpy SA module in 10.x is the use of the mapalgebra syntax and the ability to more efficiently execute tools in a workflow. Scripting gives you the oportunity to combine many tools or workflows together and when you have the final result you persist it and share it. All the intermediate data may or may not be needed and can be managed accordingly. In my opinion, this is a similar concept to stringing together multiple tools in a geoprocessing model builder. Running Spatial Analyst tools in python, you may have noticed that you no longer need to specify an output name for Spatial analyst tools (there is no out parameter in scripting). This is one of the major differences in 10.x from 9.x In its most basic form, an output raster is specified to the left of an equal sign (=), and the tools, operators, and their parameters are on the right. For example: from arcpy.sa import * outShade = Hillshade("inelevation", 99, 33) The primary raster output (outShade) of the Spatial Analyst Map Algebra expression is a Raster object. One of the most important behaviors of a Raster object is that when it is created from a Map Algebra expression, it references a temporary raster (with a default name). Temporary data, unless it is explicitly saved, may be removed when the ArcGIS session or script ends. There are also a number or raster properties you can access directly from the raster object without describing the data. The data you are refering to that contains the function_ name is the temporary raster. You will need to persist the data using the .save() method otherwise it may be removed when the ArcGIS Desktop application ends (if document is not saved) or when the script is completed. Working with the python window in ArcMap it is integrated so your result are added to the display with the name of the "raster object" you specified. The save is still required if your want to persist your data with a defined name. If you are running single expression in the python window and simple want the data to be named and persisted one suggestion is to execute the GP tool directly rather than the two step process required in the python window. I hope this helps you understand the concepts a bit better and will allow you work with this in mind. There are many tools for the job and they all have their own way to help you more quickly and effiently complete your work. For example we can give you a hammer and screw, but it may be better to use a screwdriver. 🙂 We (at esri) need to work toward helping and teaching these concepts, so your input is well appreciated. Please have a look at some of the documention to help better explain this. And feel free to dive in. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/A_quick_tour_of_using_Map_Algebra/00p600000003000000/ http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Managing_output_from_Spatial_Analyst_tools_in_Map_Algebra/00p60000001t000000/ http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v000000wt000000 Regards, -Ryan
... View more
11-04-2011
08:46 AM
|
0
|
0
|
975
|
|
POST
|
xander: The environment settings (in the GP dialog) seem to be messing up the python window. Please make sure these geoprocessing environments set in the application (dialog) are pointing to a correct and exisiting location. Is your map document saved with relative paths? Please let me know if yes? We have had cases where geoprocessing environment workspaces get altered when opening an exsiting MXD document that has relative paths. This may be your cause. If so, to remedy, set the workspaces (or clear to default) and change the document to not contain relative paths and save the mxd again. We are investigating this. Please note you can use the function arcpy.ResetEnvironments() in the python window to reset to the application settings (what is set in the geoprocessing environment dialog). Once you change an environment in the python window it should persits for that session or until you reset. You may have different environments for the python window and the GP tools, so be aware. Use the ResetEnvironments() to synch back with the application. By default the output raster in your map algerbra expression will be created in the scratch workspace. If the environment dialog shows an incorrect path the GP tool will too. Hope this helps. If you have a clear reproducible case please let me know. Thank you, -Ryan
... View more
11-03-2011
10:53 AM
|
1
|
0
|
1683
|
|
POST
|
Julian, Diffuse and direct do affect each other. However, Solar Analyst doesn�??t account for that automatically, instead, relys on the parameters. You increased the diffuse proportion parameter (which affects diffuse), however you should decrease the transmittivity parameter (which affects direct). The parameters are defined int he help as follows. diffuse_proportion: The proportion of global normal radiation flux that is diffuse. Values range from 0 to 1. This value should be set according to atmospheric conditions. The default value is 0.3 for generally clear sky conditions. Transmittivity: The fraction of radiation that passes through the atmosphere (averaged over all wavelengths). Values range from 0 (no transmission) to 1 (all transmission). The default is 0.5 for a generally clear sky. Hope this helps. Regards, -Ryan
... View more
10-19-2011
10:12 AM
|
0
|
0
|
948
|
|
POST
|
Please note, it is not a bug in SP1 or SP2, it was an issue in 10.0. Some spatial analysis tools require valid statistics for analyis. Statisitcs are invalid according to these rules. Have not been calculated Contain a skip factor greater than 1 Contain an ignore value In 10.0 statistics where being built on the fly which was not ideal because we do not want to modify user input in any way, so instead we opt to return an error. That is why it fails in 10 SP1, 10 SP2 with the error message. The solution is to use Calculate Statistics so if that didn�??t work may need to find out why. Try using the Calculate Statisitcs geoprocessing tool, or Copy Raster (specify Raster Analysis environment setting to build statistics). Optionally, output to GRID will force valid statistics. Other formats such as TIF, IMG, FGDB may have invalid statistics. In 10.0 service pack 3, changes are planned to avoid the error and, if required, calculate statistics in memory (if they do not exist or are invalid). This way we do not alter any data and the tools should run successfully. Please verify that the Calculate Statisitcs operation is working correctly. Good luck with your workflow. I appologize for any confusion. Sincerley, Ryan DeBruyn
... View more
07-25-2011
01:26 PM
|
0
|
0
|
2913
|
|
POST
|
Dear All, Is there anyone with experience in the Area Solar radiation tool of the Spatial Analyst? I was getting some seriously unreliable results so I run a simple analysis using a flat DEM and then compared these with average values based on measurements. I have included a word file explaining the problem, along with the flat DEM (please use the latitude shown on the word file if you re-run the analysis to check results I provide). I am running the analysis for two days, one typical for winter (16/2) and one for summer (11/6). I also use complete transmission and totally clear sky conditions to compute a value that can be compared to the Extraterrestrial/exo-atmospheric irradiance on horizontal. The results for the Global, Beam and Diffuse irradiances are entirely inaccurate (as an indication, the annual results underestimated the Global horizontal irradiance by 75%) and I would appreciate any help on this. Keep in mind that I am new in GIS, so please excuse me if I have done something really stupid:). I am also confused with the name of the tool, what is the difference between the Area Solar Radiation Tool and the Solar Analyst or TopoView that I usually come across in the literature? Thank you in advance, Kind Regards Eleni Please note, the Solar Radiation tools available in ArcGIS are built upon the Solar Analyst/ Topoview extension so essentially they should produce similar results. Some enhancements and bug fixes were done at this time. The results in question may be related to the settings you are using when running the tool. For single day analyisis you can try increasing the skysize to 400 (max 1000). As well there is an option to specify FLAT surface for surface paramaters rather than calculated aspect and slope from the input DEM. If you are still having quesitons or problems I would recommend contacting esri support to work with a support analyst to identify any issues and provide further input to the developement team. Perhaps the help topic for calculating the incoming radiation might be of some help. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/How_solar_radiation_is_calculated/009z000000tm000000 Regards, -Ryan
... View more
06-20-2011
11:56 AM
|
0
|
0
|
868
|
|
POST
|
Sami and Micheline, glad this worked out for you. I just want to make note of the importance of the Raster object in this case. All Spatial Analyst tools/functions return a raster object as a result. You can use this raster (variable) as input to another tool or query its properties for use. This is what I did in my initial example for Magnus from the Con(), and Sami found the error in the syntax (my mistake as out1 is already a raster object and didn't need to cast it). Micheline, in your example you are setting a variable "out1 = raster" to the name (string) of the raster in the list. This then is being cast as a raster object in the sum logic. If you need a raster object you can cast one by using the Raster() method, this is required in some cases and here it is neccesary to intialize the first raster in the list so we can sum the Rasters together using the '+' operator in a map algebra expression. I have modified the code a bit, to cast the raster directly instead of creating the extra variable. Perhaps this will help you in your future workflows.
import arcpy
import os
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = r"c:\temp\scratch.gdb"
arcpy.env.workspace = r"c:\temp\work.gdb"
#create a list of rasters in the workspace
rasters = arcpy.ListRasters("*", "GRID")
i = 0
#loop through rasters in list
for raster in rasters:
print ("processing raster: %s" %os.path.join("datapath",raster))
#sum rasters together
if i == 0:
outSUM = arcpy.Raster(raster)
i += 1
else:
outSUM = outSUM + raster
i += 1
#save final output to the current workspace
outSUM.save('sumRas') Good luck -R
... View more
05-19-2011
03:45 PM
|
0
|
0
|
1477
|
|
POST
|
Please note: The help for the RasterCalculater in 10.0 states: The Raster Calculator tool is intended for use in the ArcGIS Desktop application only as a GP tool dialog box or in ModelBuilder. It is not intended for use in scripting and is not available in the ArcPy Spatial Analyst module. The Raster Calculator is not supported in scripting because in ArcGIS 10 Map Algebra can be accessed directly when using the geoprocessing ArcPy site-package. This seamless integration of Map Algebra into Python extends the capabilities of Map Algebra by taking advantage of Python and third party Python modules and libraries; making Map Algebra far more powerful than it has been in the past. Reference: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z000000z7000000.htm http://blogs.esri.com/dev/blogs/geoprocessing/archive/2010/04/28/the-new-and-improved-raster-calculator-tool-for-arcgis-10.aspx The solution to your problem: 1) You will need to checkout the Spatial Analyst License to use operators or any Spatial Aanlayst tools with rasters. arcpy.CheckOutExtension('Spatial') To obtain your average use one of the following. A) outras = (a1+a2+a3+a4)/4
outras.save("averaster') or B) outras = arpcy.sa.CellStatisitics([a1,a2,a3,a4], "MEAN")
outras.save("averaster") Good luck, -Ryan
... View more
04-12-2011
01:27 PM
|
0
|
0
|
1397
|
|
POST
|
Hi Magnus, here is abit of code that could help get you started. I didn't test it but give it a try (see attached file). good luck -Ryan arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = outPath
arcpy.env.workspace = dataPath
#create a list of rasters in the workspace
rasters = arcpy.ListRasters('','')
i = 0
#loop through rasters in list
for raster in rasters:
print "processing raster: %s" %os.path.join(dataPath,raster)
#convert nodata to zero
out1 = Con(IsNull(raster), 0, raster)
#sum rasters together
if i == 0:
out2 = arcpy.Raster(out1)
i += 1
else:
out2 = out2 + out1
i += 1
#save final output
out.save(os.path.join(outPath,'sumRas'))
... View more
04-11-2011
10:18 PM
|
0
|
2
|
2978
|
|
POST
|
Hi Magnus, here is abit of code that could help get you started. I didn't test it but give it a try (see attached file). good luck -Ryan arcpy.env.overwriteOutput = 1 arcpy.CheckOutExtension('Spatial') arcpy.env.scratchWorkspace = outPath arcpy.env.workspace = dataPath #create a list of rasters in the workspace rasters = arcpy.ListRasters('','') i = 0 #loop through rasters in list for raster in rasters: print "processing raster: %s" %os.path.join(dataPath,raster) #convert nodata to zero out1 = Con(IsNull(raster), 0, raster) #sum rasters together if i == 0: out2 = arcpy.Raster(out1) i += 1 else: out2 = out2 + out1 i += 1 #save final output out.save(os.path.join(outPath,'sumRas'))
... View more
04-11-2011
10:15 PM
|
0
|
0
|
2978
|
|
POST
|
Magnus, What version are you using? In model builder you can create variables which will iterate through rasters in a workspace which would help you automate the process for Con(). Also using a python script would provide you with an easy way to create a loop through rasters in a workspace do the Con() and sum the rasters together as you go. If you have version 10 this is even easier to do and will only result in your final output being created not 1000's of itermediate rasters. -R
... View more
04-08-2011
10:58 AM
|
0
|
0
|
2978
|
|
POST
|
Thank you to all for your interest in this issue. So currently the complex map algebra expression, out = Raster("myraster) + Cos(0) requires a cellsize and extent to be set because the Spatial Analyst function arcpy.sa.Cos() requires it when using a scalar input. Using this or any other local function in your map algebra expression would have this requirement because the function result is a raster not a scalar. Mr. Huber and Mr. Patterson are correct in there interpretation of the problem and provided a good explaination as to why. With that said, this expression should "just work", as it did work in workstation, and I think all share the same frustration. We acknowledge this is a defect and are currently working on the solution for supporting scalar values in Spatial Analyst local functions when used in a complex expression. Workarounds for ArcGIS 10.0 (service pack 1) set cellsize and extent environment if using Spatial Analyst arcpy.sa.Cos(0) use the python math.cos(0) to return scalar (note the python uses lowercase for cos() function) Thank you again for you time and consideration. -Ryan DeBruyn ESRI - Spatial Analyst
... View more
03-17-2011
10:57 AM
|
0
|
0
|
2641
|
|
POST
|
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_Algebra 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
... View more
12-01-2010
11:54 AM
|
1
|
1
|
1235
|
|
POST
|
HI Wentao There seems to be an issue with the name of the temporary raster that is created by the tool. By default you must have a file based scratch workspace set so the format is attempting to create a grid stack(limit 9 characters). Try to set a file geodatabase as your scratch workspace there will not be a name restriction. arcpy.env.scratchWorkspace = "c:/data/myfilegdb.gdb" out = arcpy.sa.ExtractByMask(tif, shp) out.save("C:/output/final_ras") Thank you for your input, we will work to remedy the error. -Ryan ESRI Spatial Analyst Team
... View more
04-20-2010
04:17 PM
|
0
|
0
|
1199
|
|
POST
|
RasterToNumpyArray and NumpyArrayToRaster functions are are available in arcpy in 9.4 beta2. Be aware there are some known issues but in general they are working. Here is a basic syntax RasterToNumPyArray (in_raster, {lower_left_corner}, {ncols}, {nrows}, {nodata_to_value}) NumPyArrayToRaster (in_array, {lower_left_corner}, {x_cell_size}, {y_cell_size}, {value_to_nodata}) link to beta web help: http://helpdev.esri.com/EN/ArcGISDesktop/9.4/Help/index.html#/NumPyArrayToRaster/000V00000130000000/ http://helpdev.esri.com/EN/ArcGISDesktop/9.4/Help/index.html#/RasterToNumPyArray/000V0000012Z000000/ -Ryan
... View more
01-27-2010
07:52 AM
|
0
|
0
|
1695
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-20-2025 07:16 AM | |
| 1 | 06-04-2024 08:14 AM | |
| 1 | 12-01-2010 11:54 AM | |
| 1 | 08-29-2023 07:17 AM | |
| 1 | 08-29-2023 06:04 AM |
| Online Status |
Offline
|
| Date Last Visited |
10-21-2025
10:45 AM
|