[R-sig-Geo] Writing a byte image

Robert Hijmans r.hijmans at gmail.com
Fri Feb 27 02:07:58 CET 2009


Hi Ned,

This should work:

# Set output image properties
predrast <- setRaster(spot)

predrast <- setDatatype(predrast, 'INT1U')

filename(predrast) <- outImage

etc.

Robert

On Thu, Feb 26, 2009 at 10:15 PM, Ned Horning <horning at amnh.org> wrote:
> What is the recommended way to output a large byte GeoTiff image one line at
> a time? I am creating large double and integer images using writeRaster to
> create a GeoTiff file. I've been converting these to a byte data type
> outside of R but it would be nice to R to output a byte GeoTiff directly. I
> see there is a "type" flag for writeGDAL but I haven't been able to tell if
> I can use that for line-by-line writing.
>
> This is what I'm using now (thanks to feedback from Robert Hijmans and
> possible unnecessary complications by me):
> --
> # Set output image properties
> predrast <- setRaster(spot)
> filename(predrast) <- outImage
> nameVec <- colnames(trainvals)
> cname <- nameVec[2]
> for (n in 2:numbands) {
>  cname <- c(cname, nameVec[n+1])
> }
> # Use the randomForest object to predict land cover type based on the input
> # image one line at a time
> for (r in 1:nrow(spot)) {
>  spot <- readRow(spot, r)
>  rowvals <- values(spot, names=TRUE)
>  colnames(rowvals) <- cname
>  pred <- predict(randfor, rowvals)
>  pred <- as.numeric(pred)
>  predrast <- setValues(predrast, pred, r)
>  predrast <- writeRaster(predrast, format='GTiff', overwrite=TRUE)
> }
> --
>
> Ned
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list