0

I'm trying to read in a TIF file as follows:

d = readGDAL('F182013.v4c.stable_lights.avg_vis.tif')
Error in validityMethod(as(object, superClass)) : 
  Geographical CRS given to non-conformant data: -180.004166667

The file is night light data from US National Oceanic and Atmospheric Administration, so it should be a valid file. Maybe the problem relates to a numerical floating point issue.

Grateful for any advice how to workaround.

geotheory
  • 22,624
  • 29
  • 119
  • 196

2 Answers2

1

readGDAL calls the error-checking function validityMethod, which checks that the longitude is within +/- 180 degrees for WGS84. Non-fatal errors and messages can be suppressed with:

d = readGDAL('F182013.v4c.stable_lights.avg_vis.tif', silent = TRUE)

so that the file can at least be read in as a SpatialGridDataFrame. The corresponding geographic range of the object is still beyond +/-180 deg, but the error may be within the tolerance you're willing to accept.

bbox(d)
         min       max
x -180.00417 180.00417
y  -65.00417  75.00417
0

A workaround is:

require(tiff)
r = raster(readTIFF(filepath, as.is = T))
extent(r) = extent(-180,180,-65,75)
crs(r) = CRS("+proj=longlat +datum=WGS84")
geotheory
  • 22,624
  • 29
  • 119
  • 196