geotiff.js icon indicating copy to clipboard operation
geotiff.js copied to clipboard

Issue of calling readRasters()

Open ukalpa opened this issue 2 years ago • 6 comments

I am trying to parse Geotiff data from SRTM (https://srtm.csi.cgiar.org/wp-content/uploads/files/srtm_5x5/TIFF/srtm_21_06.zip), I can get tiff and image object following the guide however it pops the below error message when calling readRasters, I appreciate for any suggestions.

Source Code:

const tiff = await GeoTIFF.fromUrl("srtm_21_06.tif");
const image = await tiff.getImage();
console.log(
    "GeoTIFF",
    image.getWidth(),
    image.getHeight(),
    image.getTileWidth(),
    image.getResolution(),
    image.getBoundingBox()
  );
const data = await image.readRasters();

Error Info: Screenshot from 2022-06-26 22-40-48

Screenshot from 2022-06-26 22-42-58

Screenshot from 2022-06-26 22-42-09

ukalpa avatar Jun 26 '22 10:06 ukalpa

Have you solved this problem? I also met

wukong-c avatar Jul 04 '22 10:07 wukong-c

I met the problem too

nitenzhao avatar Jul 05 '22 03:07 nitenzhao

+1

nadavpld avatar Sep 14 '22 18:09 nadavpld

+1

asukachiharu avatar Sep 19 '22 06:09 asukachiharu

Hi all,

I had a similar problem:

Failed to read from url or blob tracker_data/sea_ice_conc_6km_cog/asi-AMSR2-s6250-20230208-v5.4.tif TypeError: Cannot read properties of undefined (reading 'offset')
    at blockedsource.js:271:29
    at Array.map (<anonymous>)
    at BlockedSource.readSliceData (blockedsource.js:259:19)
    at BlockedSource.fetch (blockedsource.js:160:17)
    at async GeoTIFFImage.getTileOrStrip (geotiffimage.js:385:20)
    at async Promise.all (:3000/index 110)
    at async GeoTIFFImage._readRaster (geotiffimage.js:517:5)
    at async GeoTIFFImage.readRasters (geotiffimage.js:611:20)

I patched this problem for me by subtracting one from the high block id at line 262:

diff --git a/node_modules/geotiff/dist-module/source/blockedsource.js b/node_modules/geotiff/dist-module/source/blockedsource.js
index 5630efb..8099b16 100644
--- a/node_modules/geotiff/dist-module/source/blockedsource.js
+++ b/node_modules/geotiff/dist-module/source/blockedsource.js
@@ -262,7 +262,7 @@ export class BlockedSource extends BaseSource {
         top = Math.min(this.fileSize, top);
       }
       const blockIdLow = Math.floor(slice.offset / this.blockSize);
-      const blockIdHigh = Math.floor(top / this.blockSize);
+      const blockIdHigh = Math.floor((top-1) / this.blockSize);
       const sliceData = new ArrayBuffer(slice.length);
       const sliceView = new Uint8Array(sliceData);

I think when the requested slice was an exact number of blocks, it would give this error because it was trying to request one more block than needed.

Problematic file is at https://data.seaice.uni-bremen.de/amsr2/asi_daygrid_swath/s6250/2023/feb/Antarctic/asi-AMSR2-s6250-20230208-v5.4.tif

anton-seaice avatar Jun 16 '23 05:06 anton-seaice

+1

ericyoungberg avatar Jun 25 '23 10:06 ericyoungberg