83 local tile
Using local raster datasets or remote Cloud Optimized GeoTIFFs (COG) with geemap
Uncomment the following line to install geemap and localtileserver if needed.
In [1]:
Copied!
# !pip install geemap localtileserver
# !pip install geemap localtileserver
In [2]:
Copied!
import os
import geemap
import os
import geemap
Specify input raster datasets
In [3]:
Copied!
out_dir = os.path.expanduser('~/Downloads')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
dem = os.path.join(out_dir, 'dem.tif')
out_dir = os.path.expanduser('~/Downloads')
if not os.path.exists(out_dir):
os.makedirs(out_dir)
dem = os.path.join(out_dir, 'dem.tif')
Download samples raster datasets.
In [4]:
Copied!
if not os.path.exists(dem):
dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'
geemap.download_from_gdrive(dem_url, 'dem.tif', out_dir, unzip=False)
if not os.path.exists(dem):
dem_url = 'https://drive.google.com/file/d/1vRkAWQYsLWCi6vcTMk8vLxoXMFbdMFn8/view?usp=sharing'
geemap.download_from_gdrive(dem_url, 'dem.tif', out_dir, unzip=False)
Create an interactive map.
In [5]:
Copied!
m = geemap.Map()
m = geemap.Map()
Add local raster datasets to the map. The available palettes can be found at https://jiffyclub.github.io/palettable/
In [6]:
Copied!
m.add_local_tile(dem, palette='matplotlib.Viridis_10', layer_name="DEM")
m.add_local_tile(dem, palette='matplotlib.Viridis_10', layer_name="DEM")
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [6], in <cell line: 1>() ----> 1 m.add_local_tile(dem, palette='matplotlib.Viridis_10', layer_name="DEM") File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:585, in Map.add_local_tile(self, source, band, palette, vmin, vmax, nodata, attribution, layer_name, **kwargs) 560 def add_local_tile( 561 self, 562 source, (...) 570 **kwargs, 571 ): 572 """Add a local raster dataset to the map. 573 574 Args: (...) 582 layer_name (str, optional): The layer name to use. Defaults to None. 583 """ --> 585 tile, bounds = get_local_tile_layer( 586 source, 587 band=band, 588 palette=palette, 589 vmin=vmin, 590 vmax=vmax, 591 nodata=nodata, 592 attribution=attribution, 593 tile_format="folium", 594 layer_name=layer_name, 595 get_bounds=True, 596 **kwargs, 597 ) 598 tile.add_to(self) 599 self.zoom_to_bounds(bounds) File ~/.local/lib/python3.9/site-packages/geemap/common.py:8705, in get_local_tile_layer(source, port, debug, projection, band, palette, vmin, vmax, nodata, attribution, tile_format, layer_name, get_center, get_bounds, **kwargs) 8702 if isinstance(palette, str): 8703 from .colormaps import get_palette -> 8705 palette = get_palette(palette, hashtag=True) 8707 if tile_format not in ["ipyleaflet", "folium"]: 8708 raise ValueError("The tile format must be either ipyleaflet or folium.") File ~/.local/lib/python3.9/site-packages/geemap/colormaps.py:24, in get_palette(cmap_name, n_class, hashtag) 22 colors = _palette_dict[cmap_name] 23 else: ---> 24 cmap = plt.cm.get_cmap(cmap_name, n_class) 25 colors = [mpl.colors.rgb2hex(cmap(i))[1:] for i in range(cmap.N)] 26 if hashtag: File ~/.local/lib/python3.9/site-packages/matplotlib/cm.py:286, in get_cmap(name, lut) 284 if isinstance(name, colors.Colormap): 285 return name --> 286 _api.check_in_list(sorted(_cmap_registry), name=name) 287 if lut is None: 288 return _cmap_registry[name] File ~/.local/lib/python3.9/site-packages/matplotlib/_api/__init__.py:129, in check_in_list(_values, _print_supported_values, **kwargs) 127 if _print_supported_values: 128 msg += f"; supported values are {', '.join(map(repr, values))}" --> 129 raise ValueError(msg) ValueError: 'matplotlib.Viridis_10' is not a valid value for name; supported values are 'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'hot', 'hot_r', 'hsv', 'hsv_r', 'inferno', 'inferno_r', 'jet', 'jet_r', 'magma', 'magma_r', 'nipy_spectral', 'nipy_spectral_r', 'ocean', 'ocean_r', 'pink', 'pink_r', 'plasma', 'plasma_r', 'prism', 'prism_r', 'rainbow', 'rainbow_r', 'seismic', 'seismic_r', 'spring', 'spring_r', 'summer', 'summer_r', 'tab10', 'tab10_r', 'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c', 'tab20c_r', 'terrain', 'terrain_r', 'turbo', 'turbo_r', 'twilight', 'twilight_r', 'twilight_shifted', 'twilight_shifted_r', 'viridis', 'viridis_r', 'winter', 'winter_r'
In [7]:
Copied!
m
m
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Add a remote Cloud Optimized GeoTIFF(COG) to the map.
In [8]:
Copied!
m = geemap.Map()
m = geemap.Map()
In [9]:
Copied!
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
url = 'https://opendata.digitalglobe.com/events/california-fire-2020/pre-event/2018-02-16/pine-gulch-fire20/1030010076004E00.tif'
In [10]:
Copied!
m.add_remote_tile(url, layer_name="CA Fire")
m.add_remote_tile(url, layer_name="CA Fire")
In [11]:
Copied!
m
m
Out[11]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Last update:
2022-03-14