protomaps / PMTiles

Cloud-optimized + compressed single-file tile archives for vector and raster maps
https://protomaps.com/docs/pmtiles/
BSD 3-Clause "New" or "Revised" License
2.02k stars 118 forks source link

pmtiles-convert index out of range error #13

Closed thisisaaronland closed 3 years ago

thisisaaronland commented 3 years ago

Before I start poking around in earnest I wanted to see whether this error was a "known-known" or otherwise something that you'd recognized faster than me.

The error is triggered by running a pmtiles-convert on a MBTiles database derived from the Geofabrik downloads, using tilemaker.

$> wget https://download.geofabrik.de/north-america/us/california/norcal-latest.osm.pbf

$> tilemaker --input norcal-latest.osm.pbf --output norcal-latest.mbtiles

$> pmtiles-convert norcal-latest.mbtiles norcal-latest.pmtiles
Traceback (most recent call last):
  File "/usr/local/bin/pmtiles-convert", line 49, in <module>
    result = writer.finalize(metadata)
  File "/usr/local/lib/python3.9/site-packages/pmtiles/writer.py", line 98, in finalize
    root = [(group[0],list(group[1])) for group in itertools.groupby(self.tiles,key=by_parent) if group[0][0] == 0][0]
IndexError: list index out of range
bdon commented 3 years ago

@thisisaaronland the MBTiles you've created only has zoom levels 12-14. IS this how you expect to use the tileset in the final product? Right now PMTiles assumes a complete pyramid (every tile that exists at Z+1 has a parent tile at Z in the tileset).

In any case, I think it won't be too hard to make the tool work with limited zoom tile sets. Looking into it now.

bdon commented 3 years ago

@thisisaaronland can you try python pmtiles version 0.0.6? Previously assumed at least one tile exists in the root directory, it now can be empty.

thisisaaronland commented 3 years ago

I can confirm that v0.0.6 does the right thing:

$> pmtiles-convert norcal-latest.mbtiles norcal-latest.pmtiles
Num tiles: 92300
Num unique tiles: 92241
Num leaves: 12

I was unaware that the MBTiles file was only Z12-14. I guess I missed something in the tilemaker documentation which would explain why when I load the norcal-latest.pmtiles with the example app in the go-http-protomaps package there is no map.

$> ./bin/example -protomaps-tile-url file:///usr/local/data/osm/norcal-latest.pmtiles
2021/05/19 11:27:05 Listening for requests on http://localhost:8080

Curiously, though when I zoom in to Z12-14 I see stuff like this:

Screen Shot 2021-05-19 at 11 28 25

I will try rebuilding the MBTiles database again and see if that fixes things. In the meantime is there an extra step necessary to ensure styling information is applied to a .pmtiles database?

bdon commented 3 years ago

That looks like there isn't any styling being applied to the data layers in the vector tileset. That information is defined as parameters to the LeafletLayer, or by default it uses this here (analogous to Tangram YAML or MapboxGL JSON styles):

https://github.com/protomaps/protomaps.js/blob/master/src/default_style/style.ts#L38

The default styles are specific to the layers and organization of features from protomaps.com , so those will need to be adapted to the specific tileset you are using which almost certainly has differently named and organized layers.