[R-sig-Geo] Clipping problem

Kamran Safi ksafi at orn.mpg.de
Thu Oct 28 22:47:56 CEST 2010


Hi Pete,

you get the indices of the points inside the polygons and the associated 
polygon ID value.

something like

clip<- grd[!is.na(overlay(grd, ccShapet)),]



should do.

Hope this helps, although I did not check the line in particular (just 
from the top of my head)

Kamran

Am 28.10.2010 22:23, schrieb Peter Larson:
> Hello all,
>
> I have a grid of points and a spatial polygon shape file. I want to
> clip the grid so that I only have the point which lie within the
> shapefile.
>
> I tried the following code:
>
> ## create a grid onto which we will interpolate:
> ## first get the range in data
> x.range<- c(37,50)
> y.range<- c(29,38)
>
> ## now expand to a grid with 500 meter spacing:
> grd<- expand.grid(x=seq(from=x.range[1], to=x.range[2], by=.01),
> y=seq(from=y.range[1], to=y.range[2], by=.01) )
>
> ## convert to SpatialPixel class
> coordinates(grd)<- ~ x+y
> gridded(grd)<- TRUE
>
> ## Read in Shapefile
> ccShapet=readShapePoly('IRQ_adm0') # here cbg00barncnty is an ArcGIS shapefile
>
> ## Clip
> clip<- overlay(grd, ccShapet)
>
> #Plot
> plot(clip)
>
> BUT it does not work. I just get a vector of number and NA's, but not
> the clipped grid.
>
> Any ideas?
>
> Thanks
>
> Pete
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ksafi.vcf
Type: text/x-vcard
Size: 400 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101028/9c8f2c8d/attachment.vcf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5861 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101028/9c8f2c8d/attachment.bin>


More information about the R-sig-Geo mailing list