Thursday 26 November 2015

arcgis desktop - Normalizing raster using raster calculator raises TypeError


In ArcGIS 10.1 I'm trying to normalize a section of a DEM (digital elevation model) from original values to values ranging from 0 to 100. First I clipped the raster DEM with an irregulary shaped polygon. Now I'm tying to change all the values to a range of 0 to 100 for further analysis.


I'm using the Raster calculator tool with this equation:


("DEM" - min("DEM")) * 100 / (max("DEM") - min("DEM")) + 0 


I keep getting TypeError: 'Raster' object not iterable. This is the log I get:


   ERROR 000539: Error running expression: rcexec() 
Traceback (most recent call last):
File "", line 1, in
File "", line 5, in rcexec
TypeError: 'Raster' object is not iterable

I also tried running the command on the unclipped raster, unsuccessfully.



Answer



The builtin python min() and max() functions operate only on python iterables (i.e lists, tuples, etc.) and return the smallest/largest item in the iterable. They do not return the minimum/maximum value of a Raster object which is why a TypeError was raised.



You need to use the Raster.minimum and Raster.maximum properties.


For example:


("dem" -"dem".minimum) * 100 / ("dem".maximum - "dem".minimum) + 0 

Note: This will work as long as you have already calculated statistics for the raster, otherwise it will fail as "raster".minimum will return None.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...