0

I am importing and exporting ASTER digital elevation models in R using the raster package. These data have a geographic coordinate system, so that the extent of the raster and its cellsize are in degrees.

I find that there must be some kind of arithmetic underflow when importing and exporting one and the same dataset. For example, I import a toy ASTER scene ASTGTMV003_N48W122_dem.tif into R (I uploaded the data set here) and want to find out its resolution:

# example scene downloaded from EarthExplorer (https://earthexplorer.usgs.gov/)
r <- raster("ASTGTMV003_N48W122_dem.tif") 
res(r)

And R tells me that the resolution (x, y) is: 0.0002777778 0.0002777778 QGIS, however, suggests that the same dataset has much more digits: 0.0002777777777777779944,-0.0002777777777777779944.

So here comes the twist: I now export this dataset as a GeoTIFF and import it again and keep all parameters unchanged. R would tell me that nothing has changed:

writeRaster(r, "test.tif") # export GTiff
r2 <- raster("test.tif")   # import again
res(r) == res(r2)          # which returns TRUE TRUE

Yet in GIS, I find that my new test.tif has a resolution of 0.0002777777778394882884,-0.0002777777778394882884, which is different from the original ASTER scene. While R seems to be forgiving in this regard, GIS tells me that the extents and the cellsizes are NOT the same. I reproduced this example with other ASTER and SRTM scenes and the problem persists. Yet the digits are always different from the 13th digit onward.

I speculate that the problem is tied to the uneven number of rows and columns (3601, 3601). At least, using ALOS3D 30m data with 3600 rows and columns, I couldn't reproduce this issue.

Did anyone face a similar issue with extents and resolutions when exporting and importing SRTM or ASTER data?

GeVe
  • 1
  • Hello and welcome to StackOveflow. Your first question is well documented, thanks for that. – Arthur Apr 07 '20 at 11:42
  • 2
    BUT are you sure that the question is relevant at all? I mean, do you need **that** level of precision for the work at hand? If it is, please explain why ;) You probably know the XKCD cartoon for that, eh? https://xkcd.com/2170/ – Arthur Apr 07 '20 at 11:44
  • 1
    Yes, it matters, because these digits shift every time I import and export the ASTER scene (which hardly warrants reproducible science, no?). SAGA-GIS, for example, is very strict with regards to extents and resolutions of rasters. Using the example here, it recognizes two different extents, so that I cannot directly compare the original with the processed one. Strange, isn't it? – GeVe Apr 07 '20 at 11:59
  • Could it be just a `float` vs `double` conversion problem? – Arthur Apr 07 '20 at 12:11
  • `x <- 0.0002777777777777779944 ; save(x, file="x.rda") ; load("x.rda") ; x` gives `0.0002777778` – Arthur Apr 07 '20 at 12:31

0 Answers0