Created
May 24, 2023 02:38
-
-
Save emileten/030b52e057ff0da9d48a5671e97f5688 to your computer and use it in GitHub Desktop.
test-titiler-pgstac
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
{ | |
"cells": [ | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## titiler.PgSTAC Demo\n", | |
"\n", | |
"This Notebook aims to show the different features provided by titiler.pgstac application\n", | |
"\n", | |
"In order to run this demo you'll need to have a PgSTAC database and the titiler.pgstac application running. The easiest way to launch them is to use the repo's docker-compose.yml\n", | |
"\n", | |
"```\n", | |
"docker-compose up tiler\n", | |
"```\n", | |
"\n", | |
"\n", | |
"### Python requirements\n", | |
"\n", | |
"```\n", | |
"pip install httpx folium pypgstac\n", | |
"```\n", | |
"\n", | |
"### Populate the PgSTAC db with data \n", | |
"\n", | |
"```\n", | |
"$ pypgstac load collections tests/fixtures/noaa-emergency-response.json --dsn postgresql://username:password@localhost:5439/postgis --method insert \n", | |
"$ pypgstac load items tests/fixtures/noaa-eri-nashville2020.json --dsn postgresql://username:password@localhost:5439/postgis --method insert\n", | |
"```\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'database_online': True}\n" | |
] | |
} | |
], | |
"source": [ | |
"import json\n", | |
"import httpx\n", | |
"from folium import Map, TileLayer, GeoJson\n", | |
"import requests\n", | |
"\n", | |
"from geojson_pydantic import Feature, Polygon\n", | |
"\n", | |
"endpoint = \"https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com\"\n", | |
"\n", | |
"print(requests.get(f\"{endpoint}/healthz\").json())" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe srcdoc=\"<!DOCTYPE html>\n", | |
"<html>\n", | |
"<head>\n", | |
" \n", | |
" <meta http-equiv="content-type" content="text/html; charset=UTF-8" />\n", | |
" \n", | |
" <script>\n", | |
" L_NO_TOUCH = false;\n", | |
" L_DISABLE_3D = false;\n", | |
" </script>\n", | |
" \n", | |
" <style>html, body {width: 100%;height: 100%;margin: 0;padding: 0;}</style>\n", | |
" <style>#map {position:absolute;top:0;bottom:0;right:0;left:0;}</style>\n", | |
" <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>\n", | |
" <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>\n", | |
" <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>\n", | |
" <script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"/>\n", | |
" <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css"/>\n", | |
" <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css"/>\n", | |
" \n", | |
" <meta name="viewport" content="width=device-width,\n", | |
" initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n", | |
" <style>\n", | |
" #map_e2cfbaf9160fc729e6b574855acd9c35 {\n", | |
" position: relative;\n", | |
" width: 100.0%;\n", | |
" height: 100.0%;\n", | |
" left: 0.0%;\n", | |
" top: 0.0%;\n", | |
" }\n", | |
" .leaflet-container { font-size: 1rem; }\n", | |
" </style>\n", | |
" \n", | |
"</head>\n", | |
"<body>\n", | |
" \n", | |
" \n", | |
" <div class="folium-map" id="map_e2cfbaf9160fc729e6b574855acd9c35" ></div>\n", | |
" \n", | |
"</body>\n", | |
"<script>\n", | |
" \n", | |
" \n", | |
" var map_e2cfbaf9160fc729e6b574855acd9c35 = L.map(\n", | |
" "map_e2cfbaf9160fc729e6b574855acd9c35",\n", | |
" {\n", | |
" center: [0.0, 0.0],\n", | |
" crs: L.CRS.EPSG3857,\n", | |
" zoom: 2,\n", | |
" zoomControl: true,\n", | |
" preferCanvas: false,\n", | |
" }\n", | |
" );\n", | |
"\n", | |
" \n", | |
"\n", | |
" \n", | |
" \n", | |
" var tile_layer_543e8609402a79d9d47486bbd42de9d8 = L.tileLayer(\n", | |
" "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",\n", | |
" {"attribution": "Data by \\u0026copy; \\u003ca target=\\"_blank\\" href=\\"http://openstreetmap.org\\"\\u003eOpenStreetMap\\u003c/a\\u003e, under \\u003ca target=\\"_blank\\" href=\\"http://www.openstreetmap.org/copyright\\"\\u003eODbL\\u003c/a\\u003e.", "detectRetina": false, "maxNativeZoom": 18, "maxZoom": 18, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}\n", | |
" ).addTo(map_e2cfbaf9160fc729e6b574855acd9c35);\n", | |
" \n", | |
" \n", | |
" function geo_json_7873c6442da20b1540d9e571b81ce968_styler(feature) {\n", | |
" switch(feature.id) {\n", | |
" default:\n", | |
" return {"dashArray": "1", "fillOpacity": 0, "opacity": 1, "weight": 1};\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" function geo_json_7873c6442da20b1540d9e571b81ce968_onEachFeature(feature, layer) {\n", | |
" layer.on({\n", | |
" });\n", | |
" };\n", | |
" var geo_json_7873c6442da20b1540d9e571b81ce968 = L.geoJson(null, {\n", | |
" onEachFeature: geo_json_7873c6442da20b1540d9e571b81ce968_onEachFeature,\n", | |
" \n", | |
" style: geo_json_7873c6442da20b1540d9e571b81ce968_styler,\n", | |
" });\n", | |
"\n", | |
" function geo_json_7873c6442da20b1540d9e571b81ce968_add (data) {\n", | |
" geo_json_7873c6442da20b1540d9e571b81ce968\n", | |
" .addData(data)\n", | |
" .addTo(map_e2cfbaf9160fc729e6b574855acd9c35);\n", | |
" }\n", | |
" geo_json_7873c6442da20b1540d9e571b81ce968_add({"features": [{"geometry": {"coordinates": [[[-180.0, -90.0], [180.0, -90.0], [180.0, 90.0], [-180.0, 90.0], [-180.0, -90.0]]], "type": "Polygon"}, "id": "0", "type": "Feature"}], "type": "FeatureCollection"});\n", | |
"\n", | |
" \n", | |
"</script>\n", | |
"</html>\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>" | |
], | |
"text/plain": [ | |
"<folium.folium.Map at 0x10ee1c0a0>" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# bounds of an item\n", | |
"bounds = (-180, -90, 180, 90)\n", | |
"\n", | |
"poly = Polygon.from_bounds(*bounds)\n", | |
"geojson = Feature(geometry=poly).dict(exclude_none=True)\n", | |
"\n", | |
"m = Map(\n", | |
" tiles=\"OpenStreetMap\",\n", | |
" location=((bounds[1] + bounds[3]) / 2,(bounds[0] + bounds[2]) / 2),\n", | |
" zoom_start=2\n", | |
")\n", | |
"\n", | |
"geo_json = GeoJson(\n", | |
" data=geojson,\n", | |
" style_function=lambda x: {\n", | |
" 'opacity': 1, 'dashArray': '1', 'fillOpacity': 0, 'weight': 1\n", | |
" },\n", | |
")\n", | |
"geo_json.add_to(m)\n", | |
"m" | |
] | |
}, | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Register Search query" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'searchid': '93ac4e08b875f5ec748c19dfb60e7ebc', 'links': [{'rel': 'metadata', 'type': 'application/json', 'href': 'https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/info'}, {'rel': 'tilejson', 'type': 'application/json', 'href': 'https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/tilejson.json'}]}\n" | |
] | |
} | |
], | |
"source": [ | |
"search_request = {\n", | |
" # Filter collection\n", | |
" \"collections\": [\"NASA_JPL_global_agb_mean_2020\"],\n", | |
" # limit bounds of the known items (note: the bbox will also be used in the tilejson response)\n", | |
" \"bbox\": bounds,\n", | |
" \"filter-lang\": \"cql-json\",\n", | |
"}\n", | |
"\n", | |
"response = httpx.post(\n", | |
" f\"{endpoint}/mosaic/register\", json=search_request,\n", | |
").json()\n", | |
"print(response)\n", | |
"\n", | |
"searchid = response[\"searchid\"]" | |
] | |
}, | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Show list of Mosaics" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"['93ac4e08b875f5ec748c19dfb60e7ebc']\n" | |
] | |
} | |
], | |
"source": [ | |
"response = httpx.get(f\"{endpoint}/mosaic/list\").json()\n", | |
"print(\n", | |
" [\n", | |
" search[\"search\"][\"hash\"]\n", | |
" for search in response[\"searches\"]\n", | |
" ]\n", | |
")" | |
] | |
}, | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Get Search Metadata" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'search': {'hash': '93ac4e08b875f5ec748c19dfb60e7ebc', 'search': {'bbox': [-180.0, -90.0, 180.0, 90.0], 'collections': ['NASA_JPL_global_agb_mean_2020'], 'filter-lang': 'cql-json'}, '_where': \"collection = ANY ('{NASA_JPL_global_agb_mean_2020}') AND st_intersects(geometry, '0103000020E6100000010000000500000000000000008066C000000000008056C000000000008066C0000000000080564000000000008066400000000000805640000000000080664000000000008056C000000000008066C000000000008056C0')\", 'orderby': 'datetime DESC, id DESC', 'lastused': '2023-05-24T02:16:34.683223+00:00', 'usecount': 1, 'metadata': {'type': 'mosaic'}}, 'links': [{'rel': 'self', 'type': 'application/json', 'href': 'https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/info'}, {'rel': 'tilejson', 'type': 'application/json', 'href': 'https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/tilejson.json'}]}\n" | |
] | |
} | |
], | |
"source": [ | |
"info_response = httpx.get(f\"{endpoint}/mosaic/{searchid}/info\").json()\n", | |
"print(info_response)" | |
] | |
}, | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Get TileJSON\n", | |
"\n", | |
"Note: to return a valid tilejson document you'll need to pass either the `assets` or `expression` option." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'tilejson': '2.2.0', 'name': '93ac4e08b875f5ec748c19dfb60e7ebc', 'version': '1.0.0', 'scheme': 'xyz', 'tiles': ['https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog_default'], 'minzoom': 0, 'maxzoom': 24, 'bounds': [-180.0, -90.0, 180.0, 90.0], 'center': [0.0, 0.0, 0]}\n" | |
] | |
} | |
], | |
"source": [ | |
"tj_response = httpx.get(f\"{endpoint}/mosaic/{searchid}/tilejson.json?assets=cog_default\").json()\n", | |
"print(tj_response)" | |
] | |
}, | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Load tiles" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'tilejson': '2.2.0',\n", | |
" 'name': '93ac4e08b875f5ec748c19dfb60e7ebc',\n", | |
" 'version': '1.0.0',\n", | |
" 'scheme': 'xyz',\n", | |
" 'tiles': ['https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog_default'],\n", | |
" 'minzoom': 0,\n", | |
" 'maxzoom': 24,\n", | |
" 'bounds': [-180.0, -90.0, 180.0, 90.0],\n", | |
" 'center': [0.0, 0.0, 0]}" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"tj_response" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe srcdoc=\"<!DOCTYPE html>\n", | |
"<html>\n", | |
"<head>\n", | |
" \n", | |
" <meta http-equiv="content-type" content="text/html; charset=UTF-8" />\n", | |
" \n", | |
" <script>\n", | |
" L_NO_TOUCH = false;\n", | |
" L_DISABLE_3D = false;\n", | |
" </script>\n", | |
" \n", | |
" <style>html, body {width: 100%;height: 100%;margin: 0;padding: 0;}</style>\n", | |
" <style>#map {position:absolute;top:0;bottom:0;right:0;left:0;}</style>\n", | |
" <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>\n", | |
" <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>\n", | |
" <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>\n", | |
" <script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"/>\n", | |
" <link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/all.min.css"/>\n", | |
" <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css"/>\n", | |
" \n", | |
" <meta name="viewport" content="width=device-width,\n", | |
" initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n", | |
" <style>\n", | |
" #map_63f7c99026cdfafb97522c0e090c530f {\n", | |
" position: relative;\n", | |
" width: 100.0%;\n", | |
" height: 100.0%;\n", | |
" left: 0.0%;\n", | |
" top: 0.0%;\n", | |
" }\n", | |
" .leaflet-container { font-size: 1rem; }\n", | |
" </style>\n", | |
" \n", | |
"</head>\n", | |
"<body>\n", | |
" \n", | |
" \n", | |
" <div class="folium-map" id="map_63f7c99026cdfafb97522c0e090c530f" ></div>\n", | |
" \n", | |
"</body>\n", | |
"<script>\n", | |
" \n", | |
" \n", | |
" var map_63f7c99026cdfafb97522c0e090c530f = L.map(\n", | |
" "map_63f7c99026cdfafb97522c0e090c530f",\n", | |
" {\n", | |
" center: [0.0, 0.0],\n", | |
" crs: L.CRS.EPSG3857,\n", | |
" zoom: 3,\n", | |
" zoomControl: true,\n", | |
" preferCanvas: false,\n", | |
" }\n", | |
" );\n", | |
"\n", | |
" \n", | |
"\n", | |
" \n", | |
" \n", | |
" var tile_layer_606ec11f83f56607cae6c6bdf833dc95 = L.tileLayer(\n", | |
" "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",\n", | |
" {"attribution": "Data by \\u0026copy; \\u003ca target=\\"_blank\\" href=\\"http://openstreetmap.org\\"\\u003eOpenStreetMap\\u003c/a\\u003e, under \\u003ca target=\\"_blank\\" href=\\"http://www.openstreetmap.org/copyright\\"\\u003eODbL\\u003c/a\\u003e.", "detectRetina": false, "maxNativeZoom": 18, "maxZoom": 18, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}\n", | |
" ).addTo(map_63f7c99026cdfafb97522c0e090c530f);\n", | |
" \n", | |
" \n", | |
" function geo_json_e32a836b44b7b654acf8748946d4fb43_styler(feature) {\n", | |
" switch(feature.id) {\n", | |
" default:\n", | |
" return {"dashArray": "1", "fillOpacity": 0, "opacity": 1, "weight": 1};\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" function geo_json_e32a836b44b7b654acf8748946d4fb43_onEachFeature(feature, layer) {\n", | |
" layer.on({\n", | |
" });\n", | |
" };\n", | |
" var geo_json_e32a836b44b7b654acf8748946d4fb43 = L.geoJson(null, {\n", | |
" onEachFeature: geo_json_e32a836b44b7b654acf8748946d4fb43_onEachFeature,\n", | |
" \n", | |
" style: geo_json_e32a836b44b7b654acf8748946d4fb43_styler,\n", | |
" });\n", | |
"\n", | |
" function geo_json_e32a836b44b7b654acf8748946d4fb43_add (data) {\n", | |
" geo_json_e32a836b44b7b654acf8748946d4fb43\n", | |
" .addData(data)\n", | |
" .addTo(map_63f7c99026cdfafb97522c0e090c530f);\n", | |
" }\n", | |
" geo_json_e32a836b44b7b654acf8748946d4fb43_add({"features": [{"geometry": {"coordinates": [[[-180.0, -90.0], [180.0, -90.0], [180.0, 90.0], [-180.0, 90.0], [-180.0, -90.0]]], "type": "Polygon"}, "id": "0", "type": "Feature"}], "type": "FeatureCollection"});\n", | |
"\n", | |
" \n", | |
" \n", | |
" var tile_layer_993bd77d22c40f24c067615809f68303 = L.tileLayer(\n", | |
" "https://lv5hbsr7xi.execute-api.us-west-2.amazonaws.com/mosaic/93ac4e08b875f5ec748c19dfb60e7ebc/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog_default",\n", | |
" {"attribution": "Mosaic", "detectRetina": false, "maxNativeZoom": 1, "maxZoom": 1, "minZoom": 1, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}\n", | |
" ).addTo(map_63f7c99026cdfafb97522c0e090c530f);\n", | |
" \n", | |
"</script>\n", | |
"</html>\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>" | |
], | |
"text/plain": [ | |
"<folium.folium.Map at 0x10ee83190>" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"m = Map(\n", | |
" location=((bounds[1] + bounds[3]) / 2,(bounds[0] + bounds[2]) / 2),\n", | |
" zoom_start=3\n", | |
")\n", | |
"\n", | |
"geo_json = GeoJson(\n", | |
" data=geojson,\n", | |
" style_function=lambda x: {\n", | |
" 'opacity': 1, 'dashArray': '1', 'fillOpacity': 0, 'weight': 1\n", | |
" },\n", | |
")\n", | |
"geo_json.add_to(m)\n", | |
"\n", | |
"aod_layer = TileLayer(\n", | |
" tiles=tj_response[\"tiles\"][0],\n", | |
" attr=\"Mosaic\",\n", | |
" min_zoom=1,\n", | |
" max_zoom=1,\n", | |
" max_native_zoom=1, \n", | |
")\n", | |
"aod_layer.add_to(m)\n", | |
"m" | |
] | |
}, | |
{ | |
"attachments": {}, | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"### Register a Mosaic with Metadata" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'searchid': '4b0db3dbd1858d54a3a55f84de97d1ca', 'links': [{'rel': 'metadata', 'type': 'application/json', 'href': 'http://127.0.0.1:8081/mosaic/4b0db3dbd1858d54a3a55f84de97d1ca/info'}, {'rel': 'tilejson', 'type': 'application/json', 'href': 'http://127.0.0.1:8081/mosaic/4b0db3dbd1858d54a3a55f84de97d1ca/tilejson.json'}]}\n" | |
] | |
} | |
], | |
"source": [ | |
"search_request = {\n", | |
" # Filter collection\n", | |
" \"collections\": [\"noaa-emergency-response\"],\n", | |
" # limit bounds of the known items (note: the bbox will also be used in the tilejson response)\n", | |
" \"bbox\": bounds,\n", | |
" \"filter-lang\": \"cql-json\",\n", | |
" \"metadata\": {\n", | |
" \"bounds\": [-87.0251, 36.0999, -85.4249, 36.2251], # This is redondant because it's in the bbox filter\n", | |
" \"minzoom\": 14,\n", | |
" \"maxzoom\": 18,\n", | |
" \"assets\": [\"cog\"],\n", | |
" \"defaults\": {\n", | |
" \"true_color\": {\n", | |
" \"bidx\": [1, 2, 3],\n", | |
" },\n", | |
" },\n", | |
" },\n", | |
"}\n", | |
"\n", | |
"response = httpx.post(\n", | |
" f\"{endpoint}/mosaic/register\", json=search_request,\n", | |
").json()\n", | |
"print(response)\n", | |
"\n", | |
"searchid = response[\"searchid\"]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"{'tilejson': '2.2.0', 'name': '4b0db3dbd1858d54a3a55f84de97d1ca', 'version': '1.0.0', 'scheme': 'xyz', 'tiles': ['http://127.0.0.1:8081/mosaic/tiles/4b0db3dbd1858d54a3a55f84de97d1ca/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog'], 'minzoom': 14, 'maxzoom': 18, 'bounds': [-87.0251, 36.0999, -85.4249, 36.2251], 'center': [-86.225, 36.162499999999994, 14]}\n" | |
] | |
} | |
], | |
"source": [ | |
"tj_response = httpx.get(f\"{endpoint}/mosaic/{searchid}/tilejson.json?assets=cog\").json()\n", | |
"print(tj_response)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe srcdoc=\"<!DOCTYPE html>\n", | |
"<head> \n", | |
" <meta http-equiv="content-type" content="text/html; charset=UTF-8" />\n", | |
" \n", | |
" <script>\n", | |
" L_NO_TOUCH = false;\n", | |
" L_DISABLE_3D = false;\n", | |
" </script>\n", | |
" \n", | |
" <style>html, body {width: 100%;height: 100%;margin: 0;padding: 0;}</style>\n", | |
" <style>#map {position:absolute;top:0;bottom:0;right:0;left:0;}</style>\n", | |
" <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.js"></script>\n", | |
" <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>\n", | |
" <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>\n", | |
" <script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css"/>\n", | |
" <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"/>\n", | |
" <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css"/>\n", | |
" <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"/>\n", | |
" <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css"/>\n", | |
" <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css"/>\n", | |
" \n", | |
" <meta name="viewport" content="width=device-width,\n", | |
" initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n", | |
" <style>\n", | |
" #map_b38de3dc4bc9af19637871c0b579e8c3 {\n", | |
" position: relative;\n", | |
" width: 100.0%;\n", | |
" height: 100.0%;\n", | |
" left: 0.0%;\n", | |
" top: 0.0%;\n", | |
" }\n", | |
" </style>\n", | |
" \n", | |
"</head>\n", | |
"<body> \n", | |
" \n", | |
" <div class="folium-map" id="map_b38de3dc4bc9af19637871c0b579e8c3" ></div>\n", | |
" \n", | |
"</body>\n", | |
"<script> \n", | |
" \n", | |
" var map_b38de3dc4bc9af19637871c0b579e8c3 = L.map(\n", | |
" "map_b38de3dc4bc9af19637871c0b579e8c3",\n", | |
" {\n", | |
" center: [36.162499999999994, -86.225],\n", | |
" crs: L.CRS.EPSG3857,\n", | |
" zoom: 14,\n", | |
" zoomControl: true,\n", | |
" preferCanvas: false,\n", | |
" }\n", | |
" );\n", | |
"\n", | |
" \n", | |
"\n", | |
" \n", | |
" \n", | |
" var tile_layer_cadb0163df1862177b9846b5362efd22 = L.tileLayer(\n", | |
" "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",\n", | |
" {"attribution": "Data by \\u0026copy; \\u003ca href=\\"http://openstreetmap.org\\"\\u003eOpenStreetMap\\u003c/a\\u003e, under \\u003ca href=\\"http://www.openstreetmap.org/copyright\\"\\u003eODbL\\u003c/a\\u003e.", "detectRetina": false, "maxNativeZoom": 18, "maxZoom": 18, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}\n", | |
" ).addTo(map_b38de3dc4bc9af19637871c0b579e8c3);\n", | |
" \n", | |
" \n", | |
" function geo_json_940dac1f952e8e5fbe3239dbdcd71a70_styler(feature) {\n", | |
" switch(feature.id) {\n", | |
" default:\n", | |
" return {"dashArray": "1", "fillOpacity": 0, "opacity": 1, "weight": 1};\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" function geo_json_940dac1f952e8e5fbe3239dbdcd71a70_onEachFeature(feature, layer) {\n", | |
" layer.on({\n", | |
" });\n", | |
" };\n", | |
" var geo_json_940dac1f952e8e5fbe3239dbdcd71a70 = L.geoJson(null, {\n", | |
" onEachFeature: geo_json_940dac1f952e8e5fbe3239dbdcd71a70_onEachFeature,\n", | |
" \n", | |
" style: geo_json_940dac1f952e8e5fbe3239dbdcd71a70_styler,\n", | |
" });\n", | |
"\n", | |
" function geo_json_940dac1f952e8e5fbe3239dbdcd71a70_add (data) {\n", | |
" geo_json_940dac1f952e8e5fbe3239dbdcd71a70\n", | |
" .addData(data)\n", | |
" .addTo(map_b38de3dc4bc9af19637871c0b579e8c3);\n", | |
" }\n", | |
" geo_json_940dac1f952e8e5fbe3239dbdcd71a70_add({"features": [{"geometry": {"coordinates": [[[-87.0251, 36.0999], [-85.4249, 36.0999], [-85.4249, 36.2251], [-87.0251, 36.2251], [-87.0251, 36.0999]]], "type": "Polygon"}, "id": "0", "type": "Feature"}], "type": "FeatureCollection"});\n", | |
"\n", | |
" \n", | |
" \n", | |
" var tile_layer_c978413d31bcfac7c038761d64f09538 = L.tileLayer(\n", | |
" "http://127.0.0.1:8081/mosaic/tiles/4b0db3dbd1858d54a3a55f84de97d1ca/WebMercatorQuad/{z}/{x}/{y}@1x?assets=cog",\n", | |
" {"attribution": "Mosaic", "detectRetina": false, "maxNativeZoom": 18, "maxZoom": 18, "minZoom": 14, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}\n", | |
" ).addTo(map_b38de3dc4bc9af19637871c0b579e8c3);\n", | |
" \n", | |
"</script>\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>" | |
], | |
"text/plain": [ | |
"<folium.folium.Map at 0x14f1f4760>" | |
] | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"m = Map(\n", | |
" location=((bounds[1] + bounds[3]) / 2,(bounds[0] + bounds[2]) / 2),\n", | |
" zoom_start=14\n", | |
")\n", | |
"\n", | |
"geo_json = GeoJson(\n", | |
" data=geojson,\n", | |
" style_function=lambda x: {\n", | |
" 'opacity': 1, 'dashArray': '1', 'fillOpacity': 0, 'weight': 1\n", | |
" },\n", | |
")\n", | |
"geo_json.add_to(m)\n", | |
"\n", | |
"aod_layer = TileLayer(\n", | |
" tiles=tj_response[\"tiles\"][0],\n", | |
" attr=\"Mosaic\",\n", | |
" min_zoom=tj_response[\"minzoom\"],\n", | |
" max_zoom=tj_response[\"maxzoom\"],\n", | |
" max_native_zoom=tj_response[\"maxzoom\"], \n", | |
")\n", | |
"aod_layer.add_to(m)\n", | |
"m" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"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.10.9" | |
}, | |
"vscode": { | |
"interpreter": { | |
"hash": "2590a9e34ee6c8bdce5141410f2a072bbabd2a859a8a48acdaa85720923a90ef" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment