Skip to content

Commit

Permalink
Change tms_to_geotiff to map_tiles_to_geotiff
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Sep 7, 2023
1 parent 265435e commit e9b2812
Show file tree
Hide file tree
Showing 9 changed files with 533 additions and 332 deletions.
6 changes: 3 additions & 3 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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**
Expand Down
261 changes: 261 additions & 0 deletions docs/notebooks/74_map_tiles_to_geotiff.ipynb
Original file line number Diff line number Diff line change
@@ -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
}
Loading

0 comments on commit e9b2812

Please sign in to comment.