[R-sig-Geo] Create a simple spatial grid

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Fri May 23 00:57:32 CEST 2014


On Thu, May 22, 2014 at 7:44 PM, Remi Genevest <rgenevest at free.fr> wrote:
> Alright !
> You pointed out my goal indeed... but 100meters by 100meters is still a bit
> too high for a map over Europe.
> So, this is what I have done :
>
> ### create a grid raster
> ll = CRS("+init=epsg:4326")
> origin = SpatialPoints(cbind(7,40),ll)
> grid = raster()
> ## make resolution ie 0.008 min par 0.008 spaced cells (equals to about
> 800m*800m), that is actually quite accurate
> e = extent(5,18,40,50)
> extent(grid)<-e
> res(grid)=c(0.008,0.008)
> grid
>
> Now, I hope that the extract() function will work fine after adding my other
> layers (that do not have the same original CRS nor resolution...!)

Converting vector data (points, lines, polygons) from one CRS to
another is essentially lossless and often reversible. However
converting raster data from one grid to another is lossy (eg when your
new grid cells overlap more than one old grid cell and you taken an
average) and when reversed you don't get your original back (because
of the lossy nature). When possible, consider the raster data you may
have been supplied with as the CRS to work with, and transform vector
data to that system.

If you have multiple raster CRSs then you might never need to
transform them to the same system anyway, if all you are doing is,
say, sampling raster values at a set of points - just transform the
points to each raster's CRS in turn, and sample. Doing raster-raster
overlay will need a raster-raster transform though...

Barry



More information about the R-sig-Geo mailing list