0

I am trying to load multiple rasters (87 in total) into R for analysis. The rasters are being loaded direct to a stack using this code:

filelist <- list.files(path="mypath", pattern="tif$", full.names=TRUE)
stk1 <- raster::stack(filelist)

The data largely load correctly apart from 9 problematic bands that seem to have the same issue. These bad bands are loading with 'attributes'. See example below

goodband

> goodband
class       : RasterLayer 
dimensions  : 1768, 3674, 6495632  (nrow, ncol, ncell)
resolution  : 40, 40  (x, y)
extent      : 135800.4, 282760.4, 22297.69, 93017.69  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 
data source : goodband.tif 
names       : Good 
values      : 0.5, 36  (min, max)

badband

> badband
class       : RasterLayer 
dimensions  : 1768, 3674, 6495632  (nrow, ncol, ncell)
resolution  : 40, 40  (x, y)
extent      : 135800.4, 282760.4, 22297.69, 93017.69  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 
data source : badband.tif 
names       : Bad 
values      : 33, 6824  (min, max)
attributes  :
        ID OID Value Count
 from:   0   0    33   433
 to  : 529 529  6824  1307

As you can see the badband has additional 'attributes' at the bottom. When trying to analyse bad bands they are just full of null values and don't operate like the good bands.

Could you advise how best to fix this problem?

ChrisY
  • 1
  • 3
  • Did you try opening the "bad bands" e.g., with QGIS and see if they are ok ? If not, then the problem is not in rasterstack, but in the input data (which seems probable to me) – lbusett Oct 25 '16 at 22:01
  • Yes, I have opened in ArcGIS (where they were made) and they work fine. I have also recreated them and re-stacked the rasters and same problem – ChrisY Nov 01 '16 at 13:11
  • One maybe strange thing is that your "bad" band has a completely different range of values than the "good" band. Is that correct ? – lbusett Nov 01 '16 at 20:28
  • The data are both geochemical data. The ranges are not that different, they are still both two orders of magnitude from min to max – ChrisY Nov 02 '16 at 09:48
  • Yes, but one is 0.5 to 36, while the other is 33 to 6824. If they are the same parameter it seems strange. But again, you obviously know this better than me ! – lbusett Nov 02 '16 at 13:14

0 Answers0