Skip to content
Prev 9731 / 29559 Next

Help with GIS

This is a dummy example - especially in terms of made up coordinate
system details, but shows how you can reproject with the raster
package:

library(rgdal)

## create a grid, with dummy coordinates / projection

im <- image2Grid(list(x = 1e5 * (1:nrow(volcano)), y = 1e5 *
(1:ncol(volcano)), z = volcano), p4 = "+proj=laea")

writeGDAL(im, "dummy.tif")

## now the process, using raster package

library(raster)


r0 <- raster("dummy.tif")

# proj.4 projection description
newproj <- "+proj=longlat +ellps=WGS84"

pr <- projectExtent(r0, newproj)
## (optionally) Adjust the cell size
## res(pr) <- res(pr)/2


# project the values of RasterLayer 'r' to the new RasterLayer 'projras'
projras <- projectRaster(r0, pr)

## now go back to sp and extract matrix

spprojras <- as(projras, "SpatialGridDataFrame")

m <- as.image.SpatialGridDataFrame(spprojras)$z

image(m)


I'm not sure if the coercion to SpatialGridDataFrame will
automatically give you all of the detail in the source by default for
large grids, but there would be a way.

Cheers, MIke.
On Wed, Oct 27, 2010 at 7:03 PM, <fsantos at ujaen.es> wrote: