24 publish maps
Uncomment the following line to install geemap if needed.
In [1]:
Copied!
# !pip install geemap
# !pip install geemap
To follow this tutorial, you will need to sign up for an account with https://datapane.com, then install and authenticate the datapane
Python package. More information can be found here.
pip install datapane
datapane login
datapane ping
In [2]:
Copied!
import ee
import geemap.foliumap as geemap
import ee
import geemap.foliumap as geemap
In [3]:
Copied!
# Create a map centered at (lat, lon).
Map = geemap.Map(center=[40, -100], zoom=4)
# Use an elevation dataset and terrain functions to create
# a custom visualization of topography.
# Load a global elevation image.
elev = ee.Image('USGS/GMTED2010')
# Zoom to an area of interest.
Map.setCenter(-121.069, 50.709, 6)
# Add the elevation to the map.
Map.addLayer(elev, {}, 'elev')
# Use the terrain algorithms to compute a hillshade with 8-bit values.
shade = ee.Terrain.hillshade(elev)
Map.addLayer(shade, {}, 'hillshade', False)
# Create a "sea" variable to be used for cartographic purposes
sea = elev.lte(0)
Map.addLayer(sea.mask(sea), {'palette': '000022'}, 'sea', False)
# Create a custom elevation palette from hex strings.
elevationPalette = ['006600', '002200', 'fff700', 'ab7634', 'c4d0ff', 'ffffff']
# Use these visualization parameters, customized by location.
visParams = {'min': 1, 'max': 3000, 'palette': elevationPalette}
# Create a mosaic of the sea and the elevation data
visualized = ee.ImageCollection(
[
# Mask the elevation to get only land
elev.mask(sea.Not()).visualize(**visParams),
# Use the sea mask directly to display sea.
sea.mask(sea).visualize(**{'palette': '000022'}),
]
).mosaic()
# Note that the visualization image doesn't require visualization parameters.
Map.addLayer(visualized, {}, 'elev palette', False)
# Convert the visualized elevation to HSV, first converting to [0, 1] data.
hsv = visualized.divide(255).rgbToHsv()
# Select only the hue and saturation bands.
hs = hsv.select(0, 1)
# Convert the hillshade to [0, 1] data, as expected by the HSV algorithm.
v = shade.divide(255)
# Create a visualization image by converting back to RGB from HSV.
# Note the cast to byte in order to export the image correctly.
rgb = hs.addBands(v).hsvToRgb().multiply(255).byte()
Map.addLayer(rgb, {}, 'styled')
states = ee.FeatureCollection('TIGER/2018/States')
Map.addLayer(ee.Image().paint(states, 0, 2), {}, "US States")
# Create a map centered at (lat, lon).
Map = geemap.Map(center=[40, -100], zoom=4)
# Use an elevation dataset and terrain functions to create
# a custom visualization of topography.
# Load a global elevation image.
elev = ee.Image('USGS/GMTED2010')
# Zoom to an area of interest.
Map.setCenter(-121.069, 50.709, 6)
# Add the elevation to the map.
Map.addLayer(elev, {}, 'elev')
# Use the terrain algorithms to compute a hillshade with 8-bit values.
shade = ee.Terrain.hillshade(elev)
Map.addLayer(shade, {}, 'hillshade', False)
# Create a "sea" variable to be used for cartographic purposes
sea = elev.lte(0)
Map.addLayer(sea.mask(sea), {'palette': '000022'}, 'sea', False)
# Create a custom elevation palette from hex strings.
elevationPalette = ['006600', '002200', 'fff700', 'ab7634', 'c4d0ff', 'ffffff']
# Use these visualization parameters, customized by location.
visParams = {'min': 1, 'max': 3000, 'palette': elevationPalette}
# Create a mosaic of the sea and the elevation data
visualized = ee.ImageCollection(
[
# Mask the elevation to get only land
elev.mask(sea.Not()).visualize(**visParams),
# Use the sea mask directly to display sea.
sea.mask(sea).visualize(**{'palette': '000022'}),
]
).mosaic()
# Note that the visualization image doesn't require visualization parameters.
Map.addLayer(visualized, {}, 'elev palette', False)
# Convert the visualized elevation to HSV, first converting to [0, 1] data.
hsv = visualized.divide(255).rgbToHsv()
# Select only the hue and saturation bands.
hs = hsv.select(0, 1)
# Convert the hillshade to [0, 1] data, as expected by the HSV algorithm.
v = shade.divide(255)
# Create a visualization image by converting back to RGB from HSV.
# Note the cast to byte in order to export the image correctly.
rgb = hs.addBands(v).hsvToRgb().multiply(255).byte()
Map.addLayer(rgb, {}, 'styled')
states = ee.FeatureCollection('TIGER/2018/States')
Map.addLayer(ee.Image().paint(states, 0, 2), {}, "US States")
In [4]:
Copied!
# Display the map.
Map
# Display the map.
Map
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [5]:
Copied!
Map.publish(
name='Terrain Visualization',
description='A folium map with Earth Engine data layers',
)
Map.publish(
name='Terrain Visualization',
description='A folium map with Earth Engine data layers',
)
Bokeh version 2.4.2 is not supported, these plots may not display correctly, please install version ~=2.2.0
Uploading report and associated data - please wait...
Your report only contains a single element - did you know you can include additional plots, tables and text in a single report? More info here
--------------------------------------------------------------------------- InvalidTokenError Traceback (most recent call last) File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:1573, in Map.publish(self, name, description, source_url, tags, source_file, open, formatting, **kwargs) 1571 try: -> 1573 dp.Report(dp.Plot(self)).upload( 1574 name=name, 1575 description=description, 1576 source_url=source_url, 1577 tags=tags, 1578 source_file=source_file, 1579 open=open, 1580 formatting=formatting, 1581 ) 1583 except Exception as e: File ~/.local/lib/python3.9/site-packages/datapane/client/api/report/core.py:420, in Report.upload(self, name, description, source_url, visibility, tags, project, source_file, open, formatting, **kwargs) 418 display_msg("Uploading report and associated data - *please wait...*") --> 420 self._upload_report( 421 name, description, source_url, visibility, tags, project, source_file, formatting=formatting, **kwargs 422 ) 424 if open: File ~/.local/lib/python3.9/site-packages/datapane/client/api/report/core.py:381, in Report._upload_report(self, name, description, source_url, visibility, tags, project, source_file, formatting, **kwargs) 380 files["source_file"] = [output_file.file] --> 381 res = Resource(self.endpoint).post_files(files, document=report_str, **kwargs) 383 # Set dto based on new URL File ~/.local/lib/python3.9/site-packages/datapane/client/api/common.py:162, in Resource.__init__(self, endpoint) 161 self.endpoint = endpoint.split("/api", maxsplit=1)[-1] --> 162 config = c.check_get_config() 163 self.url = up.urljoin(config.server, f"api{self.endpoint}") File ~/.local/lib/python3.9/site-packages/datapane/client/config.py:183, in check_get_config() 182 webbrowser.open(url=str(f), new=2) --> 183 raise InvalidTokenError( 184 "Please sign-up and login - if you already have then please restart your Jupyter kernel/Python instance to initialize your new token" 185 ) 186 return _config InvalidTokenError: Please sign-up and login - if you already have then please restart your Jupyter kernel/Python instance to initialize your new token Please run with `dp.enable_logging()`, restart your Jupyter kernel/Python instance, and/or visit https://www.github.com/datapane/datapane to raise issue / discuss if error repeats During handling of the above exception, another exception occurred: Exception Traceback (most recent call last) Input In [5], in <cell line: 1>() ----> 1 Map.publish( 2 name='Terrain Visualization', 3 description='A folium map with Earth Engine data layers', 4 ) File ~/.local/lib/python3.9/site-packages/geemap/foliumap.py:1584, in Map.publish(self, name, description, source_url, tags, source_file, open, formatting, **kwargs) 1573 dp.Report(dp.Plot(self)).upload( 1574 name=name, 1575 description=description, (...) 1580 formatting=formatting, 1581 ) 1583 except Exception as e: -> 1584 raise Exception(e) Exception: Please sign-up and login - if you already have then please restart your Jupyter kernel/Python instance to initialize your new token Please run with `dp.enable_logging()`, restart your Jupyter kernel/Python instance, and/or visit https://www.github.com/datapane/datapane to raise issue / discuss if error repeats
Last update:
2022-03-14