[GIS] Changing raster cells values inside of a polygon to the closest cells just outside the polygon!

arcgis-desktopnodatapolygonraster

I have been wrestling with this for a while and couldn't find out how I can do this. I want each cell of a raster inside of a polygon boundary to have the value of the closest cell just outside of the polygon.

I think the closest answer was the one at this question, but I couldn't apply it!

My plan was:

  1. Use "Polygon to Raster" to change the polygon to a raster. The cells
    inside the polygon become 1 and the points outside of the
    polygon are nodata.
  2. Use Con(IsNull(Raster),0,NULL) and assign it to Raster2
  3. Add Raster1 and Raster2 to get nodata inside the polygon
  4. It should be easy from here with nodata inside the polygon. We just use "Euclidean Allocation" and it does the job.

I'm stuck at step 2 and get an error:

[SELECT * FROM VAT_Extent_RAS WHERE IsNull( "Value" )] Failed to
execute (Con).

Do you have any thoughts? Is there an easier way to do this?

Update:

I'll try to summarize my progress here. I want to change all raster cells inside the polygon to "nodata" while the raster cells outside of the polygon remain the same. I used polygon to raster function first. This gives me a raster with 0 cell inside the polygon and "nodata" outside of the polygon. What do I do next?

Best Answer

The Euclidean Allocation tool can accept your polygon as input, but you are right you need to set the values inside the polygon to NoData for this tool to work, otherwise it will pick up the values that are already there.

First to feature to polygon, this will give values (any value, it doesn't matter, we're only interested in value or NoData) inside the polygon and NoData outside.

Now do IsNull on the polygon raster, this will give you a raster with 1 outside the polygon and 0 inside the polygon. Hereafter called IsNullRaster. This can be done in a single statement but I want to use it twice so it's worth persisting it to disc.

Con with the IsNullRaster: Con(IsNullRaster,ValueRaster) - now you have a raster that is null inside the polygon and contains values outside the polygon. I'll call this one ValueRasterHole. If this is giving you grief do something like Con(IsNullRaster,ValueRaster,255) and then use Set Raster Properties to enforce 255 as the nodata value.

Set your cell size, extent and snap raster to the ValueRaster and do Euclidean Allocation tool against the ValueRaster with the hole. This one is AllocatedRaster and will have values outside the polygon.

To merge the AllocatedRaster and the ValueRaster together use another Con with the IsNullRaster: Con(IsNullRaster,ValueRaster,AllocatedRaster) will fill in the hole in the polygon with the allocated raster.

Related Question