Reputation: 1
I'm trying to use mercantile to display a tile from maptiler. However, it doesn't look like the tiles are lining up correctly.
I'm trying to pull the tile for -95.1017, 40.9778 using this:
tile = mercantile.tile(-95.1017, 40.9778, 12)
and I'm getting: Tile(x=965, y=1536, z=12)
but when I select the tile coordinates from maptiler on maptiler-osm-2020-02-10-v3.11-planet.mbtiles, I'm getting ocean. This should be pretty close to the center of the US.
I've tried reversing the lat/long, thinking I had them wrong. I've tried adjusting the lat/long by using the offset from the mbtiles metadata center, etc. I'm stumped at this point. Is there a way to adjust the 'center' for mercantile? Because I can't find one.
I've also tried morecantile, but that doesn't seem to be giving me anything better, or worse, depending on the zoom level it throws an error.
as above, and I expected to see something with features other than 'ocean'.
This following code is simplified as much as I can think to make it.
import sqlite3
import gzip
import io
import mercantile
import geopandas as gpd
conn = sqlite3.connect('/mnt/c/Users/dmars/Downloads/maptiler-osm-2020-02-10-v3.11-planet.mbtiles')
cursor = conn.cursor()
tile = mercantile.tile(-95.1017, 40.9778, 12)
cursor.execute(f"select images.tile_data, map.zoom_level, map.tile_column, map.tile_row, map.tile_id, map.grid_id from map, images where map.tile_column = {tile.y} and map.tile_row = {tile.y} and map.zoom_level = {tile.z} and images.tile_id = map.tile_id;")
blob = cursor.fetchone()
with io.BytesIO(blob[0]) as f:
with gzip.GzipFile(fileobj=f, mode='rb') as g:
decompressed = g.read()
print(type(decompressed))
with io.BytesIO(decompressed) as b:
gdf = gpd.read_file(b)
print(gdf)
Upvotes: 0
Views: 24