ARiisgaard / Thesis

0 stars 0 forks source link

Loading tiles from wrong zoom level #28

Open ARiisgaard opened 4 years ago

ARiisgaard commented 4 years ago

Currently the wrong tiles are being loaded - which I hadn't really been paying much attention to earlier, since the coloring so far have based on the right layer. This has changed now that the coloring is done based on loaded tiles instead of a pregenerated file.

I think the cause it the issue is the tiles and how they are being loaded. Currently I'm manually taking the resolution information i need from the xml file, that gdal2tiles.py product. In a perfect world I would use the GetCapabilities-function to automaticly get the metadata. However, this is not a perfect world, so the xml format that gdal2tiles produce is quite different from the data that GetCapabilites can accept. It complains about missing a layer identifier, but the two formats are so different that I think it also would complain, even a layer-information was added. The xml created by gdal2tiles can be seen in the bottom of the document.

This is what lead to the #24 issue. forEachTileCoord correctly knows which tiles currently should be loaded, but tileSource.url is asking for the wrong tiles. Therefore forEachTIleCoord couldn't be used for the coloring, since finding the maxValue by comparing the two datasets didn't result in anything (as the datasets were uncomparable due to the differences in zoom levels)

I can change the way tiles are being loaded, so that tiles from the correct zoom level are being loaded by changing the tile resolution to be calculated this instead of based on the tile-metadata:

const projectionExtent = projection.getExtent();
const size = ol.extent.getWidth(projectionExtent) / 256;
const resolutions = new Array(18);
const matrixIds = new Array(18);

// create matrix
for (z = 0; z < 18; ++z) {
  // generate resolutions and matrixIds arrays for this WMTS
  // eslint-disable-next-line no-restricted-properties
  resolutions[z] = size / Math.pow(2, (z + 1));
  matrixIds[z] = z;
}

The end result looks like this however: image

A possible solution would be to tinker with the xml file, so it aligns with the format, but that would be time consuming and I'm not sure it would work. So unless you have some good ideas up your sleeve I'm going to run a parallel tile-fetch to get the correct tiles for the coloring. This is not ideal (since it would double the amount of fetching), but it would give coloring based on the tiles from the right layer

XML from gdal2tiles:

<?xml version="1.0" encoding="UTF-8"?>

-<TileMap tilemapservice="http://tms.osgeo.org/1.0.0" version="1.0.0">

<Title>testRaster.tiff</Title>

<Abstract/>

<SRS>GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]</SRS>

<BoundingBox maxy="25.00000000000814" maxx="80.99999999999989" miny="19.00000000000815" minx="72.99999999999989"/>

<Origin y="19.00000000000815" x="72.99999999999989"/>

<TileFormat extension="tiff" mime-type="image/tiff" height="256" width="256"/>

-<TileSets profile="raster">

<TileSet order="0" units-per-pixel="0.03333333333333" href="0"/>

<TileSet order="1" units-per-pixel="0.01666666666667" href="1"/>

<TileSet order="2" units-per-pixel="0.00833333333333" href="2"/>

<TileSet order="3" units-per-pixel="0.00416666666667" href="3"/>

<TileSet order="4" units-per-pixel="0.00208333333333" href="4"/>

<TileSet order="5" units-per-pixel="0.00104166666667" href="5"/>

<TileSet order="6" units-per-pixel="0.00052083333333" href="6"/>

<TileSet order="7" units-per-pixel="0.00026041666667" href="7"/>

</TileSets>

</TileMap>
crstn commented 4 years ago

On the metadata issue: these are two different standards. Gdal2tiles produces metadata according to the OSGeo Tile Map Service Specification, but OpenLayers expects OGC WMTS metadata. This post might help with conversion if you want to go down that path. But I agree, the fastest hack is probably to fetch the tiles twice.