R Raster: Why do the cropped GeoTIFF rasters have different values than the original rasters (the values are rounded)?

Viewed 58

I have an interesting problem with the crop function. When I crop a stack of my rasters, the resulting files have different values from the original files - values are rounded. Interestingly, when I do this in QGIS, I don't have this problem. For example, below I am pasting the values read from individual rasters using the tool sample raster values in QGIS:

Original raster Cropped in R Cropped in QGIS
-1,649999999999980 -2,000000000000000 -1,649999999999980
0,850000000000023 1,000000000000000 0,850000000000023
-1,649999999999980 -2,000000000000000 -1,649999999999980
-1,149999999999980 -1,000000000000000 -1,149999999999980
-4,049999999999960 -4,000000000000000 -4,049999999999960
-3,049999999999950 -3,000000000000000 -3,049999999999950

Here is my code:

require(raster)
require(rgdal)
rasterOptions(tmpdir="C:/GIS/Temp", progress="text", timer=TRUE)
setwd("C:/GIS/Saved")
maska <- readOGR(dsn="C:/GIS/Mask", layer="Europe")
pliki_chelsa<- list.files("C:/GIS/Chelsa 2.1/1981-2010/bio/1",pattern='tif',full.names=TRUE)
stack_chelsa <- raster::stack(pliki_chelsa)
crs(stack_chelsa) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
nazwy_chelsa <- names(stack_chelsa)
maska_chelsa <- crop(stack_chelsa, maska)
writeRaster(maska_chelsa, filename=nazwy_chelsa, format="GTiff", prj=TRUE, bylayer=TRUE, suffix=nazwy_chelsa, overwrite=TRUE)

I will be grateful for any help.

Regards Adrian

0 Answers
Related