Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/tutorials/Image/01_image_overview.ipynb
2313 views
Kernel: Python 3

Image Overview

As mentioned in the Get Started doc, raster data are represented as Image objects in Earth Engine. Images are composed of one or more bands and each band has its own name, data type, scale, mask and projection. Each image has metadata stored as a set of properties.

In addition to loading images from the archive by an image ID, you can also create images from constants, lists or other suitable Earth Engine objects. The following illustrates methods for creating images, getting band subsets, and manipulating bands:

Install Earth Engine API and geemap

Install the Earth Engine Python API and geemap. The geemap Python package is built upon the ipyleaflet and folium packages and implements several methods for interacting with Earth Engine data layers, such as Map.addLayer(), Map.setCenter(), and Map.centerObject(). The following script checks if the geemap package has been installed. If not, it will install geemap, which automatically installs its dependencies, including earthengine-api, folium, and ipyleaflet.

Important note: A key difference between folium and ipyleaflet is that ipyleaflet is built upon ipywidgets and allows bidirectional communication between the front-end and the backend enabling the use of the map to capture user input, while folium is meant for displaying static data only (source). Note that Google Colab currently does not support ipyleaflet (source). Therefore, if you are using geemap with Google Colab, you should use import geemap.foliumap. If you are using geemap with binder or a local Jupyter notebook server, you can use import geemap, which provides more functionalities for capturing user input (e.g., mouse-clicking and moving).

# Installs geemap package import subprocess try: import geemap except ImportError: print("geemap package not installed. Installing ...") subprocess.check_call(["python", "-m", "pip", "install", "geemap"]) # Checks whether this notebook is running on Google Colab try: import google.colab import geemap.foliumap as emap except: import geemap as emap # Authenticates and initializes Earth Engine import ee try: ee.Initialize() except Exception as e: ee.Authenticate() ee.Initialize()

Create an interactive map

The default basemap is Google Satellite. Additional basemaps can be added using the Map.add_basemap() function.

Map = geemap.Map(center=[40, -100], zoom=4) Map.add_basemap("ROADMAP") # Add Google Map Map

Add Earth Engine Python script

# Create a constant image. image1 = ee.Image(1) print(image1.getInfo())
# Concatenate two images into one multi-band image. image2 = ee.Image(2) image3 = ee.Image.cat([image1, image2]) print(image3.getInfo())
# Create a multi-band image from a list of constants. multiband = ee.Image([1, 2, 3]) print(multiband.getInfo())
# Select and (optionally) rename bands. renamed = multiband.select( ["constant", "constant_1", "constant_2"], # old names ["band1", "band2", "band3"], # new names ) print(renamed.getInfo())
# Add bands to an image. image4 = image3.addBands(ee.Image(42)) print(image4.getInfo())

Display Earth Engine data layers

Map.addLayerControl() Map