Select to view content in your preferred language

Manipulating raster values in ESRI GRID files with ArcPy

222
2
Jump to solution
04-04-2025 12:23 PM
beachcomber_0972
Emerging Contributor

Hi GISers,

I have an interpolated raster product stored in ESRI GRID format. The interpolation technique left some residual values below zero, but for the product in question (estimated abundance data) those values do not make sense. I want to convert them to zero.

There are a bit fewer than 100 rasters to process, so this needs to be done via ArcPy. I've found some hints on how to achieve this in the GUI, but haven't been able to turn up much on how to do it via scripting.

My sense is that this will be an easy layup for anyone who knows the syntax. If anyone has any thoughts, I'd be much obliged.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
beachcomber_0972
Emerging Contributor

Thanks for the info.

For anybody curious, the simplest solution that I came up with was to just use the spatial analyst raster iterator. This was actually trivially simple:

for a,b in Myraster:
     if Myraster[a,b]<0:
            Myraster[a,b] = 0

Myraster.save()

View solution in original post

0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

You probably want to batch the Con tool.

Con (Spatial Analyst)—ArcGIS Pro | Documentation

There are basic examples there.  I might suggest putting the output into a folder and rather than an esri grid, specify a *.tif file extension to get tif rasters


... sort of retired...
0 Kudos
beachcomber_0972
Emerging Contributor

Thanks for the info.

For anybody curious, the simplest solution that I came up with was to just use the spatial analyst raster iterator. This was actually trivially simple:

for a,b in Myraster:
     if Myraster[a,b]<0:
            Myraster[a,b] = 0

Myraster.save()

0 Kudos