Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: pmtiles convert INPUT.mbtiles OUTPUT.pmtiles fails silently for MBTiles v 1.0 #167

Closed
mizmay opened this issue May 13, 2024 · 4 comments

Comments

@mizmay
Copy link

mizmay commented May 13, 2024

Problem

When trying to convert MBTiles created based on the 1.0 spec, such as in this repo, PMTiles are generated but won't display.

Explanation

MBTiles 1.0 spec did not include format among the top-level metadata. PMTiles relies on this field to determine whether the data is vector or raster, since this version only supported raster (jpg/png).

Potential fixes

  1. Can be fixed manually by adding name/value format/png to the metadata table of the MBTiles, convert operation will work as expected.

  2. Raising an error from the CLI and/or JS library to warn users the required metadata is missing to aid debugging

  3. Inferring format from other available metadata or the contents of the MBTiles

Additional Information

Repo that currently contains a bunch of MBTiles 1.0: https://github.com/mizmay/BerkeleyElectionResults

Sample (detailed) metadata for MBTiles 1.0 before adding the required format tag (note there is other non-required metadata available that could be used to resolve the value):

id: ElectionBerkeleyMeasureS
tile_info:
  format: png
  encoding: ''
tilejson:
  tilejson: 3.0.0
  tiles: []
  attribution: Stephanie May ~ mizmay.com
  bounds:
  - -122.3263
  - 37.8448
  - -122.2012
  - 37.9063
  center:
  - -122.2747
  - 37.8731
  - 13
  description: 'MEASURE S: "Shall an ordinance prohibiting sitting on sidewalks in commercial districts from 7:00 am to 10:00 pm, with exceptions for: (a) medical emergencies; (b) wheelchairs and similar mobility devices; (c) bus benches; (d) street events; (e) other furniture placed on the sidewalk pursuant to a permit; requiring the City to ensure that it is applied in a constitutional manner and requiring a warning prior to citation, be approved?" '
  legend: "<div class='my-legend'>\n<div class='legend-title'>Measure S - Berkeley, CA</div>\n<div class='legend-scale'>\n<div class='legend-subtitle'>Yes Votes</div>\n  <ul class='legend-labels'>\n    <li><span style='background:#FFFFB2;'></span>7 - 30%</li>\n    <li><span style='background:#FECC5C;'></span>31 - 40%</li>\n    <li><span style='background:#FD8D3C;'></span>41 - 50%</li>\n    <li><span style='background:#F03B20;'></span>51 - 60%</li>\n    <li><span style='background:#BD0026;'></span>61 - 100%</li>\n  </ul>\n<div class='legend-source'>Source: <a href=\"http://www.acgov.org/rov/current.htm\">Alameda County Registrar of Voters</a></div>\n</div>\n\n<style type='text/css'>\n  .wax-legends { \n    top:5px !important;\n    bottom: auto !important;\n    }\n  .wax-legend .legend-title {\n    text-align: left;\n    margin-bottom: 8px;\n    font-weight: bold;\n    font-size: 100%;\n    }\n  .wax-legend .legend-subtitle {\n    text-align: left;\n    margin-bottom: 3px;\n    font-weight: bold;\n    font-size: 85%;\n    }\n  .wax-legend .legend-text {\n    text-align: center;\n    margin-bottom: 6px;\n    font-size: 80%;\n    }\n  .wax-legend .legend-scale ul {\n    margin: 0;\n    padding: 0;\n    float: left;\n    list-style: none;\n    }\n  .wax-legend .legend-scale ul li {\n    display: block;\n    float: left;\n    width: 50px;\n    text-align: center;\n    font-size: 80%;\n    list-style: none;\n    }\n  .wax-legend ul.legend-labels li span {\n    display: block;\n    float: left;\n    height: 15px;\n    width: 50px;\n    }\n  .wax-legend .legend-source {\n    font-size: 70%;\n    color: #999;\n    clear: both;\n    }\n  .wax-legend a {\n    color: #777;\n    }\n</style"
  maxzoom: 16
  minzoom: 13
  name: Measure S - November 2012 Election - Berkeley, CA
  template: |-
    {{#__location__}}{{/__location__}}{{#__teaser__}}Precinct: <strong>{{{CPrecinct}}}</strong><br/>
    Yes Votes: <strong>{{{S_pct}}}%</strong><br/>
    <strong> {{{S_turnout}}}%</strong> of registered voters voted on Measure S.<br/>
    <style>
    .wax-tooltip {
      top: auto !important;
      bottom: 150px !important;
    }
    </style>{{/__teaser__}}{{#__full__}}Precinct: <strong>{{{CPrecinct}}}</strong><br/>
    Yes Votes: <strong>{{{S_pct}}}%</strong><br/>
    Registered Votors: <strong>{{{Registrati}}}</strong> <br/>
    Ballots Cast: <strong>{{{t_BallotsC}}}</strong><br/>
    Mail-in Votes: <strong>{{{m_MSVoted}}}</strong> <br/>
    Votes at Poll: <strong> {{{p_MSVoted}}} </strong><br/>
    Abstained on S: <strong>{{{t_MSNoVote}}}</strong><br/>
    <strong> {{{NoS_pct}}}%</strong> of voters skipped Measure S.<br/>


    <style>
    .wax-tooltip {
      top: auto !important;
      bottom: 150px !important;
    }
    </style>{{/__full__}}
  version: 1.0.0
@mizmay mizmay changed the title CLI: CLI: pmtiles convert INPUT.mbtiles OUTPUT.pmtiles fails silently for MBTiles v 1.0 May 13, 2024
@bdon
Copy link
Member

bdon commented May 14, 2024

MBTiles spec 1.1 and later have the format key: https://github.com/mapbox/mbtiles-spec/blob/master/1.1/spec.md

Because this is isolated to only 1.0, I am tempted to just detect version = 1.0 and exit with a suggestion of adding the metadata manually.

Other alternatives:

  • Use the tile_info key to derive png/jpg. If around the year 2011, the only program making MBTiles was TileMill, and it always added this key, maybe this is good enough?
  • Inspect the first tile in the tileset and sniff the PNG magic bytes to distinguish between jpeg/png - more annoying to implement

@prusswan
Copy link

Option to specify the format is better (out of all the supported image formats). In reality the spec could work with any format as long as the data is organized in the expected schema in a sqlite database.

@bdon bdon transferred this issue from protomaps/PMTiles May 28, 2024
@bdon
Copy link
Member

bdon commented May 28, 2024

Added a log message if no format metadata is detected in the MBTiles archive

@bdon
Copy link
Member

bdon commented May 28, 2024

Updated in 1.19.2

@bdon bdon closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants