writing tiff file by row {raster}
Thanks Robert Yes, I do work with real numbers. So easiest format for simple grids I'd guess is geotiff or something more complicated for bands. I really only need a compressed format for mapping the grid (and saving disk space) and I would guess that people would not (could not) process large grids (above 32bit windows limitation, around 3-4gig depending on setup) in Arc, so even a compressed read only format that Arc supports would do (see http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?tocVisable=0&ID=3027&TopicName=Supported%20raster%20dataset%20file%20formats&pid=3026). Cheers Herry -----Original Message----- From: Robert Hijmans [mailto:r.hijmans at gmail.com] Sent: Wednesday, December 24, 2008 3:27 AM To: Herr, Alexander Herr - Herry (CSE, Gungahlin) Subject: Re: [R-sig-Geo] writing tiff file by row {raster} Alexander, I added a function "grdToBil" to the raster package. It may take 24 hours or so before it is available in the compiled package on R-forge, after that you can get it via install.packages("raster",repos="http://R-Forge.R-project.org") The below example, adjusted from yours, works for me. That is, the raster package creates a GRD file, row by row, and when it is done it exports it to a BIL file using the new function. In R I can read that file (via rgdal). Whether ArcMap can read this file is another matter (I do not have access to ArcMap right now). Arc-* used to (and perhaps still does) assume that BIL files have unsigned integer values. Thus, if your data are real numbers and/or include negative numbers you might have trouble with reading the exported BIL file in ArcMap. Perhaps you need to round the numbers. The negative number can sometimes be solved with a calculation in Arc (in command line ArcInfo, with a statement like newgrid = con(oldgrid >= 32768, oldgrid - 65536, newgrid) I will look into a less error prone binary format that ArcMap can read; perhaps Erdas IMG. Suggestions anyone? require(raster) # read and write row by row; write to binary file rs <- raster.from.file(system.file("external/test.ag", package="sp")) binrow <- set.filename(rs, "binrow.grd") for (r in 1:nrow(rs)) { rs <- readRow(rs, r) # print(paste(nrow(rs)+1 - r, " rows to go")) vals<-values(rs)/4 vals[values(rs)<=500]<-NA # perhaps you need to add something like the following two lines for your data # vals <- round(vals) # binrow <- set.datatype(binrow, "integer") binrow <- set.values.row(binrow, vals, r) binrow <- write.row(binrow, overwrite=TRUE) } # bilraster has not been documented yet # it exports a binary raster to a bil file bilrs <- grdToBil(binrow, keepGRD = TRUE, overwrite = TRUE) # to show that it worked raster.map(rs, col=topo.colors(25)) windows() raster.map(bilrs, col=topo.colors(25)) Cheers, Robert
On Tue, Dec 23, 2008 at 8:40 AM, <Alexander.Herr at csiro.au> wrote:
Hi List,
I can write out ascii grids by row (see below), but I can't figure out how to do this in say compressed geotiff or another compressed lossless format readable by ESRI.
require(rgdal)
require(raster)
# read and write row by row; write to ascii file
rs <- raster.from.file(system.file("external/test.ag", package="sp"))
#rs <- setNA(rs, operator ="<=", value=0)
ascrow <- set.filename(rs, "ascrow.asc")
for (r in 1:nrow(rs)) {
rs <- readRow(rs, r)
#rs <- setNA(rs, operator ="<", value=10)
print(paste(nrow(rs)+1 - r, " rows to go"))
vals<-values(rs)/4
vals[values(rs)<=500]<-NA
ascrow <- set.values.row(ascrow, vals, r)
ascrow <- write.ascii(ascrow, overwrite=TRUE)
}
Any hints appreciated
Thanx
Herry
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo