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
    Welcome to GIS SE. As a new user, please take the Tour. While it might seem reasonable to mention multiple platforms in your Question, all you've really done is flag it for closure. I suggest you Edit the Question drop the the R and QGIS references and focus the Question on the platform in the title and tags. I suggest you try buffering the selection polygon by one half the square root of two times the pixel size, since only centroids of rasters are used to select them.
    – Vince
    May 20 at 13:43
  • Thank you- I have edited the question as you proposed. So, just to make sure I do not have a mistake in my thoughts, "I suggest you try buffering the selection polygon by one half the square root of two times the pixel size, since only centroids of rasters are used to select them." That would be 0.5 * sqrt(2*10*10) ?
    – Hvirina
    May 20 at 14:20

2 Answers 2


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.


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


Input data is raster and polygon boundary:


Result of model is:


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.

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.