Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockSize === null is correct? #371

Open
fornaeffe opened this issue Jul 5, 2023 · 0 comments
Open

blockSize === null is correct? #371

fornaeffe opened this issue Jul 5, 2023 · 0 comments

Comments

@fornaeffe
Copy link

fornaeffe commented Jul 5, 2023

I'm totally newbye, I found an unexpected behavior of geotiff.js, and I'm writing here just in case it is a true bug and not just some error I did in writing my code.

I was trying to fetch a GeoTIFF from WCS:

import { fromUrl  } from "geotiff";

const CRS = 'EPSG:32632'
const x = 580239
const y = 4917120
const width = 120
const height = 100
const mPerPixel = 20

let WCSurl = 'https://tinitaly.pi.ingv.it/TINItaly_1_1/wcs?' +
    'SERVICE=WCS' +
    '&VERSION=1.0.0' +
    '&REQUEST=GetCoverage' +
    '&FORMAT=GeoTIFF' +
    '&COVERAGE=TINItaly_1_1:tinitaly_dem' +
    '&BBOX=' + [(x - width / 2 * mPerPixel),(y - height / 2 * mPerPixel),(x + width / 2 * mPerPixel),(y + height / 2 * mPerPixel)].join(',') +
    '&CRS=' + CRS +
    '&RESPONSE_CRS=' + CRS +
    '&WIDTH='+ width +
    '&HEIGHT=' + height

async function loadDEM() {
    const myGeoTIFF = await fromUrl(WCSurl)
    const myGeoTIFFImage = await myGeoTIFF.getImage()
    const myRaster = await myGeoTIFFImage.readRasters()
    console.log(myRaster)
}

But I got an error:

Uncaught (in promise) AggregateError: Request failed
at BlockedSource.fetch (blockedsource.js:153:1)
at async GeoTIFF.fromSource (geotiff.js:547:1)

Trying to debug, I noticed that in the function maybeWrapInBlockedSource (remote.js line 153), blockSize is undefined (correctly, I think, because I did not specified blocksize), but when the function compares it with null (blockSize === null) it returns false, and the function returns a new BlockedSource instead of the source itself.

When the server returns a full file instead of a block, the subsequent functions throw errors.

I resolved by adding the option allowFullFile = true, but I think it's unintuitive to have to add it in such a case... Maybe the test blockSize === null should have returned true even if blockSize is undefined? (something like blockSize == null?)

async function loadDEM() {
    const myGeoTIFF = await fromUrl(WCSurl, {allowFullFile: true})
    const myGeoTIFFImage = await myGeoTIFF.getImage()
    const myRaster = await myGeoTIFFImage.readRasters()
    console.log(myRaster)
}

Edit: I'm using GeoTIFF 2.0.7, webpack 5.88.1, typescript 5.1.6 and Chrome 114.0.5735.199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant