SCM

[#6184] writeRaster returning nodatavalue = NA conflicts with single layer subsetting by "[["

Date:
2015-09-04 12:08
Priority:
3
State:
Open
Submitted by:
Benjamin Leutner (bleutner)
Assigned to:
Nobody (None)
Hardware:
None
Product:
None
Operating System:
None
Component:
None
Version:
None
Severity:
None
Resolution:
None
URL:
Summary:
writeRaster returning nodatavalue = NA conflicts with single layer subsetting by "[["

Detailed description
Hi Robert,

writeRaster of a RasterStack (nodatavalue = -Inf) returns a RasterBrick with nodatavalue = NA.
This can cause problems down the road (readCells.R:l86) if you query pixel values from a single layer with "[[" which turns NAchanged to TRUE but leaves nodatavalue at NA

### raster version 2.4-19 and 2.4-18 ##

r <- stack(raster(val=1, ncol=1, nrow=1))
## NA data value is -Inf
r@layers[[1]]@file

rf <- writeRaster(r, rasterTmpFile(), datatype="INT1S")
## nodatavalue is NA, NAchanged is FALSE
rf@file

## Get first layer: -> NAchanged is TRUE, but nodatavalue is NA
rf[[1]]@file

## Getting values
rf[1]
#> layer
#> [1,] 1

rf[[1]][1]
#> Error in if (x@file@nodatavalue < 0) { :
#> missing value where TRUE/FALSE needed



Cheers
Benjamin

Comments:

No Comments Have Been Posted

Attached Files:

Changes

No Changes Have Been Made to This Item

Thanks to:
Vienna University of Economics and Business Powered By FusionForge