[R-sig-Geo] How to mask out

Edzer J. Pebesma e.pebesma at geog.uu.nl
Tue Jan 4 20:47:12 CET 2005


José, you would have to do the following:
1. obtain the polygons the make up the Iberian peninsula
2. overlay the interpolation grid with the polygons:
   for each point on the grid, determine whether it is
   inside or outside the peninsula;
3. put these (logical) values in a matrix of the same
   form of the z argument in the list returned by interp.new
   (the matrix in the form that "image" likes)
4. using this logical matrix, say B, mask out the "outside"
   values in the interpolated matrix, say A$z, by
   > A$z[B] = NA

I don't know whether maps can give you the complete polygons,
I think they work from topology; if rings are formed on the
fly, I don't know how to get them. Try:

library(maps)
x = map("world", "spain")
polygon(cbind(x$x,x$y),col="red")

and you'll see that x does not contain one single polygon
for the big peninsula, but many fragments.

Points in polygon are not so hard to get in R.
My guess is that Roger might be able to help you further.
--
Edzer

José Agustín García García wrote:
> Hello
> 
> I am traying to interpolate several rainfalls data over the Iberian 
> Peninsula and display the results over a map of the Peninsula. I have 
> used the akima package to make the interpolation and the maps package to 
> draw the map. My cuestion is whow may I  mask out the output of the 
> interp.new function (with extrapolation) with the iberian Peninsula map 
> provided by the map package in order to restrict the image to the 
> Iberian Peninsula ? . Any suggestions are wellcome
> 
> Thank in advance for your help
> 
> Agustin

-- 
Edzer




More information about the R-sig-Geo mailing list