[R-sig-Geo] Combining spatial pixels objects
Edzer Pebesma
edzer.pebesma at uni-muenster.de
Tue Nov 19 15:27:11 CET 2013
On 11/19/2013 02:58 PM, Mark Payne wrote:
> 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?
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,
--
Edzer Pebesma
Institute for Geoinformatics (ifgi), University of Münster
Heisenbergstraße 2, 48149 Münster, Germany. Phone: +49 251
83 33081 http://ifgi.uni-muenster.de GPG key ID 0xAC227795
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 555 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20131119/2482af9e/attachment.bin>
More information about the R-sig-Geo
mailing list