r-spatial / stars

Spatiotemporal Arrays, Raster and Vector Data Cubes
https://r-spatial.github.io/stars/
Apache License 2.0
563 stars 94 forks source link

Sensitivity of grid spacing #714

Closed pvanlaake closed 14 hours ago

pvanlaake commented 1 month ago

In https://github.com/r-spatial/stars/issues/700#issuecomment-2316793857 opening the file generates the GDAL error that the latitude grid is not evenly spaced. Looking at the raw latitude values that is indeed the case:

unique(abs(diff(diff(hu[["lat"]]$values))))  # Using package ncdfCF
# [1] 1.000000e-05 3.552714e-15 0.000000e+00 1.000000e-05 7.105427e-15 1.000000e-05

The largest difference between the latitude spacing in meters thus works out to be about:

 20000 / 180 * 1.e-05 * 1000  # 20,000km from pole to pole
# [1] 1.111111

That is about half the ensemble accuracy of the WGS 84 datum that this data is based upon, and with a cell separation of 20000 / 256 = 78.125 km it seems more of a spurious rounding error rather than an irregular spacing.

This is no doubt an issue buried deep in GDAL, but shouldn't the spacing assessment of geodetic coordinates be informed by - at the very least - datum (or ellipsoid) properties?

edzer commented 14 hours ago

I agree, but this is a property of the NetCDF driver of GDAL, not something that can be changed in this package, afaict.