Select to view content in your preferred language

How can I use a raster statistic as a variable in the raster calculator?

3045
2
12-11-2015 08:49 AM
DavidBrooks4
Deactivated User

Hi Everyone,

I have a tool who's output is a raster of values ranging from 0 - infinity.

I want to insert the raster calculator into the model and use it to divide each cell by the max value in the raster (contained within the raster's statistics). This would create a normalised raster with values ranging from 0 - 1.

Is there a way of doing this within the model? I don't want to have to manually run this on the model's output each time.

Cheers, David

0 Kudos
2 Replies
DarrenWiens2
MVP Honored Contributor

There are at least a few ways to do this.

Zonal Statistics where zone is the size of the raster in question, with statistic type MAXIMUM, will return the maximum value in the raster.

You could also convert to numpy array and find the maximum value in that array, if you want to incorporate Python.

I wouldn't be surprised if there was function that reads from the raster statistics directly, but a quick search didn't reveal it to me.

edit: the arcpy Raster object does contain a maximum property that you can read directly.

edit 2: Get Raster Properties looks like the tool you're after.

DanPatterson_Retired
MVP Emeritus

Raster out....

RasterToNumPyArray—Help | ArcGIS for Desktop

Do some work...

>>> a = np.arange(1.0,26.0).reshape((5,5))
>>> a
array([[  1.,  2.,  3.,  4.,  5.],
      [  6.,  7.,  8.,  9.,  10.],
      [ 11.,  12.,  13.,  14.,  15.],
      [ 16.,  17.,  18.,  19.,  20.],
      [ 21.,  22.,  23.,  24.,  25.]])
>>> b = a/a.max()
>>> b
array([[ 0.04,  0.08,  0.12,  0.16,  0.2 ],
      [ 0.24,  0.28,  0.32,  0.36,  0.4 ],
      [ 0.44,  0.48,  0.52,  0.56,  0.6 ],
      [ 0.64,  0.68,  0.72,  0.76,  0.8 ],
      [ 0.84,  0.88,  0.92,  0.96,  1.  ]])

Array out and back to ArcMap...

NumPyArrayToRaster—Help | ArcGIS for Desktop

If you intend to do simple operations like you indicated, it is far faster to do it within a few lines of code using arcpy and numpy.  ArcGIS PRO has added access to SciPy, Pandas and a load of other stuff should your needs be analytic and not offered by standard Spatial Analysst tools.

0 Kudos