protomaps / go-pmtiles

Single-file executable tool for working with PMTiles archives
https://docs.protomaps.com/pmtiles/cli
BSD 3-Clause "New" or "Revised" License
377 stars 51 forks source link

Unusable pmtiles file generated if source mbtiles file has no metadata #60

Closed russss closed 1 year ago

russss commented 1 year ago

I think if you use the pmtiles command line tool to convert an mbtiles into a pmtiles file, and the mbtiles doesn't have bounds/center metadata, then you get a successfully-generated pmtiles file which the JS library (at least) will silently ignore.

I'm 80% sure this is what's happening, but I don't have the time to dig into the code to confirm at the moment (sorry).

bdon commented 1 year ago

Can you share the mbtiles file?

Is it possible that the center/bounds are defaulting to the world and it just not visible at the scale when loaded in JS?

russss commented 1 year ago

I dug into this a bit more, hopefully this explains it better:

  1. I created an .mbtiles file from a bunch of pbf files using mb-util. There was no metadata file included, so the metadata table in the resulting mbtiles database was empty.
  2. I created a .pmtiles file from this .mbtiles file, which results in the pmtiles file having a value of 0 for all the bounds. (Full pmtiles show output included below.)
  3. I try to display this pmtiles file in maplibre-js. MapLibre won't try and fetch tiles if they're outside the source's bounding box, and the pmtiles provider uses the bounds from the header of the pmtiles file, so the bounding box is [0,0,0,0], which results in the pmtiles file being silently ignored.

I'd suggest that the pmtiles command should refuse to create files with an invalid bounding box such as this, or at least issue a warning. I'd also suggest that the JS library should probably issue a warning if the pmtiles file has an invalid bounding box.

Result of `pmtiles show` ``` $ pmtiles show ./buildmap-nometadata.pmtiles pmtiles spec version: 3 total size: 24 MB tile type: Unknown bounds: 0.000000,0.000000 0.000000,0.000000 min zoom: 7 max zoom: 20 center: 0.000000,0.000000 center zoom: 7 addressed tiles count: 12946 tile entries count: 8418 tile contents count: 5367 clustered: true internal compression: 2 tile compression: 0 ```
bdon commented 1 year ago

We can either

1) error out when the bounds is invalid - has an area or 0, or the min is greater than max, out of the coordinate system, etc 2) detect the error cases but default the bounds to -180,-90,180,90.

I have a slight preference for 2 because the MBTiles spec uses the SHOULD language (a valid bounds is not a hard requirement)

bdon commented 1 year ago

opened a PR: https://github.com/protomaps/go-pmtiles/pull/77

bdon commented 1 year ago

@russss this should be resolved by https://github.com/protomaps/go-pmtiles/releases/tag/v1.10.0 which will fail if a zero-area bounds is passed, but accept no bounds. Please re-open if this is still an issue!