[R-sig-Geo] is it possible to resample a raster image?

Vladimir Eremeev wl at eimb.ru
Thu Apr 19 11:50:55 CEST 2007


Dear all,

I am studying new knowledge areas now.

I am curious, if it is possible to transform a projected raster image
to another geographic projection using R packages.

For example, I have a matrix (representing an image)
It has 304 columns by 448 rows.
Initially it is stored in a file, having 2 bytes per pixel.
Lots of such images can be found here
ftp://sidads.colorado.edu/pub/DATASETS/brightness-temperatures/polar-stereo/ssmi/north/2006/

I import one of them in R:

tb.mtx<-matrix(readBin("ftp://sidads.colorado.edu/pub/DATASETS/brightness-temperatures/polar-stereo/ssmi/north/2006/tb_f13_20060101_v2_n19h.bin",
                       "integer",n=304*448,size=2),
               ncol=304,byrow=TRUE)

Then I create the SpatialGridDataFrame:

egrid<-cbind(expand.grid(x=seq(-3850000.0000000,3725000.0000000,by=25000),
                         y=seq(-5350000.0000000,5825000,by=25000)),
             as.vector(t(tb.mtx)[,448:1]))

coordinates(egrid)<-c("x","y")
gridded(egrid)<-TRUE
proj4string(egrid)<-CRS("+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +ellps=clrk66")

I have worked with these data using other tools for a long time
already, therefore, I know about their projection and dimensions.
These are documented in the web and also in `readme` files.

Now I would like to *use R-spatial packages* to transform egrid to another projection,
and export the result into an external flat binary file, similar to
the one, I have imported with readBin.

I can easily do it using other tool sets, however, now I am exploring
R.
Is it possible?

I tried the following, however, got errors.
> egtr<-spTransform(egrid,CRS("+proj=latlong"))
> gridded(egtr)<-TRUE

Error in if (any(outside)) { : missing value where TRUE/FALSE needed
In addition: Warning messages:
1: grid has empty column/rows in dimension 1 in: points2grid(points, tolerance) 
2: NAs introduced by coercion 
3: grid has empty column/rows in dimension 2 in: points2grid(points, tolerance) 
4: NAs introduced by coercion 

> fullgrid(egtr)<-TRUE
Error in `fullgrid<-`(`*tmp*`, value = TRUE) : 
        fullgrid<- only works on objects of class or extending SpatialPixels


Thank you!


---
Best regards,
Vladimir                mailto:wl at eimb.ru



--SevinMail--




More information about the R-sig-Geo mailing list