Fill islands in raster with constant value

2182
5
Jump to solution
09-18-2016 05:55 PM
NealBanerjee
Occasional Contributor

I have a raster that represents water depth which was generated by subtracting a flood elevation raster minus a DEM raster along a river system.  I have cases where there are negative depth values (i.e. DEM is higher than flood elevation), but are completely surrounded by positive depths - thus "islands" in the raster.  I would like to "remove" these islands by replace  the isolated negative depth cells with a constant depth of zero (or other specified constant). 

The challenge that I am have is that I want to keep negative depth values that are not surrounded by positive depth values.  I have many negative depth values along the edge of the raster (i.e. higher ground in the river valley) that I will ultimately replace with no data

Ive seen posts that suggest focal statistics, but I the problem I have with that is that I only want to change negative depth cells that are completely surrounded and I want to specify a constant value for them (rather than a mean or maximum)

Any suggestions would be greatly appreciated

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
NealBanerjee
Occasional Contributor

Thank you Dan, Mody, and Xander for your quick response are helpful suggestions - the RegionGroup tool coupled with a few other processes did the trick.

A summary of the solution was:

  • Run Con function in raster calculator to separate all negative and positive raster value.  Resulting raster has 2 groups with all positive values given value of 1, all negative cells given value of -1. 
  • Run RegionGroup to separate contiguous regions of positive and negative cells.  Resulting raster (in my case) had hundreds of records
  • Use Con function coupled with Lookup function in raster calculator to identify the cells that were either positive in resultant raster in step 2 OR were less than a threshold size (in my case I used about 3 acres), so that any of the islands/holes that are less than the threshold get reassigned a value of 0.  The negative cells on the boundary (which cover much larger contiguous areas) are removed (assigned as no data).
  • Use Max function with original depth raster and result of step 3 to give final depth raster (I havent done this step yet, but expect will work find.

View solution in original post

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

Neal, the first thought that comes to mind is to use RegionGroup to identify the discrete zones that you have and perhaps incorporate that with a search by a threshold area or negative value, then replace those zones with your constant value ...

 Region Group—Help | ArcGIS for Desktop 

Creating individual zones with Region Group—Help | ArcGIS for Desktop 

at least it will get you thinking how to identify the areas simply

ModyBuchbinder
Esri Regular Contributor

Why not creating a constant raster with the same extent (there is a GP tool for that) and use the "con" command to replace some values in raster 1 with raster2?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Mody, that would also change the near shore values as well since they are negative an Neal wants to retain those for now.  From the visual that is provided, the only criteria separating the surrounded negative values from the non-surrounded negative non-shore values is that they are discrete zones of a smaller size, hence, I think separating into zone (aka regions) then filtering by size criteria might work... unless there are other non-conformal zones skulking off-screen

0 Kudos
XanderBakker
Esri Esteemed Contributor

The RegionGroup tool will identify the polygons, but if there are many small polygons it might be quite some work to identify those. You could also go for a vector approach. Convert a raster that contains two values to identify the grey and blue areas to polygons and identify those that are islands. Convert to raster and with the Con statement assign the values you want.

NealBanerjee
Occasional Contributor

Thank you Dan, Mody, and Xander for your quick response are helpful suggestions - the RegionGroup tool coupled with a few other processes did the trick.

A summary of the solution was:

  • Run Con function in raster calculator to separate all negative and positive raster value.  Resulting raster has 2 groups with all positive values given value of 1, all negative cells given value of -1. 
  • Run RegionGroup to separate contiguous regions of positive and negative cells.  Resulting raster (in my case) had hundreds of records
  • Use Con function coupled with Lookup function in raster calculator to identify the cells that were either positive in resultant raster in step 2 OR were less than a threshold size (in my case I used about 3 acres), so that any of the islands/holes that are less than the threshold get reassigned a value of 0.  The negative cells on the boundary (which cover much larger contiguous areas) are removed (assigned as no data).
  • Use Max function with original depth raster and result of step 3 to give final depth raster (I havent done this step yet, but expect will work find.
0 Kudos