I have a Map Algebra formula that works perfectly in the old Spatial Analyst Raster Calculator in 9.3.1 that has a Python error (Python syntax error: Parsing error : invalid syntax) in 10.0 Not sure if the syntax needs revision or what. I also have multiple rasters being created by the script and wasn't sure how the changes in the new Raster Calculator would handle them. Here is a sample of the formula:
😞 I've read about why the changes to Raster Calculator were applied to 10.0 which I found troubling (especially when it was stated that most of the user community has accepted and has adapted to the new Raster Calculator). I work in a multi-agency federal government environment with several hundred users and we definitely have not adapted!! This leads me to the fact that this decision was not thought out well and did not have a majority of users in support! :confused:
I still get a "Pythox syntax error: Parsing error" message.
What I'm trying to do is find the grid cell values that occupy the same location in 2 raster data layers ("caca3fm40" and "caca2fmc") that match the stated criteria and then perform an Abosolute math process on them (subtraction) and then save the results in a raster named "nbgrs". Thanks again! Best regards, - Craig
The Raster Calculator geoprocessing tool in ArcGIS 10 is indeed not the same as the Raster Calculator toolbar tool in ArcGIs 9.x. A more detailed explanation is avaialable in the Raster Calculator tool help as well as a blog post introducing the New Raster Calculator tool. Aside from that, a couple of key points to get you started here are:
1) The Map Algebra in the new Raster Calculator tool uses Python, whereas the syntax of the old Raster Calculator was based off of Workstation Grid commands.) 2) In the new Raster Calculator tool, you specify the expression and the output raster seperately in the dialog (in a way, similar to the old Single Output Map Algebra tool), whereas for the the old Raster Calculator, the expression and output were specified in a single line.
Some things to know about Python:
1) Python is case sensitive. Each tool name must always start with a capital letter, with other letters of the tool name cased appropriately. For example, type Con, not con; And, not and; SetNull not setnull, etcetera. 2) Strings, such as dataset names, must be in quotes (for example, "caca2fm40", or 'caca2fm40'). 3) The And operator in Python performs a Bitwise And, not a Boolean And. When working with rasters in an expression, use the & operator instead. 4) When using multiple boolean and relational operations in a row in an expression, parentheses must be used to indicate the order of operation. For example, type ("caca2fm40" > 100) & ("caca2fmc" < 120) instead of "caca2fm40" > 100 & "caca2fmc" < 120.
Taking one of the formulas in your post as an example:
Another solution is to write a small Python script, which I have attached. Just add your layers to the table of contents, right click in the Python Window and load the script, then press enter (modify the output path if necessary, currently the output path is set to C:/temp).
The only thing that I can think of that is on the plus side is that they seem to be sticking with Python, which...according to Guido...won't change significantly for at least 3 years...and we aren't even ported to 2.7 yet and the up-porting to 3.x Python isn't too onerous. My feeling is, the language-de-jour days are getting a bit stale. Since the GIS community didn't stick with Fortran ( 🙂 ) at least open source languages offer a salvation for code-porting....and Python seems to be it.