question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GDAL_NODATA value being rounded

See original GitHub issue

Generally the GDAL_NODATA metadata is working for me but I have some files that get an incorrect value.

For example with this file, when I run gdalinfo I get a nodata value of 9.99999998050644787e+18 but geotiff.js says 1.0E19 (gdalinfo is correct).

I’m not sure what the difference is with how gdalinfo determines the value, so I’m not sure if it’s possible that the nodata metadata is incorrect but gdalinfo gets its info from somewhere else, or if geotiff.js is not reading the value correctly.

$ gdalinfo example.tif

Driver: GTiff/GeoTIFF
Files: example.tif
Size is 279, 416
Coordinate System is:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (135.033453258464164,-23.596259085710940)
Pixel Size = (0.003889256068923,-0.003789922154798)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_RESOLUTIONUNIT=1 (unitless)
  TIFFTAG_XRESOLUTION=1
  TIFFTAG_YRESOLUTION=1
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  ( 135.0334533, -23.5962591) (135d 2' 0.43"E, 23d35'46.53"S)
Lower Left  ( 135.0334533, -25.1728667) (135d 2' 0.43"E, 25d10'22.32"S)
Upper Right ( 136.1185557, -23.5962591) (136d 7' 6.80"E, 23d35'46.53"S)
Lower Right ( 136.1185557, -25.1728667) (136d 7' 6.80"E, 25d10'22.32"S)
Center      ( 135.5760045, -24.3845629) (135d34'33.62"E, 24d23' 4.43"S)
Band 1 Block=272x416 Type=Float32, ColorInterp=Gray
  NoData Value=9.99999998050644787e+18

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
zakjancommented, Nov 12, 2021

I have a similar issue with CMEMS sea_ice_fraction scaled NetCDF. It contains non-sea points with descaled value 1.27999997138977, that I have to override as nodata.

gdal_translate -a_nodata 1.27999997138977 stores it as 1.27999997138977051 string. QGIS shows these points correctly as nodata. JS parses this string as 1.2799999713897705, so strict equality in JS doesn’t match the points.

My current workaround:

function maskData(data, nodata = undefined) {
  if (!nodata) {
    return data;
  }

  const maskedData = new data.constructor(Array.from(data).map(value => {
    return Math.abs(value - nodata) > Number.EPSILON * 2 ? value : NaN;
  }));

  return maskedData;
}
0reactions
zakjancommented, Nov 16, 2021

I think my issue is similar to @DanielJDufour’s issue. As fileDirectory.GDAL_NODATA is stored as ASCII text, is it possible that it is a GDAL bug (or a “feature”)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

gdal_translate 8bits (Byte format), how to handle nodata-values
This works fine but I get a lot of pixels which are rounded down (truncated) to 0, which is my nodata value, this...
Read more >
Replacing nodata values by a constant using GDAL CLI tools
But I always fear some glitches when copy-pasting such large numerical values, especially if they got rounded at some point. Is it safe...
Read more >
#7097 (Non-finite nodata values are getting clamped) – GDAL
they're specific, known values that can't be mathsed, rounded or otherwise munged. We've been using them without problems for several years for nodata...
Read more >
gdaldem — GDAL documentation
This command outputs a single-band raster with values computed from the elevation. Roughness is the largest inter-cell difference of a central pixel and...
Read more >
Loading Terrain Data and Making the Terrain Model
However, the data being imported must be in a gridded format, in order to be ... Tiled data uses less area of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found