Visualize local raster datasets
This notebook demonstrates how to visualize local raster datasets with localtileserver.
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# %pip install "leafmap[maplibre]"
# %pip install "leafmap[maplibre]"
In [2]:
Copied!
import leafmap.maplibregl as leafmap
import leafmap.maplibregl as leafmap
In [3]:
Copied!
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
# import os
# os.environ["MAPTILER_KEY"] = "YOUR_API_KEY"
In [4]:
Copied!
url = "https://github.com/opengeos/datasets/releases/download/raster/landsat.tif"
filepath = "landsat.tif"
leafmap.download_file(url, filepath)
url = "https://github.com/opengeos/datasets/releases/download/raster/landsat.tif"
filepath = "landsat.tif"
leafmap.download_file(url, filepath)
Downloading... From: https://github.com/opengeos/datasets/releases/download/raster/landsat.tif To: /home/runner/work/leafmap/leafmap/docs/maplibre/landsat.tif
0%| | 0.00/10.1M [00:00<?, ?B/s]
100%|██████████| 10.1M/10.1M [00:00<00:00, 177MB/s]
Out[4]:
'/home/runner/work/leafmap/leafmap/docs/maplibre/landsat.tif'
In [5]:
Copied!
m = leafmap.Map(style="streets")
m.add_raster(filepath, indexes=[3, 2, 1], vmin=0, vmax=100, name="Landsat-321")
m.add_raster(filepath, indexes=[4, 3, 2], vmin=0, vmax=100, name="Landsat-432")
m
m = leafmap.Map(style="streets")
m.add_raster(filepath, indexes=[3, 2, 1], vmin=0, vmax=100, name="Landsat-321")
m.add_raster(filepath, indexes=[4, 3, 2], vmin=0, vmax=100, name="Landsat-432")
m
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.
In [6]:
Copied!
m.layer_interact()
m.layer_interact()
In [7]:
Copied!
url = "https://github.com/opengeos/datasets/releases/download/raster/srtm90.tif"
filepath = "srtm90.tif"
leafmap.download_file(url, filepath)
url = "https://github.com/opengeos/datasets/releases/download/raster/srtm90.tif"
filepath = "srtm90.tif"
leafmap.download_file(url, filepath)
Downloading... From: https://github.com/opengeos/datasets/releases/download/raster/srtm90.tif To: /home/runner/work/leafmap/leafmap/docs/maplibre/srtm90.tif
0%| | 0.00/16.6M [00:00<?, ?B/s]
100%|██████████| 16.6M/16.6M [00:00<00:00, 237MB/s]
Out[7]:
'/home/runner/work/leafmap/leafmap/docs/maplibre/srtm90.tif'
In [8]:
Copied!
m = leafmap.Map(style="streets")
m.add_raster(filepath, colormap="terrain", name="DEM")
m
m = leafmap.Map(style="streets")
m.add_raster(filepath, colormap="terrain", name="DEM")
m
Failed to retrieve the MapTiler style. Defaulting to OpenFreeMap 'liberty' style.
In [9]:
Copied!
m.layer_interact()
m.layer_interact()