You can use readGDAL and writeGDAL. If you really need lower level gdal functions you can look at the code of these functions. you can also use functions from 'raster':
library(raster) r <- raster(fname) x <- r * 2 x <- writeRaster( x, "t1.tif") plot(x) On Tue, Aug 28, 2012 at 5:27 AM, cpadwick <cpadw...@hotmail.com> wrote: > Hi, I want to read an existing geotiff file (with georeferencing info), > operate on the raster data, and write out the result to a Float32 file. > I'm > working with hyperion data which is Integer. > > This code creates an outputfile, however, the output file t1.tif is > Integer. > I need it to be float. > > fname = "./EO1H0420362001131100P1/EO1H0420362001131100P1_B023_L1T.TIF" > x <- GDAL.open(fname, read.only=TRUE) > tmp = getRasterData(x) > xx <- copyDataset(x, driver="GTiff") > putRasterData(xx, tmp+1) > saveDataset(xx, "t1.tif") > GDAL.close(x) > GDAL.close(xx) > > This code creates a Float32 file, however, the geo referencing information > is lost: > > x <- GDAL.open(fname, read.only=TRUE) > tmp = getRasterData(x) > xx <- new("GDALTransientDataset", driver=new("GDALDriver", "GTiff"), > rows=ncol(tmp), cols=nrow(tmp), bands=1, type="Float32") > putRasterData(xx, tmp+1) > saveDataset(xx, "t2.tif") > GDAL.close(x) > GDAL.close(xx) > > This code fails with the following error: > > Error in function (classes, fdef, mtable) : > unable to find an inherited method for function "gridded", for signature > "GDALTransientDataset" > > x <- GDAL.open(fname, read.only=TRUE) > tmp = getRasterData(x) > xx <- copyDataset(x, driver="GTiff") > putRasterData(xx, tmp+1) > writeGDAL(xx, "t3.tif") > GDAL.close(x) > GDAL.close(xx) > > Any help will be greatly appreciated. > > > > > > > -- > View this message in context: > http://r-sig-geo.2731867.n2.nabble.com/problems-writing-a-tiff-file-with-georeferencing-tp7580850.html > Sent from the R-sig-geo mailing list archive at Nabble.com. > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo