NumpyTile
In [ ]:
Copied!
# Uncomment this line if you need to install the dependencies
# !pip install numpy mercantile
# Uncomment this line if you need to install the dependencies
# !pip install numpy mercantile
In [ ]:
Copied!
import httpx
import mercantile
from io import BytesIO
import numpy
%pylab inline
import httpx
import mercantile
from io import BytesIO
import numpy
%pylab inline
In [ ]:
Copied!
titiler_endpoint = "https://titiler.xyz" # Developmentseed Demo endpoint. Please be kind.
url = "https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif"
titiler_endpoint = "https://titiler.xyz" # Developmentseed Demo endpoint. Please be kind.
url = "https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif"
In [ ]:
Copied!
r = httpx.get(f"{titiler_endpoint}/cog/WebMercatorQuad/tilejson.json?url={url}").json()
print(r)
r = httpx.get(f"{titiler_endpoint}/cog/WebMercatorQuad/tilejson.json?url={url}").json()
print(r)
In [ ]:
Copied!
# Get a list of tiles for minzoom + 2
tiles = list(mercantile.tiles(*r["bounds"], r["minzoom"] + 2))
# Get a list of tiles for minzoom + 2
tiles = list(mercantile.tiles(*r["bounds"], r["minzoom"] + 2))
In [ ]:
Copied!
# Call TiTiler endpoint using the first tile
tile = tiles[0]
r = httpx.get(f"{titiler_endpoint}/cog/tiles/WebMercatorQuad/{tile.z}/{tile.x}/{tile.y}.npy?url={url}")
# Call TiTiler endpoint using the first tile
tile = tiles[0]
r = httpx.get(f"{titiler_endpoint}/cog/tiles/WebMercatorQuad/{tile.z}/{tile.x}/{tile.y}.npy?url={url}")
In [ ]:
Copied!
# Load result using numpy.load
arr = numpy.load(BytesIO(r.content))
print(type(arr))
print(arr.shape)
# Load result using numpy.load
arr = numpy.load(BytesIO(r.content))
print(type(arr))
print(arr.shape)
In [ ]:
Copied!
# By default we put the data and the mask in the same array
tile, mask = arr[0:-1], arr[-1]
# By default we put the data and the mask in the same array
tile, mask = arr[0:-1], arr[-1]
In [ ]:
Copied!
print(tile.shape)
print(tile.shape)
In [ ]:
Copied!
print(mask.shape)
print(mask.shape)
In [ ]:
Copied!