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

feature: patch header/metadata from JSON #63

Open
bdon opened this issue Sep 4, 2023 · 11 comments
Open

feature: patch header/metadata from JSON #63

bdon opened this issue Sep 4, 2023 · 11 comments

Comments

@bdon
Copy link
Member

bdon commented Sep 4, 2023

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.

@dvd3v
Copy link

dvd3v commented Sep 29, 2023

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.

@bdon
Copy link
Member Author

bdon commented Sep 30, 2023

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

@spatialillusions
Copy link

@bdon Since you sort of mentioned it in protomaps/basemaps#160 (comment), it would be really handy if I just could push all my extra data into the metadata json in a simple way.

@bdon
Copy link
Member Author

bdon commented Oct 30, 2023

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
Copy link
Member Author

bdon commented Oct 30, 2023

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?

@spatialillusions
Copy link

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

@bdon
Copy link
Member Author

bdon commented Oct 31, 2023

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

#98

@AndrewJDR
Copy link

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
Copy link

AndrewJDR commented Feb 16, 2024

(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

@bdon
Copy link
Member Author

bdon commented Feb 16, 2024

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

@bdon
Copy link
Member Author

bdon commented Mar 19, 2024

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 added a commit that referenced this issue Mar 19, 2024
* add new CLI commands for writing header and metadata (stubs)
bdon added a commit that referenced this issue Sep 15, 2024
* add new CLI commands for writing header and metadata (stubs)
bdon added a commit that referenced this issue Sep 15, 2024
Print a JSON representation of part of the header [#63]
* refactor show to take io.Writer instead of os.Stdout
* add integration test for Show command
* hide write command as it's not implemented yet.
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

4 participants