Generate a Function for Map Algebra Expression

4693
20
03-11-2016 10:42 AM
PeterWilson
Occasional Contributor III

I've written a Python script that reclassifies a raster using a set of conditional statements into 4 classes:

  • 0 - 12
  • 12 - 24
  • 24 - 30
  • 30 - 60

rec_ras = Con(costmin <= 12, 12, Con((costmin > 12) & (costmin <= 24), 24, Con((costmin > 24) & (costmin <= 30), 30, Con((costmin > 30) & (costmin <= 60), 60))))

I then needed to change the classes into 7 classes:

  • 0 - 5
  • 5 - 10
  • 10 - 15
  • 15 - 20
  • 20 - 25
  • 25 - 30
  • 30 - 60

rec_ras = Con(costmin <= 5, 5, Con((costmin > 5) & (costmin <= 10), 10, Con((costmin > 10) & (costmin <= 15), 15, Con((costmin > 15) & (costmin <= 20), 20, Con((costmin > 20) & (costmin <= 25), 25, Con((costmin > 25) & (costmin <= 30), 30, Con((costmin > 30) & (costmin <= 60), 60)))))))

Is ther a better way of creating a Python function that can create my conditional statement as and if when I need to change the classes before running it. The following is part of  a larger Python Class.

0 Kudos
20 Replies
curtvprice
MVP Esteemed Contributor

It's not a view but a "temporary raster" in arcpy map algebra... out_raster will be written to a real raster as soon as it's needed in a later map algebra expression. Including if you save it with

out_raster.save("outraster.tif")

In ArcMap at the python prompt, however, it gets calculated and written right away to a temp grid in the scratch folder so it can be added to the map (if addOutputsToMap is set).

The dimensions of the output are determined by the currently active environment settings.

0 Kudos