Hi,

I'm trying to read a Sentinel TIFF image using GeoTiffReader and 
CogSourceSPIProvider. I've gotten the url's from a STAC and the url for the 
visual asset is working fine. The problem is when I try to read a single band. 
In this case B04. The error I get is "Bad value for bits!". After some 
debugging I see that the number of bits is 15.

Here is the stack trace:

java.lang.RuntimeException: Couldn't read url: 
https://sentinel2l2a01.blob.core.windows.net/sentinel2-l2/32/V/PM/2025/08/19/S2C_MSIL2A_20250819T104041_N0511_R008_T32VPM_20250819T155312.SAFE/GRANULE/L2A_T32VPM_A004983_20250819T104040/IMG_DATA/R10m/T32VPM_20250819T104041_B04_10m.tif
        at no.roarbra.PlanetaryCogReader.openReader(PlanetaryCogReader.java:70)
        at no.roarbra.SentinelViewer.main(SentinelViewer.java:21)
Caused by: org.geotools.api.data.DataSourceException: Bad value for bits!
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:281)
        at no.roarbra.PlanetaryCogReader.openReader(PlanetaryCogReader.java:68)
        ... 1 more
Caused by: org.geotools.api.data.DataSourceException: Bad value for bits!
        at 
org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:549)
        at org.geotools.gce.geotiff.GeoTiffReader.<init>(GeoTiffReader.java:268)
        ... 2 more
Caused by: java.lang.IllegalArgumentException: Bad value for bits!
        at 
java.desktop/javax.imageio.ImageTypeSpecifier$Grayscale.<init>(ImageTypeSpecifier.java:584)
        at 
java.desktop/javax.imageio.ImageTypeSpecifier.createGrayscale(ImageTypeSpecifier.java:685)
        at 
it.geosolutions.imageio.plugins.tiff.TIFFDecompressor.getRawImageTypeSpecifier(TIFFDecompressor.java:1260)
        at 
it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReader.getImageTypes(TIFFImageReader.java:1365)
        at 
org.geotools.gce.geotiff.GeoTiffReader.getHRInfo(GeoTiffReader.java:368)
        ... 3 more

And this is part of my code (the exception is at the last line):

String token = readToken();
URL imageUrl = new URI(assetUrl + "?" + token).toURL();
HttpRangeReader rangeReader = new HttpRangeReader(imageUrl.toURI(), 
CogImageReadParam.DEFAULT_HEADER_LENGTH);
CogSourceSPIProvider input = new CogSourceSPIProvider(new 
BasicAuthURI(imageUrl, false), 
                                                                                
new CogImageReaderSpi(),
                                                                                
new CogImageInputStreamSpi(), 
                                                                                
rangeReader.getClass().getName());
return new GeoTiffReader(input, new Hints(Hints.SKIP_EXTERNAL_OVERVIEWS, true));

Best regards,
Roar Brænden

_______________________________________________
GeoTools-GT2-Users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to