2

I have a series of GTiff images that I am trying to merge into a single larger extent. 6 small tiles need to be combined to generate my larger extent. My original 6 tiles have values which range from 0 to 255.

For example:

> tiff.list[[1]]
class       : RasterLayer 
dimensions  : 1200, 1200, 1440000  (nrow, ncol, ncell)
resolution  : 926.6254, 926.6254  (x, y)
extent      : -10007555, -8895604, 2223901, 3335852  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs 
data source : D:\Scratch\Data\MOD15A2.A2016153.h09v06.005.2016166083754.tif 
names       : MOD15A2.A2016153.h09v06.005.2016166083754 
values      : 0, 255  (min, max)

However, when merging the tiles using the code detailed here, I get a new image file and the values have changed:

> xx
class       : RasterLayer 
dimensions  : 2400, 3600, 8640000  (nrow, ncol, ncell)
resolution  : 926.6254, 926.6254  (x, y)
extent      : -10007555, -6671703, 1111951, 3335852  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs 
data source : D:\Scratch\Modis\A2016161.tif 
names       : A2016161 
values      : 0, 25  (min, max)

Does anyone know why this is happening? I've tried changing the file format and dataType ('INT1U') but it keeps happening. It's important the values don't change from 0 to 255 as the original data comes from NASAs MODIS satellite and certain values (i.e. 248-255) have specific fill values associated with them (for example, land cover assigned as water or snow). This change from a max value of 255 to 25 is removing important information from the original files.

Any assistance provided would be most welcome.

Community
  • 1
  • 1
Simon
  • 991
  • 8
  • 30
  • 1
    I've experienced the same thing when working with MODIS data, and it is not as the RobertH suggest that the values are absent in the original file, for some reason `merge` or `mosaic` will change the values of MODIS rasters (it appears to usually be by 2 orders of magnitude). I've found that using `mosaic_rasters()` from `gdalutils` produces the desired results see the final answer to this question for more info: https://stackoverflow.com/questions/15876591/merging-multiple-rasters-in-r – admccurdy Dec 06 '17 at 23:22

1 Answers1

1

This suggests that these values are absent in the original files. The min and max values reported for the original files are based on the metadata provided therein. The metadata was likely wrong (showing the range of possible, not the actual values). To investigate do

setMinMax(tiff.list[[1]])

or

tiff.list[[1]] * 1
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63