# Clipping a raster using a polyline or polygon

I have a large raster created from values that cover the whole United States and Alaska which are both polygon and polyline features, this raster was caluclated using Spatial Analyst IDW Interpolation. How can I get the raster to clip with the either the polyline of the United States border or the polygon shape of the United States?

UPDATE: 12/21/10

Ok so I followed your advice Swingley and set the cell size environment setting to match the original raster. It gives it a smooth border but instead of having smooth grades of differentiating colors now i have large blocks of differentiating colors.

Good

Any ideas on how I can fix this and get the Bad raster to look like the orignial (good) raster but keep the bad rasters border?

-

-
Tried this but it severely killed the resolution of the raster, any way to keep the original res? –  Furlong Dec 21 '10 at 0:03
What's the cell size of the raster being clipped? You could also try setting the cell size environment setting for ArcGIS: help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… –  Derek Swingley Dec 21 '10 at 1:25
You are absolutely correct. In some cases the result will be sensitive to the grid origin, too, so a better approach is to set the origin and cellsize to the same as the interpolated grid. Actually, in retrospect it's best to establish the desired projection, specify an explicit raster environment at the outset, create the mask first, and then do the interpolation with the mask in place: that would be easier for both the analyst and the computer. –  whuber Dec 21 '10 at 14:48
This works great, thank you guys! –  Furlong Dec 21 '10 at 15:35

With GRASS GIS you could rasterize your polygone of the USA (v.to.rast) and then use a mask.

-
I will try that for my next project. –  Furlong Dec 21 '10 at 17:50

You can also use the GDAL utility program GDALWarp - http://www.gdal.org/gdalwarp.html

Passing in a -cutline parameter (a feature from any OGR datasource) clips the original raster.

E.g.

C:\gdal\apps\gdalwarp C:\myraster.tif C:\output.tif -cutline C:\inputfeat.json -dstnodata -9999


In GDAL 1.8 there is a new -crop_to_cutline paramter that may also be useful.

-
only problem with this -cutline parameter is that the resulting raster comes with a mislocation of ~1 pixel... –  vascobnunes Jul 14 '11 at 14:05