feat(mbtiles): add Mbtiles::stream_coords and Mbtiles::stream_tiles#1847
Merged
CommanderStorm merged 12 commits intomaplibre:mainfrom May 24, 2025
Merged
feat(mbtiles): add Mbtiles::stream_coords and Mbtiles::stream_tiles#1847CommanderStorm merged 12 commits intomaplibre:mainfrom
Mbtiles::stream_coords and Mbtiles::stream_tiles#1847CommanderStorm merged 12 commits intomaplibre:mainfrom
Conversation
- [TileCoord::checked()] - [TileCoord::checked_inverted()]
- [Mbtiles::stream_tiles()] - streams tile coords + their data, and - [Mbtiles::stream_coords()] - only streams tile coords. By "streaming" I mean [futures::Stream] trait, aka "async iterator".
Contributor
Author
|
Ooops, using |
e2a80fe to
9393e94
Compare
CommanderStorm
requested changes
May 24, 2025
Member
CommanderStorm
left a comment
There was a problem hiding this comment.
I have attached two minor refactorings/renamings.
(this is a public api => naming is here important)
Comment on lines
352
to
373
| fn parse_tile_index(z: Option<i64>, x: Option<i64>, y: Option<i64>) -> Option<TileCoord> { | ||
| let z: u8 = z?.try_into().ok()?; | ||
| let x: u32 = x?.try_into().ok()?; | ||
| let y: u32 = y?.try_into().ok()?; | ||
| TileCoord::checked_inverted(z, x, y) | ||
| } | ||
|
|
||
| fn validate_tile_index( | ||
| z: Option<i64>, | ||
| x: Option<i64>, | ||
| y: Option<i64>, | ||
| filepath: &str, | ||
| ) -> MbtResult<TileCoord> { | ||
| parse_tile_index(z, x, y).ok_or_else(|| { | ||
| MbtError::InvalidTileIndex( | ||
| filepath.to_string(), | ||
| format!("{z:?}"), | ||
| format!("{x:?}"), | ||
| format!("{y:?}"), | ||
| ) | ||
| }) | ||
| } |
Member
There was a problem hiding this comment.
I don't quite like how this code snakes four functions deep, most of which are minimal code.
This is a bit unnecessary.
Lets inline these two at least:
validate_tile_indexchecked_inverted
Contributor
Author
There was a problem hiding this comment.
Fair points.
Let's get rid of checked_inverted().
But I didn't quite get it how you want me to inline validate_tile_index(). Should I duplicate error creation logic in both stream_tiles() and stream_coords()?
Co-authored-by: Frank Elsinga <frank@elsinga.de>
3d756b8 to
8acec4d
Compare
for more information, see https://pre-commit.ci
Mbtiles::stream_coords and Mbtiles::stream_tiles
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds two new methods to
Mbtilesstruct frommbtilescrate.Mbtiles::stream_coords()returns aStream(aka "async iterator") over all tile indexes in the database (TileCoordstruct).Mbtiles::stream_tiles()returns a stream over all tiles, i.e. both tile index and its data. A type aliaspub type Tile = (TileCoord, Option<Vec<u8>>)is introduced tomartin-tile-utilscrate.This allows us to efficiently iterate over all tiles in an
.mbtilesfile.Discussion of this feature is here.