1

I am trying to clip a raster with a polygon. The raster has a very coarse resolution of 10m (and must remain with that). I would like to keep only the raster cells that are fully within the polygon (see image "yes"), I would like to discard everything that is even slightly over the border of the polygon (see image "no")

I have tried using the clipping feature and the extract by mask process provided by ArcGIS, but I have not found any option to use "fully contain" or "completly within" or something.enter image description here

I hope it's possible with Arc GIS!

1
  • Are you using ArcGIS Pro or ArcMap to try and do this?
    – PolyGeo
    Jun 13, 2023 at 9:55

2 Answers 2

2

I think the issue here is that your polygons are captured using a different technique (e.g. manually captured) and scale so they don't align with the raster cells.

Here is a simple model that will guarantee the selected pixels are fully within the polygon boundary. But because the polygon does not follow the raster cell alignment this approach can miss pixels that are fully within the boundary, so if you don't mind losing a few then this approach works well.

You convert the polygon to a raster, shrink it by 1 pixel then use this to mask out the raster

Model

Input data is raster and polygon boundary:

Inputs

Result of model is:

Result

Here is a zoomed in example of where pixels can be missed, the result of extract by mask is displayed as green pixels on top of the original raster, but all green pixels are fully within the polygon. Note some grey pixels which are fully within the polygon are not green.

Missed pixels

The model could easily be wrapped up with an iterator to step through many polygons.

If this is not sufficient I think you'll need to convert the data into vector and intersect the data, drop out anything that is not fully within the polygon and then use that to mask out the data. This would be a slower approach due to the conversion of data but quite achievable.

0

This can be done after masking out conflicting cells at boundaries of polygons. So set sell size and snap raster to original raster and:

PolygonToLine_management("POLYGONS", "in_memory/lines")
PolylineToRaster_conversion("lines", "OBJECTID", "TWO", cell_assignment="MAXIMUM_LENGTH")
RasterToPoint_conversion(in_raster="TWO", out_point_features="in_memory/pts", raster_field="Value")
PointToRaster_conversion(in_features="pts", value_field="pointid", out_rasterdataset="ONE")
RasterToPolygon_conversion(in_raster="ONE", out_polygon_features="in_memory/R2P", simplify="NO_SIMPLIFY")
Intersect_analysis(in_features="R2P #;POLYGONS #", out_feature_class="in_memory/isect", join_attributes="ONLY_FID")

Output of above:

enter image description here

Compute frequency of highlighted field and transfer it to table of small square polygons: enter image description here

Pink polygons are to be converted to raster and cells underneath erased from original raster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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