0

I am reading a EU-DEM v1.1 geotiff file downloaded from copernicus website using geotiff.js package with the following code :

        const geo = await fromFile(this.demFileUrl);

        const image = await geo.getImage();

        const bbox = image.getBoundingBox();

        this.heightMatrixProps.pixel_width = image.getWidth();
        this.heightMatrixProps.pixel_height = image.getHeight();
        this.heightMatrixProps.bbox_width = bbox[2] - bbox[0];
        this.heightMatrixProps.bbox_height = bbox[3] - bbox[1];
        this.heightMatrixProps.bbox_0 = bbox[0];
        this.heightMatrixProps.bbox_1 = bbox[1];

        const pool = new Pool();
        const rasterData = (await image.readRasters({ pool: pool }))[0] as TypedArray;

        this.heightMatrix = new Array(image.getHeight());
        for (var j = 0; j < image.getHeight(); j++) {
            this.heightMatrix[j] = new Array(image.getWidth());
            for (var i = 0; i < image.getWidth(); i++) {
                this.heightMatrix[j][i] = rasterData[i + j * image.getWidth()];
            }
        }

According to the metadata provided the pixel resolution is 25m (i.e. each pixel is 25m x 25m).

After reading the file I am running bresenham's circle drawing algorithm in order to draw a circular "height map". After few iterations, I have noticed that the circle is not a circle...

I than proceeded to check the distance from neighboring pixels in the height matrix :

        const widthPct = (from.longitude - this.heightMatrixProps.bbox_0) / this.heightMatrixProps.bbox_width;
        const heightPct = (from.latitude - this.heightMatrixProps.bbox_1) / this.heightMatrixProps.bbox_height;
        const xPx = Math.floor(this.heightMatrixProps.pixel_width * widthPct);
        const yPx = Math.floor(this.heightMatrixProps.pixel_height * (1 - heightPct));

        const pointY = this.translateXYtoCoordinates([xPx, yPx + 1]);
        const pointX = this.translateXYtoCoordinates([xPx + 1, yPx]);

        console.log(getDistance({latitude: pointY[0], longitude: pointY[1]}, {latitude: from.latitude, longitude: from.longitude}));
        console.log(getDistance({latitude: pointX[0], longitude: pointX[1]}, {latitude: from.latitude, longitude: from.longitude}));

The above logged 25 for the distance in the Y direction and 12 for the X direction.

*getDistance function from geolib package.

How come the height matrix has a resolution of 25m x 12m ?

New contributor
Nadav Peled is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • What's projection is it in?
    – Ian Turton
    Sep 23 at 18:52

0

Your Answer

Nadav Peled is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.