Raster clipping issue

6001
5
05-03-2017 03:49 AM
EvaPintado
New Contributor

I need to clip a raster using a shapefile (many polygons), but I want it to clip only the pixels that are completely inside the polygons. I mean, I do not want to include the pixels that are part outside the boundaries of the polygons, is there any way to do this?

I know I can convert the raster into a shp and clip it but I do not want the pixels to split either; I need only whole pixels covered by the polygons.

Ideas anyone?

Eva

0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

clipping a raster will use the rule that the center of the cell must be inside the polygon.  This will aesthetically give you some 'jaggies' around the boundary of the polygon.  If you find this difficult to deal with, then the simplest solution is to create an indicator grid (0's and 1's) of the polygon file using the same cell size, extent and snap as the raster to be clipped.  Once you have your indicator grid use the spatial analyst's Shrink tool to shrink the 1's (ie inside) by 1 cell, effectively producing a negative buffer.  That file can be used for clipping or with the Combine tool amongst others.

0 Kudos
EvaPintado
New Contributor

Hi Dan, thank you very much for your reply. However I do not think it will work since I will loose a pixel in all the boundaries, regardless if those boundaries are fine or not. Do you know if there is any way of changing the rule in the clipping tool?

0 Kudos
DanPatterson_Retired
MVP Emeritus

You can't change the rule, if the centre is in the polygon, then you have to live with the fact that it will 'appear' that part of a 'cell' is split by the boundary.  Consider a perfectly horizontal or vertical line.... that feature will connect the centers of the cells.  Shifting will only move the problem in the other direction.  Or consider a polygon square.  In order for a raster cell to be completely within the square, then all 4 corners would have to be within the bounds of the polygon.  The only way this can happen is if the raster representation of the square polygon is shrunk by 1 cell.  If you don't like the jagged look, then you can use a smaller cell size along with limiting the zoom extent of a layer.  It is a difference between raster and vector data that is not surmountable even if using hexagonal raster cells or cells where the X and Y sizes can vary.

0 Kudos
EvaPintado
New Contributor

Thank you Dan. It is not a question of liking or not the jagged look, I need to have only the pixels completely inside the polygons (which are many and very irregular in shape) to do some calculations. Thank you anyway, will keep looking to see if can  filter them this in any way.

0 Kudos
curtvprice
MVP Esteemed Contributor

If the raster cells are much bigger than your polygons, a straight-forward approach would be to convert your clipped raster cells (some of which are totally inside, some partially outside) to polygon using the Raster To Polygon tool, and use the Select By Location tool to select the polygons that are entirely inside (CONTAINED BY) your clip polygons. You could then leave your cells as polygons or convert back to raster using Polygon To Raster (using the extent and snap raster and cell size of your clipped raster so it will line up).

Dan's other suggestion is also a good approach -- take your clip polygons, buffer them with a negative value of half the diagonal of a cell (cellsize * 1.41 * 0.5), and clip by that polygon. If the cells are not as huge as I envisioned from your description, this would be a better approach, as zillions of cell polygons are kind of hard to work with.

negative buffer