go-pmtiles icon indicating copy to clipboard operation
go-pmtiles copied to clipboard

feature: patch header/metadata from JSON

Open bdon opened this issue 1 year ago • 11 comments

define a JSON schema like

{
  'tile_type':0,
  'metadata':{
    'my_key':'my_value'
  }
}

to allow modification of pmtiles by writing a new file.

pmtiles show --header-metadata-json would also be useful to output this.

bdon avatar Sep 04 '23 06:09 bdon

Is it always necessary to write to a new file? Given that PMTiles can become quite large, updating the metadata in place would be beneficial.

dvd3v avatar Sep 29 '23 13:09 dvd3v

Yes, same as flatgeobuf, parquet or video files, there is no extra space left in the file.

bdon avatar Sep 30 '23 01:09 bdon

@bdon Since you sort of mentioned it in https://github.com/protomaps/basemaps/issues/160#issuecomment-1784156935, it would be really handy if I just could push all my extra data into the metadata json in a simple way.

spatialillusions avatar Oct 29 '23 16:10 spatialillusions

the command would be something like pmtiles metadata FILE.pmtiles --write metadata.json where you provide whatever metadata.json you need.

pmtiles show --metadata FILE.pmtiles > metadata.json
pmtiles metadata FILE.pmtiles --write metadata.json # this is a noop

It would be fast+atomic but require temporary disk space as large as the new file, since it writes a completely new file.

bdon avatar Oct 30 '23 00:10 bdon

an open question is whether we ever want to expose the ability to modify the header (non-metadata parts) - I guess if you accidentally set the wrong bounds or tile type, or want to change the center position/zoom?

bdon avatar Oct 30 '23 00:10 bdon

I vote for just metadata for now. Maybe a pmtiles header XXXX command in the future for other parts of the header.

spatialillusions avatar Oct 30 '23 08:10 spatialillusions

Step one is making pmtiles show --metadata FILE write just the raw JSON to stdout:

https://github.com/protomaps/go-pmtiles/pull/98

bdon avatar Oct 31 '23 00:10 bdon

I have a question related to this -- Is it currently possible to add additional metadata to the output pmtiles file when running pmtiles convert input.mbtiles output.pmtiles?

If this is not currently possible, I assume this would be a bit easier than an in-place method that works against existing pmtiles files?

AndrewJDR avatar Feb 16 '24 09:02 AndrewJDR

(~~Incidentally, I'm not aware of any command line tool that can just patch the metadata of an existing mbtiles file, which would also solve this problem. If anyone is aware of something like this, please do let me know~~) Edit: I suppose the answer is to just use sqlite directly. Sorry for the slight thread hijacking. Disregard :D

AndrewJDR avatar Feb 16 '24 09:02 AndrewJDR

Yeah I would say use the sqlite3 CLI to modify the MBTiles. there's no equivalent with the pmtiles CLI yet.

bdon avatar Feb 16 '24 16:02 bdon

Needing this now, currently plan:

pmtiles show foo.pmtiles --header-json > header.json

Writes a JSON representation of the non-offset parts of the header to a file.

pmtiles show foo.pmtiles --metadata > metadata.json

Writes the JSON metadata to a file.

pmtiles write-header old.pmtiles header.json new.pmtiles (or maybe new.pmtiles first?)

Write the JSON representation of the header into a new archive. (maybe we need --inplace where it atomically deletes and renames?) All fields must be specified.

pmtiles write-metadata old.pmtiles metadata.json new.pmtiles (or maybe new.pmtiles first?)

Write the JSON representation of the header into a new archive. (maybe --inplace) ?

bdon avatar Mar 19 '24 05:03 bdon