Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/examples/template/template.py
2313 views
1
# %%
2
"""
3
<table class="ee-notebook-buttons" align="left">
4
<td><a target="_blank" href="https://github.com/gee-community/geemap/tree/master/examples/template/template.ipynb"><img width=32px src="https://www.tensorflow.org/images/GitHub-Mark-32px.png" /> View source on GitHub</a></td>
5
<td><a target="_blank" href="https://nbviewer.jupyter.org/github/gee-community/geemap/blob/master/examples/template/template.ipynb"><img width=26px src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Jupyter_logo.svg/883px-Jupyter_logo.svg.png" />Notebook Viewer</a></td>
6
<td><a target="_blank" href="https://colab.research.google.com/github/gee-community/geemap/blob/master/examples/template/template.ipynb"><img src="https://www.tensorflow.org/images/colab_logo_32px.png" /> Run in Google Colab</a></td>
7
</table>
8
"""
9
10
# %%
11
"""
12
## Install Earth Engine API and geemap
13
Install the [Earth Engine Python API](https://developers.google.com/earth-engine/python_install) and [geemap](https://geemap.org). The **geemap** Python package is built upon the [ipyleaflet](https://github.com/jupyter-widgets/ipyleaflet) and [folium](https://github.com/python-visualization/folium) packages and implements several methods for interacting with Earth Engine data layers, such as `Map.addLayer()`, `Map.setCenter()`, and `Map.centerObject()`.
14
The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its [dependencies](https://github.com/gee-community/geemap#dependencies), including earthengine-api, folium, and ipyleaflet.
15
"""
16
17
# %%
18
# Installs geemap package
19
import subprocess
20
21
try:
22
import geemap
23
except ImportError:
24
print("Installing geemap ...")
25
subprocess.check_call(["python", "-m", "pip", "install", "geemap"])
26
27
# %%
28
import ee
29
import geemap
30
31
# %%
32
"""
33
## Create an interactive map
34
The default basemap is `Google Maps`. [Additional basemaps](https://github.com/gee-community/geemap/blob/master/geemap/basemaps.py) can be added using the `Map.add_basemap()` function.
35
"""
36
37
# %%
38
Map = geemap.Map(center=[40, -100], zoom=4)
39
Map
40
41
# %%
42
"""
43
## Add Earth Engine Python script
44
"""
45
46
# %%
47
# Add Earth Engine dataset
48
image = ee.Image("USGS/SRTMGL1_003")
49
50
# Set visualization parameters.
51
vis_params = {
52
"min": 0,
53
"max": 4000,
54
"palette": ["006633", "E5FFCC", "662A00", "D8D8D8", "F5F5F5"],
55
}
56
57
# Print the elevation of Mount Everest.
58
xy = ee.Geometry.Point([86.9250, 27.9881])
59
elev = image.sample(xy, 30).first().get("elevation").getInfo()
60
print("Mount Everest elevation (m):", elev)
61
62
# Add Earth Engine layers to Map
63
Map.addLayer(image, vis_params, "DEM")
64
Map.addLayer(xy, {"color": "red"}, "Mount Everest")
65
66
# Center the map based on an Earth Engine object or coordinates (longitude, latitude)
67
# Map.centerObject(xy, 4)
68
Map.setCenter(86.9250, 27.9881, 4)
69
70
# %%
71
"""
72
## Display Earth Engine data layers
73
"""
74
75
# %%
76
Map.addLayerControl() # This line is not needed for ipyleaflet-based Map.
77
Map
78
79