publiclab / mapknitter-exporter

The GDAL/ImageMagick-based exporter system from MapKnitter
GNU General Public License v3.0
5 stars 4 forks source link

TMS format generating only zoom 31 tiles #78

Closed jywarren closed 2 years ago

jywarren commented 2 years ago

Tiles seem individually OK in the new TMS exports - https://github.com/publiclab/mapknitter/pull/1548 and https://github.com/publiclab/mapknitter-exporter-sinatra/pull/134

https://storage.googleapis.com/mapknitter-exports-warps/1635967451/tms/31/1073743569/1073741840.png

image

But as you can see they're only generating zoom level 31. That's not right... here's the gdal2tiles command:

gdal2tiles.py -k --s_srs EPSG:3857 -t 1636041238 -g AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ public/warps/1636041238/1636041238.tif public/tms/1636041238/

What's going wrong? Testing in the sinatra app in GitPod...

jywarren commented 2 years ago

Hope to be able to fix this in https://github.com/publiclab/mapknitter-exporter/blob/c8ea1be6f94915c4c62c23788b249e1466c2d415/lib/exporter.rb#L289

jywarren commented 2 years ago

So we can force zoom levels with -z 4-22 for example, but they're all empty, so it somehow thinks these maps are really really tiny? zoom 32 is ridiculously small.

jywarren commented 2 years ago

We should check the zoom manually in... QGIS?

jywarren commented 2 years ago

Looks like the GeoTiff is wrong. It's a tiny speck near Null Island!

image

jywarren commented 2 years ago

Examining full export log: https://gist.github.com/jywarren/384ba5632ba8d90e7ab884fb30aa59b1

jywarren commented 2 years ago

So, up to the gdalwarp command, we seem OK - i checked those coordinates in this example:

image

gdalwarp -s_srs EPSG:3857 -te -71.4044638417 41.8194984457 -71.4029728831 41.8200378187 public/warps/1636053156/w312455.tif public/warps/1636053156/w312456.tif public/warps/1636053156/1636053156.tif

jywarren commented 2 years ago

working tifs are OK

image

public/warps/1636053156/w312455.tif

jywarren commented 2 years ago

So the compositing step would have to be the problem. What's wrong with this?

gdalwarp -s_srs EPSG:3857 -te -71.4044638417 41.8194984457 -71.4029728831 41.8200378187  public/warps/1636053156/w312455.tif public/warps/1636053156/w312456.tif public/warps/1636053156/1636053156.tif
Creating output file that is 627P x 227L.
Using band 4 of destination image as alpha.
Processing public/warps/1636053156/w312455.tif [1/2] : 0Using band 4 of source image as alpha.
...10...20...30...40...50...60...70...80...90...100 - done.
Processing public/warps/1636053156/w312456.tif [2/2] : 0Using band 4 of source image as alpha.
...10...20...30...40...50...60...70...80...90...100 - done.
jywarren commented 2 years ago

Resolving this will fix https://github.com/publiclab/mapknitter/issues/1343

jywarren commented 2 years ago

OK, would it work to run:

gdalwarp -s_srs EPSG:4326 -t_srs EPSG:4326 -te -71.4044638417 41.8194984457 -71.4029728831 41.8200378187  public/warps/1636053156/w312455.tif public/warps/1636053156/w312456.tif public/warps/1636053156/1636053156.tif

gdalwarp -s_srs EPSG:3857 -te -71.4044638417 41.8194984457 -71.4029728831 41.8200378187  public/warps/1636053156/w312455.tif public/warps/1636053156/w312456.tif public/warps/1636053156/1636053156.tif
jywarren commented 2 years ago

So just adding -t_srs EPSG:4326?

jywarren commented 2 years ago

THAT ALMOST WORKS!!!

It generates tiles like:

image

https://4567-silver-iguana-7u06ru3n.ws-us18.gitpod.io/tms/1636492035b/16/19769/41163.png

But actually OSM ID editor tries to fetch

https://4567-silver-iguana-7u06ru3n.ws-us18.gitpod.io/tms/1636492035b/16/19768/41163.png

Notice 19768 instead of 19769 ☹️

How are we off by one?!?!?!

jywarren commented 2 years ago

Could it be https://github.com/OSGeo/gdal/issues/3998 or https://github.com/OSGeo/gdal/issues/2463

jywarren commented 2 years ago

We should be able to test this with https://4567-silver-iguana-7u06ru3n.ws-us18.gitpod.io/tms/1636492035b/{z}/{x}/{-y}.png

jywarren commented 2 years ago
L.tileLayer('https://4567-silver-iguana-7u06ru3n.ws-us18.gitpod.io/tms/1636492035b/{z}/{x}/{-y}.png', {
    tms: true
}).addTo(map);
jywarren commented 2 years ago

/export?url=https://mapknitter.org/maps/pvdtest/warpables.json&scale=100

jywarren commented 2 years ago

OK, published the gem in https://github.com/publiclab/mapknitter-exporter/pull/79 - as 1.0.11, now moving to pull it into the Sinatra app at https://github.com/publiclab/mapknitter-exporter-sinatra/pull/144

jywarren commented 2 years ago

Done! Let's let sinatra apps reboot... then test at https://mapknitter.org/maps/pvdtest 👍

jywarren commented 2 years ago

OK, so the GeoTiff works with v1.0.11 of the gem

image

jywarren commented 2 years ago

So i think i may have made a mistake on the gdal2tiles step. Let's re-run it in Sinatra in gitpod.

https://github.com/publiclab/mapknitter-exporter/pull/79/files#diff-88ca6fff30cd420eda7ea254380019a208ebca72ed0541bb3eb04bb45c8ca1eeR289

Currently it has s_srs of 900915 but I think it should be 4326.

jywarren commented 2 years ago

OK, works in Leaflet now: image

jywarren commented 2 years ago

Works in Qgis!

image

OK, and in ID editor.

Now adding the quick link to open OpenStreetMap ID editor from the exports pane:

https://github.com/publiclab/mapknitter/commit/8e0c4923d21e3052832c8126dce91267378b72f3 https://github.com/publiclab/mapknitter/commit/6dfc357c85bd009d9128912db20f2f497f9e36e8

https://github.com/openstreetmap/iD/blob/25d4ff100fffd01df8e707aae7e1a1b9919239b9/API.md#url-parameters

should get us URLS in format

https://www.openstreetmap.org/edit#map=19/41.82003/-71.40364&background=custom:https://mapknitter-exports-warps.storage.googleapis.com/1637088561/tms/{z}/{x}/{-y}.png

jywarren commented 2 years ago

Fixed this now! All good.