[R-sig-Geo] Help with GIS

Robert J. Hijmans r.hijmans at gmail.com
Thu Oct 28 02:39:53 CEST 2010


Hi Mike,

Thanks for that suggestion, It had not occurred to me to overload
as.matrix. Done that now (raster version 1.6-7) such that
as.matrix(projras) works.

Best, Robert


On Wed, Oct 27, 2010 at 4:01 PM, Michael Sumner <mdsumner at gmail.com> wrote:
> Thanks Robert, I still haven't explored raster enough.
>
> I tried as.matrix(projras) - have you considered adding methods like
> this? I'm afraid I still don't know the structure of the raster data
> sets enough to know if that makes sense, but I think sp returns
> another orientation in this way:
>
>  as.matrix(spprojras)
>
>
> Cheers, Mike.
>
> On Thu, Oct 28, 2010 at 9:54 AM, Robert J. Hijmans <r.hijmans at gmail.com> wrote:
>> After this:
>>
>>> projras <- projectRaster(r0, pr)
>>
>> You could also do plot(projras) or image(projras) and
>>
>> v <- getValues(projras, format='matrix')
>>
>> To get a matrix of values, with the advantage that values in this
>> matrix are organized as on the map (probably what you would expect),
>> which is different in matrix 'm' in Mike's example.
>>
>> Robert
>>
>> On Wed, Oct 27, 2010 at 2:16 PM, Michael Sumner <mdsumner at gmail.com> wrote:
>>> 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:
>>>> Dear R community,
>>>>
>>>> I'm sorry, but I am newbie with GIS. I have to import a tiff using a
>>>> geotiff tool, and convert it into a data matrix. The initial projection is
>>>> Lambert Azimuthal Equal Area, and I would like to get the final matrix in
>>>> a regular lat/lon grid.
>>>>
>>>> It is possible to do it with R?
>>>>
>>>> Thanks in advance.
>>>>
>>>> _______________________________________________
>>>> R-sig-Geo mailing list
>>>> R-sig-Geo at stat.math.ethz.ch
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>>
>>>
>>>
>>>
>>> --
>>> Michael Sumner
>>> Institute for Marine and Antarctic Studies, University of Tasmania
>>> Hobart, Australia
>>> e-mail: mdsumner at gmail.com
>>>
>>> _______________________________________________
>>> R-sig-Geo mailing list
>>> R-sig-Geo at stat.math.ethz.ch
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at stat.math.ethz.ch
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>
>
> --
> Michael Sumner
> Institute for Marine and Antarctic Studies, University of Tasmania
> Hobart, Australia
> e-mail: mdsumner at gmail.com
>



More information about the R-sig-Geo mailing list