Hi, Just a comment to sum up: Robert and Johannes mentioned two ways of clipping that give different results. My example: clipping MODIS raster data to Democratic Republic of Congo (DRC)
Robert suggested: MODIS_Drc_cropped<-crop(MODIS, Drc_spdf) # Here, MODIS cropped over a rectangle, so bigger than AOI Johannes suggested: MODIS_Drc_cropped<-crop(MODIS, Drc_spdf) DRC_mask_raster <- polygonsToRaster(Drc_spdf, raster(MODIS_Drc, values=NA), field=-1, updateRaster=TRUE ) # Make a raster mask from DRC area MODIS_Drc<- mask( MODIS_Drc_cropped, DRC_mask_raster) # apply the masked to the small rectangle MODIS MODIS_Drc_cropped is MODIS clipped over a rectangle which is the bounding box of DRC. MODIS_Drc has only data within the borders (the rest is NA) Mayeul _____________________________________________________ Dr. Mayeul KAUFFMANN, Conflict Specialist European Commission, Joint Research Centre (JRC) Institute for the Protection and Security of the Citizen (IPSC) Global Security and Crisis Management - ISFEREA Via E. Fermi 2749 - I-21027 Ispra (VA), ITALY Phone: (+39) 033278 5071 http://isferea.jrc.ec.europa.eu/Staff/Pages/Kauffmann-Mayeul.aspx (Office: building 48c, 1st floor, room 123. TP: 483) -----Original Message----- From: r-sig-geo-boun...@stat.math.ethz.ch [mailto:r-sig-geo-boun...@stat.math.ethz.ch] On Behalf Of Johannes Signer Sent: Thursday, October 14, 2010 5:39 PM To: Manuel Spínola Cc: r-sig-geo@stat.math.ethz.ch Subject: Re: [R-sig-Geo] Clip a raster Hi, with the raster package you could use: polygons to raster (?polygonsToRaster), converting the Costa Rica shapefile to a raster and then use mask (?mask). Best Johannes On Thu, Oct 14, 2010 at 5:16 PM, Manuel Spínola <mspinol...@gmail.com> wrote: > Dear list members, > > I download bioclim data in a raster format (estension: .bil) and I would > like to clip the variables to a ploygon stored as a shapefile (Costa > Rica outline). > How can I do that? > > I read the raster file like this: > > x <- readGDAL("bio1_23.bil") > > Thank you very much in advance. > Best, > > Manuel > > > -- > *Manuel Spínola, Ph.D.* > Instituto Internacional en Conservación y Manejo de Vida Silvestre > Universidad Nacional > Apartado 1350-3000 > Heredia > COSTA RICA > mspin...@una.ac.cr > mspinol...@gmail.com > Teléfono: (506) 2277-3598 > Fax: (506) 2237-7036 > Personal website: Lobito de río > <https://sites.google.com/site/lobitoderio/> > Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/> > > [[alternative HTML version deleted]] > > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo _______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo