[R-sig-Geo] More questions on setting up ENVI headers...

Roger Bivand Roger.Bivand at nhh.no
Fri Jul 10 09:57:34 CEST 2009


On Thu, 9 Jul 2009, Jonathan Greenberg wrote:

> R-sig-geo'ers:
>
> I am using the following code to create an ENVI header:
>
>   driver="ENVI"
>   d.drv <- new("GDALDriver", driver)
>   tds.out <- new("GDALTransientDataset", driver = d.drv, rows = dims[2],cols 
> = dims[1], bands = bands, type = type)
>   gt <- c(offset[1] - 0.5 * cellsize[1], cellsize[1], 0.0,offset[2] + 
> (dims[2] -0.5) * cellsize[2], 0.0, -cellsize[2])
>   print(gt)
>   .Call("RGDAL_SetGeoTransform", tds.out, gt, PACKAGE = "rgdal")
>   .Call("RGDAL_SetProject", tds.out, file_projection, PACKAGE = "rgdal")
>   fn <- tempfile()
>   saveDataset(tds.out, fn)
>   GDAL.close(tds.out)
>
> gt prints out to be:
> [1]  736801.7      30.0       0.0 4447309.0       0.0     -30.0
>
>   The issue I'm having is that the output header, while containing the 
> correct projection, is not saving out the pixel sizes, an upper left 
> coordinates (e.g. I'm not getting RGDAL_SetGeoTransform to work correctly).

It is tricky, partly because in places the order of the coordinates is 
reversed - sometimes (columns, rows) for R-facing functions, often (rows, 
columns) for GDAL-facing code). I suspect that this is what is confusing 
here. Try to follow the code in writeGDAL() through called functions for 
examples.

Roger

> Here's the text of the output header:
>
> ENVI
> description = {
> /var/folders/-Y/-Yv+caBK2RaJhU+8ZQAOk++++TQ/-Tmp-//RtmpX7PvqQ/file4431b782}
> samples = 1172
> lines   = 2810
> bands   = 7
> header offset = 0
> file type = ENVI Standard
> data type = 4
> interleave = bsq
> byte order = 0
> map info = {UTM, 1, 1, 0, 0, 1, 1, 10, North,North America 1983}
> band names = {
> Band 1,
> Band 2,
> Band 3,
> Band 4,
> Band 5,
> Band 6,
> Band 7}
>
>   Thoughts?
>
> --j
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list