{ "cells": [ { "cell_type": "markdown", "id": "0", "metadata": {}, "source": [ "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/42_create_cog.ipynb)\n", "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/notebooks/42_create_cog.ipynb)\n", "[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n", "\n", "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "id": "1", "metadata": {}, "outputs": [], "source": [ "# !pip install leafmap" ] }, { "cell_type": "code", "execution_count": null, "id": "2", "metadata": {}, "outputs": [], "source": [ "import leafmap" ] }, { "cell_type": "markdown", "id": "3", "metadata": {}, "source": [ "Provide a dataset path or URL." ] }, { "cell_type": "code", "execution_count": null, "id": "4", "metadata": {}, "outputs": [], "source": [ "url = \"https://opengeos.org/data/raster/srtm90.tif\"" ] }, { "cell_type": "markdown", "id": "5", "metadata": {}, "source": [ "Validate COG." ] }, { "cell_type": "code", "execution_count": null, "id": "6", "metadata": {}, "outputs": [], "source": [ "leafmap.cog_validate(url)" ] }, { "cell_type": "code", "execution_count": null, "id": "7", "metadata": {}, "outputs": [], "source": [ "leafmap.cog_validate(url, verbose=True)" ] }, { "cell_type": "markdown", "id": "8", "metadata": {}, "source": [ "Convert the image to tiled COG." ] }, { "cell_type": "code", "execution_count": null, "id": "9", "metadata": {}, "outputs": [], "source": [ "out_cog = \"cog.tif\"\n", "leafmap.image_to_cog(url, out_cog)" ] }, { "cell_type": "markdown", "id": "10", "metadata": {}, "source": [ "Validate COG." ] }, { "cell_type": "code", "execution_count": null, "id": "11", "metadata": {}, "outputs": [], "source": [ "leafmap.cog_validate(out_cog)" ] }, { "cell_type": "code", "execution_count": null, "id": "12", "metadata": {}, "outputs": [], "source": [ "leafmap.cog_validate(out_cog, verbose=True)" ] }, { "cell_type": "markdown", "id": "13", "metadata": {}, "source": [ "Add COG to map." ] }, { "cell_type": "code", "execution_count": null, "id": "14", "metadata": {}, "outputs": [], "source": [ "m = leafmap.Map()\n", "m.add_raster(out_cog, palette=\"terrain\", layer_name=\"Local COG\")\n", "m.add_cog_layer(url, palette=\"gist_earth\", name=\"Remote COG\")\n", "m" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }