Skip to content

Instantly share code, notes, and snippets.

@vincentsarago
Created October 20, 2020 22:29
Show Gist options
  • Save vincentsarago/2a462882c34d7d33883cbcff66fe7ff4 to your computer and use it in GitHub Desktop.
Save vincentsarago/2a462882c34d7d33883cbcff66fe7ff4 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import mercantile\n",
"from io import BytesIO\n",
"import numpy"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"titiler_endpoint = \"https://api.cogeo.xyz\" # Devseed temporary endpoint\n",
"url = \"https://opendata.digitalglobe.com/events/mauritius-oil-spill/post-event/2020-08-12/105001001F1B5B00/105001001F1B5B00.tif\""
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"r = requests.get(f\"{titiler_endpoint}/cog/tilejson.json?url={url}\").json()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'tilejson': '2.2.0', 'name': '105001001F1B5B00.tif', 'version': '1.0.0', 'scheme': 'xyz', 'tiles': ['https://api.cogeo.xyz/cog/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=https%3A%2F%2Fopendata.digitalglobe.com%2Fevents%2Fmauritius-oil-spill%2Fpost-event%2F2020-08-12%2F105001001F1B5B00%2F105001001F1B5B00.tif'], 'minzoom': 10, 'maxzoom': 18, 'bounds': [57.664053823239804, -20.55473177712791, 57.84021477996238, -20.25261582755764], 'center': [57.75213430160109, -20.403673802342773, 10]}\n"
]
}
],
"source": [
"print(r)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"tiles = list(mercantile.tiles(*r[\"bounds\"], r[\"minzoom\"] + 2))"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"tile = tiles[0]\n",
"r = requests.get(f\"{titiler_endpoint}/cog/tiles/{tile.z}/{tile.x}/{tile.y}.npy?url={url}\")"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"arr = numpy.load(BytesIO(r.content))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"tile, mask = arr[0:-1], arr[-1]"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment