From e9b2812f3fdefb06bd960a4681b32c59093bb435 Mon Sep 17 00:00:00 2001 From: Qiusheng Wu Date: Wed, 6 Sep 2023 23:31:42 -0400 Subject: [PATCH] Change tms_to_geotiff to map_tiles_to_geotiff --- docs/changelog.md | 6 +- docs/notebooks/74_map_tiles_to_geotiff.ipynb | 261 ++++++++++++++++++ docs/notebooks/74_tms_to_geotiff.ipynb | 162 ----------- docs/tutorials.md | 2 +- examples/README.md | 2 +- .../notebooks/74_map_tiles_to_geotiff.ipynb | 261 ++++++++++++++++++ examples/notebooks/74_tms_to_geotiff.ipynb | 162 ----------- leafmap/common.py | 7 +- mkdocs.yml | 2 +- 9 files changed, 533 insertions(+), 332 deletions(-) create mode 100644 docs/notebooks/74_map_tiles_to_geotiff.ipynb delete mode 100644 docs/notebooks/74_tms_to_geotiff.ipynb create mode 100644 examples/notebooks/74_map_tiles_to_geotiff.ipynb delete mode 100644 examples/notebooks/74_tms_to_geotiff.ipynb diff --git a/docs/changelog.md b/docs/changelog.md index 4d755622f4..704ea92043 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -150,7 +150,7 @@ **New Features** -- Added tms_to_geotiff function (#420) +- Added map_tiles_to_geotiff function (#420) - Added tif_to_jp2 function and fixed build errors (#425) - Added Segment Anything Model (SAM) (#426) @@ -160,14 +160,14 @@ - Added marker cluster radius option (#417) - Added request_modifier param to stac_client (#421) - Added bbox parameter for create_timelapse function (#427) -- Improved tms_to_geotiff and tif_to_jp2 (#430) +- Improved map_tiles_to_geotiff and tif_to_jp2 (#430) - Fixed ArcGIS add layer bug (#434) ## v0.19.1 - Apr 21, 2023 **New Features** -- Added tms_to_geotiff function (#420) +- Added map_tiles_to_geotiff function (#420) - Added tif_to_jp2 function (#424) **Improvement** diff --git a/docs/notebooks/74_map_tiles_to_geotiff.ipynb b/docs/notebooks/74_map_tiles_to_geotiff.ipynb new file mode 100644 index 0000000000..4eaa7eb9d0 --- /dev/null +++ b/docs/notebooks/74_map_tiles_to_geotiff.ipynb @@ -0,0 +1,261 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/74_map_tiles_to_geotiff.ipynb)\n", + "[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/opengeos/leafmap/blob/master/examples/notebooks/74_map_tiles_to_geotiff.ipynb)\n", + "[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/opengeos/leafmap&urlpath=lab/tree/leafmap/examples/notebooks/74_map_tiles_to_geotiff.ipynb&branch=master)\n", + "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/opengeos/leafmap/blob/master/examples/notebooks/74_map_tiles_to_geotiff.ipynb)\n", + "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)\n", + "\n", + "**Downloading maps tiles and converting them to a GeoTIFF file**\n", + "\n", + "Disclaimer: The `leafmap.map_tiles_to_geotiff()` function is adapted from the [tms2geotiff](https://github.com/gumblex/tms2geotiff) repo. Credit goes to the GitHub user @gumblex.\n", + "\n", + "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# %pip install -U leafmap" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from leafmap import leafmap" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create an interactive map." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "64179897fd044c98a924b5fc03c04dc7", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map(center=[20, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_text…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "m = leafmap.Map()\n", + "m" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Use the drawing tools to draw a rectangle on the map." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "if m.user_roi is not None:\n", + " bbox = m.user_roi_bounds()\n", + "else:\n", + " bbox = [-122.5216, 37.733, -122.3661, 37.8095]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download TMS tiles and create a GeoTIFF file. First, let's try OpenStreetMap." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloaded image 1/15\n", + "Downloaded image 2/15\n", + "Downloaded image 3/15\n", + "Downloaded image 4/15\n", + "Downloaded image 5/15\n", + "Downloaded image 6/15\n", + "Downloaded image 7/15\n", + "Downloaded image 8/15\n", + "Downloaded image 9/15\n", + "Downloaded image 10/15\n", + "Downloaded image 11/15\n", + "Downloaded image 12/15\n", + "Downloaded image 13/15\n", + "Downloaded image 14/15\n", + "Downloaded image 15/15\n", + "Saving GeoTIFF. Please wait...\n", + "Image saved to osm.tif\n" + ] + } + ], + "source": [ + "leafmap.map_tiles_to_geotiff('osm.tif', bbox, zoom=13, source='OpenStreetMap', quiet=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://i.imgur.com/ft597DD.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try Google Satellite." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloaded image 1/15\n", + "Downloaded image 2/15\n", + "Downloaded image 3/15\n", + "Downloaded image 4/15\n", + "Downloaded image 5/15\n", + "Downloaded image 6/15\n", + "Downloaded image 7/15\n", + "Downloaded image 8/15\n", + "Downloaded image 9/15\n", + "Downloaded image 10/15\n", + "Downloaded image 11/15\n", + "Downloaded image 12/15\n", + "Downloaded image 13/15\n", + "Downloaded image 14/15\n", + "Downloaded image 15/15\n", + "Saving GeoTIFF. Please wait...\n", + "Image saved to satellite.tif\n" + ] + } + ], + "source": [ + "leafmap.map_tiles_to_geotiff('satellite.tif', bbox, zoom=13, source='Satellite')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://i.imgur.com/ILYunA9.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try OpenTopoMap." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "source = 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloaded image 1/15\n", + "Downloaded image 2/15\n", + "Downloaded image 3/15\n", + "Downloaded image 4/15\n", + "Downloaded image 5/15\n", + "Downloaded image 6/15\n", + "Downloaded image 7/15\n", + "Downloaded image 8/15\n", + "Downloaded image 9/15\n", + "Downloaded image 10/15\n", + "Downloaded image 11/15\n", + "Downloaded image 12/15\n", + "Downloaded image 13/15\n", + "Downloaded image 14/15\n", + "Downloaded image 15/15\n", + "Saving GeoTIFF. Please wait...\n", + "Image saved to topo.tif\n" + ] + } + ], + "source": [ + "leafmap.map_tiles_to_geotiff('topo.tif', bbox, zoom=13, source=source)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://i.imgur.com/4UkUZKw.png)" + ] + } + ], + "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.10.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/notebooks/74_tms_to_geotiff.ipynb b/docs/notebooks/74_tms_to_geotiff.ipynb deleted file mode 100644 index 9517b52700..0000000000 --- a/docs/notebooks/74_tms_to_geotiff.ipynb +++ /dev/null @@ -1,162 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/74_tms_to_geotiff.ipynb)\n", - "[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/opengeos/leafmap/blob/master/examples/notebooks/74_tms_to_geotiff.ipynb)\n", - "[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/opengeos/leafmap&urlpath=lab/tree/leafmap/examples/notebooks/74_tms_to_geotiff.ipynb&branch=master)\n", - "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/opengeos/leafmap/blob/master/examples/notebooks/74_tms_to_geotiff.ipynb)\n", - "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)\n", - "\n", - "**Downloading maps tiles from a Tile Map Server (TMS) and Creating a GeoTIFF file**\n", - "\n", - "Disclaimer: The `leafmap.tms_to_geotiff()` function is adapted from the [tms2geotiff](https://github.com/gumblex/tms2geotiff) repo. Credit goes to the GitHub user @gumblex.\n", - "\n", - "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# %pip install -U leafmap" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from leafmap import leafmap" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an interactive map." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m = leafmap.Map()\n", - "m" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Use the drawing tools to draw a rectangle on the map." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if m.user_roi is not None:\n", - " bbox = m.user_roi_bounds()\n", - "else:\n", - " bbox = [-122.5216, 37.733, -122.3661, 37.8095]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Download TMS tiles and create a GeoTIFF file. First, let's try OpenStreetMap." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "leafmap.tms_to_geotiff('osm.tif', bbox, zoom=13, source='OpenStreetMap', quiet=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/ft597DD.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try Google Satellite." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "leafmap.tms_to_geotiff('satellite.tif', bbox, zoom=13, source='Satellite')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/ILYunA9.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try OpenTopoMap." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "source = 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "leafmap.tms_to_geotiff('topo.tif', bbox, zoom=13, source=source)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/4UkUZKw.png)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/tutorials.md b/docs/tutorials.md index ffa818f3bb..717f96f636 100644 --- a/docs/tutorials.md +++ b/docs/tutorials.md @@ -87,7 +87,7 @@ 71. Loading geospatial datasets from an AWS S3 bucket ([notebook](https://leafmap.org/notebooks/71_aws_s3)) 72. Creating timelapse animations from satellite imagery timeseries ([notebook](https://leafmap.org/notebooks/72_timelapse)) 73. Searching Geospatial Data Interactively with Custom STAC API Endpoints ([notebook](https://leafmap.org/notebooks/73_custom_stac)) -74. Downloading maps tiles from a Tile Map Server (TMS) and Creating a GeoTIFF file ([notebook](https://leafmap.org/notebooks/74_tms_to_geotiff)) +74. Downloading maps tiles and converting them to a GeoTIFF file ([notebook](https://leafmap.org/notebooks/74_map_tiles_to_geotiff)) 75. Segmenting satellite imagery with the Segment Anything Model ([notebook](https://leafmap.org/notebooks/75_segment_anything)) 76. Comparing images with an interactive slider ([notebook](https://leafmap.org/notebooks/76_image_comparison)) 77. Spitting a raster dataset into multiple tiles ([notebook](https://leafmap.org/notebooks/77_split_raster)) diff --git a/examples/README.md b/examples/README.md index 6c0641cfbd..df2f88864b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -94,7 +94,7 @@ 71. Loading geospatial datasets from an AWS S3 bucket ([notebook](https://leafmap.org/notebooks/71_aws_s3)) 72. Creating timelapse animations from satellite imagery timeseries ([notebook](https://leafmap.org/notebooks/72_timelapse)) 73. Searching Geospatial Data Interactively with Custom STAC API Endpoints ([notebook](https://leafmap.org/notebooks/73_custom_stac)) -74. Downloading maps tiles from a Tile Map Server (TMS) and Creating a GeoTIFF file ([notebook](https://leafmap.org/notebooks/74_tms_to_geotiff)) +74. Downloading maps tiles and converting them to a GeoTIFF file ([notebook](https://leafmap.org/notebooks/74_map_tiles_to_geotiff)) 75. Segmenting satellite imagery with the Segment Anything Model ([notebook](https://leafmap.org/notebooks/75_segment_anything)) 76. Comparing images with an interactive slider ([notebook](https://leafmap.org/notebooks/76_image_comparison)) 77. Spitting a raster dataset into multiple tiles ([notebook](https://leafmap.org/notebooks/77_split_raster)) diff --git a/examples/notebooks/74_map_tiles_to_geotiff.ipynb b/examples/notebooks/74_map_tiles_to_geotiff.ipynb new file mode 100644 index 0000000000..4eaa7eb9d0 --- /dev/null +++ b/examples/notebooks/74_map_tiles_to_geotiff.ipynb @@ -0,0 +1,261 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/74_map_tiles_to_geotiff.ipynb)\n", + "[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/opengeos/leafmap/blob/master/examples/notebooks/74_map_tiles_to_geotiff.ipynb)\n", + "[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/opengeos/leafmap&urlpath=lab/tree/leafmap/examples/notebooks/74_map_tiles_to_geotiff.ipynb&branch=master)\n", + "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/opengeos/leafmap/blob/master/examples/notebooks/74_map_tiles_to_geotiff.ipynb)\n", + "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)\n", + "\n", + "**Downloading maps tiles and converting them to a GeoTIFF file**\n", + "\n", + "Disclaimer: The `leafmap.map_tiles_to_geotiff()` function is adapted from the [tms2geotiff](https://github.com/gumblex/tms2geotiff) repo. Credit goes to the GitHub user @gumblex.\n", + "\n", + "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "# %pip install -U leafmap" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from leafmap import leafmap" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Create an interactive map." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "64179897fd044c98a924b5fc03c04dc7", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "Map(center=[20, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zoom_out_text…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "m = leafmap.Map()\n", + "m" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Use the drawing tools to draw a rectangle on the map." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "if m.user_roi is not None:\n", + " bbox = m.user_roi_bounds()\n", + "else:\n", + " bbox = [-122.5216, 37.733, -122.3661, 37.8095]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Download TMS tiles and create a GeoTIFF file. First, let's try OpenStreetMap." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloaded image 1/15\n", + "Downloaded image 2/15\n", + "Downloaded image 3/15\n", + "Downloaded image 4/15\n", + "Downloaded image 5/15\n", + "Downloaded image 6/15\n", + "Downloaded image 7/15\n", + "Downloaded image 8/15\n", + "Downloaded image 9/15\n", + "Downloaded image 10/15\n", + "Downloaded image 11/15\n", + "Downloaded image 12/15\n", + "Downloaded image 13/15\n", + "Downloaded image 14/15\n", + "Downloaded image 15/15\n", + "Saving GeoTIFF. Please wait...\n", + "Image saved to osm.tif\n" + ] + } + ], + "source": [ + "leafmap.map_tiles_to_geotiff('osm.tif', bbox, zoom=13, source='OpenStreetMap', quiet=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://i.imgur.com/ft597DD.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try Google Satellite." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloaded image 1/15\n", + "Downloaded image 2/15\n", + "Downloaded image 3/15\n", + "Downloaded image 4/15\n", + "Downloaded image 5/15\n", + "Downloaded image 6/15\n", + "Downloaded image 7/15\n", + "Downloaded image 8/15\n", + "Downloaded image 9/15\n", + "Downloaded image 10/15\n", + "Downloaded image 11/15\n", + "Downloaded image 12/15\n", + "Downloaded image 13/15\n", + "Downloaded image 14/15\n", + "Downloaded image 15/15\n", + "Saving GeoTIFF. Please wait...\n", + "Image saved to satellite.tif\n" + ] + } + ], + "source": [ + "leafmap.map_tiles_to_geotiff('satellite.tif', bbox, zoom=13, source='Satellite')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://i.imgur.com/ILYunA9.png)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Try OpenTopoMap." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "source = 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png'" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Downloaded image 1/15\n", + "Downloaded image 2/15\n", + "Downloaded image 3/15\n", + "Downloaded image 4/15\n", + "Downloaded image 5/15\n", + "Downloaded image 6/15\n", + "Downloaded image 7/15\n", + "Downloaded image 8/15\n", + "Downloaded image 9/15\n", + "Downloaded image 10/15\n", + "Downloaded image 11/15\n", + "Downloaded image 12/15\n", + "Downloaded image 13/15\n", + "Downloaded image 14/15\n", + "Downloaded image 15/15\n", + "Saving GeoTIFF. Please wait...\n", + "Image saved to topo.tif\n" + ] + } + ], + "source": [ + "leafmap.map_tiles_to_geotiff('topo.tif', bbox, zoom=13, source=source)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "![](https://i.imgur.com/4UkUZKw.png)" + ] + } + ], + "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.10.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/examples/notebooks/74_tms_to_geotiff.ipynb b/examples/notebooks/74_tms_to_geotiff.ipynb deleted file mode 100644 index 9517b52700..0000000000 --- a/examples/notebooks/74_tms_to_geotiff.ipynb +++ /dev/null @@ -1,162 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/74_tms_to_geotiff.ipynb)\n", - "[![image](https://studiolab.sagemaker.aws/studiolab.svg)](https://studiolab.sagemaker.aws/import/github/opengeos/leafmap/blob/master/examples/notebooks/74_tms_to_geotiff.ipynb)\n", - "[![image](https://img.shields.io/badge/Open-Planetary%20Computer-black?style=flat&logo=microsoft)](https://pccompute.westeurope.cloudapp.azure.com/compute/hub/user-redirect/git-pull?repo=https://github.com/opengeos/leafmap&urlpath=lab/tree/leafmap/examples/notebooks/74_tms_to_geotiff.ipynb&branch=master)\n", - "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/opengeos/leafmap/blob/master/examples/notebooks/74_tms_to_geotiff.ipynb)\n", - "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/leafmap-binder)\n", - "\n", - "**Downloading maps tiles from a Tile Map Server (TMS) and Creating a GeoTIFF file**\n", - "\n", - "Disclaimer: The `leafmap.tms_to_geotiff()` function is adapted from the [tms2geotiff](https://github.com/gumblex/tms2geotiff) repo. Credit goes to the GitHub user @gumblex.\n", - "\n", - "Uncomment the following line to install [leafmap](https://leafmap.org) if needed." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# %pip install -U leafmap" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "from leafmap import leafmap" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Create an interactive map." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "m = leafmap.Map()\n", - "m" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Use the drawing tools to draw a rectangle on the map." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if m.user_roi is not None:\n", - " bbox = m.user_roi_bounds()\n", - "else:\n", - " bbox = [-122.5216, 37.733, -122.3661, 37.8095]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Download TMS tiles and create a GeoTIFF file. First, let's try OpenStreetMap." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "leafmap.tms_to_geotiff('osm.tif', bbox, zoom=13, source='OpenStreetMap', quiet=False)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/ft597DD.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try Google Satellite." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "leafmap.tms_to_geotiff('satellite.tif', bbox, zoom=13, source='Satellite')" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/ILYunA9.png)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Try OpenTopoMap." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "source = 'https://a.tile.opentopomap.org/{z}/{x}/{y}.png'" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "leafmap.tms_to_geotiff('topo.tif', bbox, zoom=13, source=source)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "![](https://i.imgur.com/4UkUZKw.png)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/leafmap/common.py b/leafmap/common.py index 8f5ba8f208..250b6f4e6d 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -9035,7 +9035,7 @@ def xy_to_window(xy): return (left, top, width, height) -def tms_to_geotiff( +def map_tiles_to_geotiff( output, bbox, zoom=None, @@ -9046,7 +9046,7 @@ def tms_to_geotiff( quiet=False, **kwargs, ): - """Download TMS tiles and convert them to a GeoTIFF. The source is adapted from https://github.com/gumblex/tms2geotiff. + """Download map tiles and convert them to a GeoTIFF. The source is adapted from https://github.com/gumblex/tms2geotiff. Credits to the GitHub user @gumblex. Args: @@ -9320,6 +9320,9 @@ def draw_tile( raise Exception(e) +tms_to_geotiff = map_tiles_to_geotiff + + def tif_to_jp2(filename, output, creationOptions=None): """Converts a GeoTIFF to JPEG2000. diff --git a/mkdocs.yml b/mkdocs.yml index 8a530c8e3a..5ca1ab250f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -201,7 +201,7 @@ nav: - notebooks/71_aws_s3.ipynb - notebooks/72_timelapse.ipynb - notebooks/73_custom_stac.ipynb - - notebooks/74_tms_to_geotiff.ipynb + - notebooks/74_map_tiles_to_geotiff.ipynb - notebooks/75_segment_anything.ipynb - notebooks/76_image_comparison.ipynb - notebooks/77_split_raster.ipynb