[prev in list] [next in list] [prev in thread] [next in thread]
List: r-sig-geo
Subject: Re: [R-sig-Geo] writing tiff file by row {raster}
From: "Robert Hijmans" <r.hijmans () gmail ! com>
Date: 2008-12-24 14:52:16
Message-ID: dc22b2570812240652t149c30eeg1fd1f6b1845d95a5 () mail ! gmail ! com
[Download RAW message or body]
Hi Herry, thanks that is a helpful list. I should be able to implement a
couple of these. For now, I have given a stab at the ENVI format. See below.
It works in R, give it a try in Arc.
require(raster)
rs <- raster.from.file(system.file("external/test.ag", package="sp"))
binrow <- set.raster(rs, "binrow.grd")
for (r in 1:nrow(rs)) {
rs <- readRow(rs, r)
vals <- values(rs)/4
binrow <- set.values.row(binrow, vals, r)
binrow <- write.row(binrow, overwrite=TRUE)
}
writeENVIHdr(binrow)
# note the use of extension "gri" here in stead of "grd" (i.e. using the
same binary data file, gdal will look for the .hdr file)
envirs <- raster.from.file("binrow.gri")
raster.map(envirs)
On Wed, Dec 24, 2008 at 6:00 AM, <Alexander.Herr@csiro.au> wrote:
> 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@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@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@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
>
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic