[GIS] Displaying map tiles from GeoPackage

coordinate systemgeopackagetilestiling-scheme

Is it possible to translate tile requests from a mapping engine wanting Google Map style tiles into tile requests from a geopackage file? If not, where can I find information about how to create a mapping engine that handles the dizzying array of options provided by geopackage (as in, something that would help with understanding how to use srid, min_x, pixel_x_size, tile_width, matrix_width, zoom_level, and screen coords to determine which tiles at which rotation displayed where)

I have used MBTiles in the past to supply tiles to a mapping engine that requested tiles in Google Map style. This worked well as MBTiles uses the same projection and uses TMS for the tiling scheme. This meant I only needed to modify the y value of each request to translate from TMS to Google Maps style.

Two of the problems that I am having trouble figuring out how to overcome in regards to translating google maps tile requests to a specific tile in geopackage is how to handle the potential difference in projection, and how to handle the difference in origin. (By difference in origin I mean Google maps starts 0,0 at the top left corner of the world (because it assumes the whole world has data), whereas geopackage starts at the top left of the data (which might be the whole world but likely will not be))

If it makes any difference I am trying to do this in C++ using Qt and QtLocation.

Best Answer

As of Jan 2015, I'm not aware of any open source implementation that fully supports every possible option in geopackage. The spec is authoritative (but likely to be updated) for implementation, so if you want to (or really don't want to, but still have to) write your own map engine, work from that. Look for a sane subset/profile, rather than trying to do it all. For example, choose to only support power-of-two zoom.

If you're able to constrain the problem a bit, the GDAL and spatialite implementations might work for you - both can give back tiles or composite images for a given area. Given your comment about iOS support, spatialite may be difficult. I don't have experience with GDAL on iOS. Those are both open source and can provide examples for how you might do a similar implementation. Even Rouault's blog entry on GeoPackage might also prove useful to either use GDAL or implement something similar.

Given arbitrary SRID, you'd need some way to either reproject the data you want to overlay on the map, or reproject the geopackage rasters and vectors, or both. That is usually proj.4 (used within both GDAL and spatialite, as well as many other tools), which is workable on Android. I can't say how hard it is on iOS.

Correction: GeoPackage origin is still (0,0) but there is no promise that there is any data at that position at any zoom level. The spec says "The tile coordinate (0,0) always refers to the tile in the upper left corner of the tile matrix at any zoom level, regardless of the actual availability of that tile." Actually, there is no promise there is data at any other position - the matrix is allowed to be empty. The background to this decision is to be able to add tiles later. What is allowed to occur though is that the (potentially empty) nominal bounding box in gpkg_tile_matrix_set doesn't need to be the whole world - it is the exact bounds for what might ever be filled in. Consider that a SRID like a UTM zone doesn't make sense to have "whole world" extent.

Related Question