Skip to content

Combining spatial pixels objects

2 messages · Mark Payne, Edzer Pebesma

#
Hi,

Consider a situation where I have a spatialpixelsdataframe, m.subset,
that is a subset of a larger dataframe, m. Due to the large size of my
dataset, its more efficient for me to work on just this subset, than
it is to work with the entire data set. Now, the question is, once
I've finished processing the subset, I want to add it back into the
original object. But the question is... how?

In terms of a code example, it might look like:

library(sp)
data(meuse.grid)
coordinates(meuse.grid) <- ~ x + y
m <- SpatialPixelsDataFrame(meuse.grid,meuse.grid at data)
m <- m[,"dist"]

#Split into a subset
m.subset <- subset(m,m$y > 333000)

#Do som fancy processing on m.subset e.g.
m.subset$dist <- m.subset$dist * 10

Now I want to combine the modified pixels in m.subset back into the
main object, m. Does anyone have any ideas how this might be done?

Best wishes,

Mark
#
On 11/19/2013 02:58 PM, Mark Payne wrote:
yes, by

total = rbind(m, m.subset)

but note that in this case total will have some pixels appear twice,
which you will not see in

image(total)

but for instance,

image(rbind(m.subset, m))

will mask the larger values. Then,

as(total, "SpatialGridDataFrame")

will remove the duplicates. Use carefully,