geosolutions-it / imageio-ext

Additional plugins and extension for the standard Java ImageIO library
Other
147 stars 84 forks source link

NFE: For input string: "-3,4028230607370965e+038" #248

Open jandam opened 3 years ago

jandam commented 3 years ago

I have GeoTIFF with malformed NO_DATA_VALUE. It was created with Slovak (same for Czech) locale - non standard decimal separator. It would be nice to support correct parsing. Reading such GeoTIFF should not fail.

Fix: for malformed value set noData to null.

if ("nan".equalsIgnoreCase(value)) {
    noData = Double.NaN;
} else {
   try {
       noData = Double.parseDouble(value);
    } catch(NumberFormatException e) {
       try {
         noData = Double.parseDouble(value.replace(',', '.');
        } catch(NumberFormatException ignored) {
         noData = null;
        } 
     }
}

java.lang.NumberFormatException: For input string: "-3,4028230607370965e+038" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110) at java.lang.Double.parseDouble(Double.java:538) at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.initializeFromMetadata(TIFFImageReader.java:1290) at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.seekToImage(TIFFImageReader.java:831) at it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getImageMetadata(TIFFImageReader.java:1442) at com.crcdata.nosql.core.io.format.geotiff.GeoTiffReaderBuilder$PathReader.read(GeoTiffReaderBuilder.java:356) at com.crcdata.nosql.core.execute.ExecBatchScan.doExecute(ExecBatchScan.java:41) ... 24 more

jandam commented 2 years ago

Utility 'gdalinfo' reports correct no data value ... Band 1 Block=128x128 Type=Float32, ColorInterp=Gray NoData Value=-3.40282306073709653e+38 ...