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

Did not receive an init message from worker after 10000ms

Open DailisLangovskis opened this issue 4 years ago • 10 comments

I am trying to use Pool() class to split the work between the workers, when parsing GeoTIFF, but I get this error.

Working with typescript syntax in angular project. Mainly the code is copied from Webraster

Goal is to parse geotiff to an image, so it can be used as ImageStatic for Openlayers ImageLayer and displayed on the map.

My code snippet ->

import {Pool, fromBlob, fromUrl} from 'geotiff';

  async loadGeotiffData(dataSouce: string | File): Promise<any> {
    try {
      let tiff;
      const pool = new Pool();
      const tiff = await fromBlob(dataSouce));
      const image = await tiff.getImage();
      const rawBox = image.getBoundingBox();
      const box = [
        rawBox[0],
        rawBox[1] - (rawBox[3] - rawBox[1]),
        rawBox[2],
        rawBox[1],
      ];

      const bands = await image.readRasters({
        pool,
      });
      const the_canvas = document.createElement('canvas'); 
      const minValue = 200; //Math.min.apply(Math,bands[0]);
      const maxValue = 1200; //Math.max.apply(Math,bands[0]);
      const plot = new plotty.plot({
        canvas: the_canvas,
        data: bands[0],
        width: image.getWidth(),
        height: image.getHeight(),
        domain: [minValue, maxValue],
        colorScale: 'earth',
        clampLow: true,
        clampHigh: true,
      });
      plot.render();
      this.imgSource = new ImageStatic({
        url: the_canvas.toDataURL('image/png'),
        imageExtent: box,
        projection: 'EPSG:4326', //to enable on-the-fly raster reprojection
      });
      this.hsAddDataCommonUrlService.loadingInfo = false;
      return;
    } catch (error) {
      this.throwParsingError(error.message);
      return;
    }
  }

Also when I was trying to readRasters using option bbox[], app responded with erorr -> Array buffer allocation failed

Would appreciate some help and information what I am doing wrong!

DailisLangovskis avatar Oct 07 '21 11:10 DailisLangovskis

Hi @DailisLangovskis

It seems like the error message is missing in your report. Could you maybe add that to the description again?

Regarding your script: this seems fine as far as I can see.

Regarding the bbox error: this is internally translated to pixel coordinates, from which region of the image the data is read and a buffer is prepared in the size requested. A typical error is when the bbox is expressed in a different coordinate system (i.e: meters instead of degrees) which causes a huge buffer allocation which in turn fails. So, typically, when the bbox is inside of your image bounds (and expressed in the same CRS) and your image is reasonably sized you should not have any problems.

Another thing you can do is to fix your width/height or specify a resolution in order to reduce the size of the result of readRasters.

constantinius avatar Oct 07 '21 12:10 constantinius

Hi @DailisLangovskis

It seems like the error message is missing in your report. Could you maybe add that to the description again?

Regarding your script: this seems fine as far as I can see.

Regarding the bbox error: this is internally translated to pixel coordinates, from which region of the image the data is read and a buffer is prepared in the size requested. A typical error is when the bbox is expressed in a different coordinate system (i.e: meters instead of degrees) which causes a huge buffer allocation which in turn fails. So, typically, when the bbox is inside of your image bounds (and expressed in the same CRS) and your image is reasonably sized you should not have any problems.

Another thing you can do is to fix your width/height or specify a resolution in order to reduce the size of the result of readRasters.

Oh, sorry, this is the error, regarding Pool - error

Ahh, just noticed that I need to install the threads-plugin, to make it work, but I wasn't successful anyway.

DailisLangovskis avatar Oct 07 '21 12:10 DailisLangovskis

@constantinius I tried using ->

const bands = await image.readRasters({ width, height, resX: 0.1, resY: 0.1});

Where ->

  const width = Math.ceil(image.getWidth() / 10);
  const height = Math.ceil(image.getHeight() / 10);

But still got the error -> err

DailisLangovskis avatar Oct 07 '21 13:10 DailisLangovskis

Okay, the error message indicates that the error is not due to the output size (also width/height are conflicting with resX/resY) but with decompression. Could you provide access to that image? Or show image metadata?

constantinius avatar Oct 07 '21 18:10 constantinius

image-obj tiff-obj

DailisLangovskis avatar Oct 07 '21 19:10 DailisLangovskis

Hm, looks solid to me. The reported compression method (8 means Adobe deflate) is supported and has worked without a problem. Could you try to convert the file to another compression using GDAL? e.g packbits?

constantinius avatar Oct 08 '21 09:10 constantinius

Hm, looks solid to me. The reported compression method (8 means Adobe deflate) is supported and has worked without a problem. Could you try to convert the file to another compression using GDAL? e.g packbits?

I will try to do so and post afterwards!

DailisLangovskis avatar Oct 10 '21 18:10 DailisLangovskis

@constantinius Hey, I used gdal_translate -co compress=lzw -co tiled=yes before.tiff after.tiff, which gave me output of ->

ERROR 1: PROJ: proj_create_from_name: Cannot find proj.db
0...10...20...30...40...50...60...70...80...90...100 - done.

When I was trying to add it to my code, it gave me the same error of -> Array buffer allocation failed. Image compression method was 5 now inside the image object, so it was compressed to LZW. Execution was the same as in the previous code, except I kept only width and height options for readRasters method. Couldn't compress to packbits, due to ->

ERROR 1: TIFFAppendToStrip:Maximum TIFF file size exceeded. Use BIGTIFF=YES creation option.
ERROR 1: TIFFAppendToStrip:Maximum TIFF file size exceeded. Use BIGTIFF=YES creation option.

I -co bigtiff=yes was added, the tiff size was 7 GB. I am new to geotiff, so I don't know it that is right or not.

DailisLangovskis avatar Oct 11 '21 09:10 DailisLangovskis

Hello, has any one come across a similar issue, i am having with reading the raster data from geotiff file?

DailisLangovskis avatar Oct 14 '21 13:10 DailisLangovskis

Did you resolve this? I am seeing the same error. "Did not receive an init message from worker after 10000ms" When I try to view my cloud optimised geotiff using COG-Explorer I created it like this. docker run --rm -it -v "d:\cog":/cog osgeo/gdal:ubuntu-small-latest gdal_translate input.tif tiled.tiff -of COG -co COMPRESS=LZW

The TIFF is here https://d35ibmkglja508.cloudfront.net/tiled.tiff

gcoleman72 avatar Jul 07 '22 03:07 gcoleman72