Skip to content

Plotting continuous data (gridded) clipped to shape boundary

1 message · Roger Bivand

#
On Wed, 27 Feb 2008, Shawn P. Serbin wrote:

            
It is not impossible that the difficulties come from mixing projected and 
geographical coordinates. Could you please try to show is your problem as 
code, say using volcano? Could you also say what you mean by "clipping" - 
do you mean painting over the areas outside Wisconsin with background 
colour? Or do you mean setting the grid cells falling outside Wisconsin to 
NA, and omitting them from the display?

If the polygon is a SpatialPolygons object, and the data are a 
SpatialGridDataFrame or SpatialPixelsDataFrame in the same coordinate 
reference system, overlay() methods in sp will do this. If not in the same 
CRS, use spTransform() on the SpatialPolygons object to get it to the grid 
CRS. For obvious reasons, you cannot transform the CRS of the grid.

Roger