[R-sig-Geo] !SPAM: Re: Help with re-sampling a matrix: akin to cutting a cloth/paper into small pieces without interpolating
Els Ducheyne
educheyne at avia-gis.be
Fri Jul 2 14:21:00 CEST 2010
Dear Emmanuel
if you use the package maptools you should be able to create an image with the resolution that you want
something like data.im.resampled<-as.im(matrix,dimyx=(floor(data.im$dim)*5))
for an image with a resolutin in x and y 5 times more fine
HTH
Els
On 2 Jul 2010, at 13:47, Emmanuel Jjunju wrote:
> #I have data in a matrix with longitude (x coordinates) regularly spaced at
> 2.8 degrees and lat (y coordinates) at 2.5 degrees.I want to Resample my
> matrix z to a different resolution of say 1x1 in R without using
> interpolation (e.g inter in Akima package) because this distorts the data
> i.e. The data should not vary smoothly in space. What I want is analogous to
> resample in a GIS withoout smoothing, something like assigning the new pixel
> with the average or maximum of the contents in the pixel location. Ideally
> think of it like cutting a piece of cloth into tiny bits that retain the
> information!
>
> x<-seq(29,36,2.8)#lon
> y<-seq(-4,6,2.5)#lat
> z<-matrix(runif(length(x)*length(y)),length(x),length(y))# my original
> matrix
> par(mfrow=c(2,2))
> image(x,y,z,col=cm.colors(20))# plots the data as is
>
> #Using Interpolation with Akima Interp
> library(akima)
> xd<-seq(29,36,1)# new lon
> yd<-seq(-4,6,1) # new lat
> old.kords<-expand.grid(x,y)
> zd<-interp(old.kords[,1],old.kords[,2],c(z),xd,yd)
> image(xd,yd,zd$z,col=cm.colors(20))# shows that interpolation has distorted
> the spatial pattern. What i want is similar pattern but with finer grid.
> Interp clearly cannot do this.
>
> # so how do i resample without changing the pattern.
>
> --
> <a href="http://inside-r.org/download" title="Download R"><img src="
> http://inside-r.org/sites/all/themes/rweb/assets/badges/download-r-badge-125-blue.png"
> border="0" /></a>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
More information about the R-sig-Geo
mailing list