I have a raster layer for drive times. I have another raster layer with my bounding geography. I want to tell ArcGIS:

For every cell in geography: if the corresponding cell in drive time is not null: geography cell = drive time else: geography cell = 120

How do you iterate over cells in a raster layer in ArcGIS?

  • Do you have the spatial analyst extension? – jbchurchill Jun 9 '16 at 18:34
  • Yes I have Spatial Analyst. – Steve Scott Jun 9 '16 at 18:36
  • Set extent=what you call geography. Con(is null(dt),120,dt). If geography is not rectangle, clip it using clipping geometry – FelixIP Jun 10 '16 at 4:30

Ok you can use the Raster Calculator for this. For best results you would want to have the same extents and cell sizes of your raster layers. You can set the output to match your other rasters by using a snap raster in the Environment Settings for the tool if that helps. You can use python for this if you need to do it for several pairs of drivetime / geography rasters but unless that is the case you can do it all with spatial analyst.

The Raster Calculator is under Spatial Analyst tools-> Map Algebra (down there at the bottom). The expression will include an "IsNull" to test if the Drivetime is null so the expression should be
Con(IsNull("DRIVETIME"), 120, "DRIVETIME")
as in this screenshot (below).
If you ARE doing this for multiple pairs of rasters in Python you will set a variable using that expression and then save it within a loop.

# this is in a loop
myResult = Con(IsNull(driveTime), 120, driveTime)
myResult.save(outputWorkspace, + "\\" + driveTime)

That is basically saying what you said. If drive time is null, make it 120 and if not use the drive time. However, that is going to give you back the drivetime raster with NoData filled in with a 120 value though so I'm puzzled as to where the "GEOGRAPHY" raster comes into play.

To second guess you a bit, I was thinking you meant if "GEOGRAPHY" is null? to set it to 120? Can you edit your question if that is the case? The way you stated the question, you are editing every value in the "GEOGRAPHY" raster. If that is really what you want, use the Environment settings to use that raster as a mask and snap raster so you only get cells where it has cells.

Raster Calculator location in toolbox

enter image description here

  • Thanks, this was very informative. I was under the impression that map algebra was not intended for use in the python environment but maybe I was mistaken. – Steve Scott Jun 28 '16 at 20:28
  • works for me Steve. – jbchurchill Jul 4 '16 at 15:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.