[R-sig-Geo] deleting grid points outside boundary

Edzer Pebesma edzer.pebesma at uni-muenster.de
Mon May 25 11:15:39 CEST 2009


you could read your shapefile with readOGR in package rgdal,
then use function overlay to find the points in the polygon,
along the lines of:

# grd is your full, rectangular grid
# polygon is the shapefile you read
fullgrid(grd) = FALSE
sel = !is.na(overlay(grd, polygon))
grd = grd[sel,]

Viscarra Rossel, Raphael (CLW, Black Mountain) wrote:
> Hello,
> I have been using gstat to krige maps over my study area.
> The area is irregularly shaped and has quite a complex boundary.
> I have made a regular (square) grid that covers my study area and made
> my estimates on this grid.
> Now that I have my maps, I would like to 'mask out' or delete the
> areas in my map that are outside my study area - i.e. where I don't
> have any data, where the interpolations don't make sense. Essentially,
> I want to end up only with the estimates over my study area.
> As I said, the boundary of the study area is quite complex so the
> chull method will not work well. I have seen a few posts where this
> was suggested.
> I have the xy coordinates for the boundary (and a shape file) for the 
> study area. I am wondering whether I could overlay it over the grid
> with my estimates and then use it to remove the bits on the grid that
> I don't want and so end up with a map of only the estimates over my
> study area.
> Could someone help with this please?
> Cheers
> R.
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Weseler Straße 253, 48151 Münster, Germany. Phone: +49 251
8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de/
http://www.springer.com/978-0-387-78170-9 e.pebesma at wwu.de

More information about the R-sig-Geo mailing list