Ergh, sorry for the update - a pox on Gmail for sabotaging my attempts at plain text! I've attached the functions in a text file to avoid [ampersand] to " at " conversion ...
---------- Forwarded message ---------- From: Michael Sumner <mdsum...@gmail.com> Date: Tue, Nov 3, 2009 at 8:45 AM Subject: Re: [R-sig-Geo] flip SpatialGridDataFrame across axis To: r-sig-geo@stat.math.ethz.ch It would be nice if the "[" methods on ?'SpatialGridDataFrame-class' could perform the same indexing orientation, but that uses the row/column values for [i,j,...] to obtain the subsetted cells which are regridded via SpatialPixels - so the direction is lost. I'm not sure it's a good idea to modify that - given that the indexing could be used to subset at the same time - which is probably why the authors have written it that way. ;) But, I've been meaning to try something like this for ages, and this seems to work: flipHorizontal <- function(x) { if (!inherits(x, "SpatialGridDataFrame")) stop("x must be a SpatialGridDataFrame") grd <- getGridTopology(x) idx = 1:prod(g...@cells.dim[1:2]) m = matrix(idx, g...@cells.dim[2], g...@cells.dim[1], byrow = TRUE)[,g...@cells.dim[1]:1] idx = as.vector(t(m)) �...@data <- x...@data[idx, TRUE, drop = FALSE] x } flipVertical <- function(x) { if (!inherits(x, "SpatialGridDataFrame")) stop("x must be a SpatialGridDataFrame") grd <- getGridTopology(x) idx = 1:prod(g...@cells.dim[1:2]) m = matrix(idx, g...@cells.dim[2], g...@cells.dim[1], byrow = TRUE)[...@cells.dim[2]:1, ] idx = as.vector(t(m)) �...@data <- x...@data[idx, TRUE, drop = FALSE] x } The approach there is stolen from 'subs.SpatialGridDataFrame' in sp/R/SpatialGridDataFrame-methods.R - so thanks as ever to the authors! Cheers, Mike. On Tue, Nov 3, 2009 at 7:49 AM, Sebastian P. Luque <splu...@gmail.com> wrote: > On Tue, 3 Nov 2009 07:40:59 +1100, > Michael Sumner <mdsum...@gmail.com> wrote: > >> Hi Sebastian, I think the "north-south" note is referring to >> possibly-rotated grids (using the transform values supported by many >> formats) - not to "north vs. south" in orientation. > >> You can easily flip a grid by reverting it (one band at a time) to an >> xyz image and using indexing. I find this approach the least confusing >> and easily repeatable. > > [...] > > Thanks for the quick reply Mike!! > > > Cheers, > > -- > Seb > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-geo >
flipSGDF.R
Description: Binary data
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo