[R-sig-Geo] Basic raster operations
Michael Sumner
mdsumner at utas.edu.au
Mon Jun 16 15:21:03 CEST 2008
I would follow this up in the elide() function of maptools. I thought
I'd post this as a partial answer, since I'm sure this is the most
productive way to go given the goals of sp/maptools.
This is a test done only for simple shift on SGDF:
## WARNING: test method only partially implemented (for shift=)
setMethod("elide", "SpatialGridDataFrame",
function(obj, ...)
{
.local <- function (obj, bb = NULL, shift = c(0, 0), reflect = c(FALSE,
FALSE), scale = NULL, flip = FALSE, rotate = 0, center = NULL)
{
#res <- elide(as(obj, "SpatialPoints"), bb = bb, shift = shift,
# reflect = reflect, scale = scale, flip = flip, rotate =
rotate,
# center = center)
warning("TEST METHOD: elide only defined for shift on SGDF!")
gt <- getGridTopology(obj)
cc.offset <- gt at cellcentre.offset + shift
gt <- GridTopology(cc.offset, gt at cellsize, gt at cells.dim)
p4 <- proj4string(obj)
df <- slot(obj, "data")
res <- SpatialGridDataFrame(gt, data = df, proj4string =
CRS(as.character(p4)))
res
}
.local(obj, ...)
})
## Examples
library(maptools)
x <- image2Grid(list(x = 1:nrow(volcano), y = 1:ncol(volcano), z = volcano))
image(x)
contour(elide(x, shift = c(-15, 10)), add = T)
y <- readGDAL(system.file("pictures/Rlogo.jpg", package = "rgdal")[1],
band=1)
image(y)
image(elide(y, shift = c(10, 10)), add = T)
I hope that helps, at least for your first question, certainly I
appreciate you pushing me in the right direction.
Cheers, Mike.
Barry Rowlingson wrote:
> I'm getting frustrated at what I thought would be simple raster
> manipulations...
>
> * How can I shift a SpatialGridDataFrame? I can't just change the
> coordinates:
>
> > coordinates(compare)=coordinates(compare)+10
> Error in `coordinates<-`(`*tmp*`, value = c(10.5, 11.5, 12.5, 13.5,
> 14.5, :
> setting coordinates cannot be done on Spatial objects, where they
> have already been set
>
> Do I have to construct a new GridTopology object, then feed that to
> SpatialGridDataFrame along with the @data slot from the original? It
> seems to work, but I was hoping for something simpler, and I always
> get the jitters when working with slots since I tend to think of them
> as private object data that I shouldn't mess with. Isn't there a
> 'getData' method?
>
> * How can I construct larger SpatialGridDataFrames by tiling smaller
> ones?
>
> If they operated like matrices or data frames I could just cbind or
> rbind them together. I think I'm going to have to do a similar
> procedure as above - work out the new GridTopology and pass a new data
> frame constructed from merging the individual data frames together and
> making sure it's all in the right order. Which is tricky, because the
> SpatialGridDataFrame constructor expects its data argument to start at
> top-left and sweep across and then down. To paste another raster to
> the right of an existing one would mean mingling the data frame rows....
>
> Or am I just missing something simple with this? Of course it *will*
> be simple, once I've written the tiling functions:
>
> foo = tile(bar,west=baz)
>
> will construct a new grid 'foo' which is bar with baz pasted on it's
> western edge, equivalent to:
>
> foo = tile(baz,east=bar)
>
> it'll check the grids have the same number of rows (or for N-S
> tiling, columns) and that the data frames are similar.
>
> Barry
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> ------------------------------------------------------------------------
>
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 8.0.100 / Virus Database: 270.3.0/1505 - Release Date: 6/16/2008 7:20 AM
>
More information about the R-sig-Geo
mailing list