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

ImageCollection Overview

An ImageCollection is a stack or time series of images. In addition to loading an ImageCollection using an Earth Engine collection ID, Earth Engine has methods to create image collections. The constructor ee.ImageCollection() or the convenience method ee.ImageCollection.fromImages() create image collections from lists of images. You can also create new image collections by merging existing collections. For example:

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 arbitrary constant images. constant1 = ee.Image(1) constant2 = ee.Image(2) # Create a collection by giving a list to the constructor. collectionFromConstructor = ee.ImageCollection([constant1, constant2]) print("collectionFromConstructor: ", collectionFromConstructor.getInfo())
# Create a collection with fromImages(). collectionFromImages = ee.ImageCollection.fromImages([ee.Image(3), ee.Image(4)]) print("collectionFromImages: ", collectionFromImages.getInfo())
# Merge two collections. mergedCollection = collectionFromConstructor.merge(collectionFromImages) print("mergedCollection: ", mergedCollection.getInfo())
# Create an ee.Geometry. polygon = ee.Geometry.Polygon( [[[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]] ) # Create a toy FeatureCollection features = ee.FeatureCollection( [ee.Feature(polygon, {"foo": 1}), ee.Feature(polygon, {"foo": 2})] ) print(features.getInfo()) # Create an ImageCollection from the FeatureCollection # by mapping a function over the FeatureCollection. images = features.map(lambda feature: ee.Image(ee.Number(feature.get("foo")))) # Print the resultant collection. print("Image collection: ", images.getInfo())

Display Earth Engine data layers

Map.addLayerControl() Map

Note that in this example an ImageCollection is created by mapping a function that returns an Image over a FeatureCollection. Learn more about mapping in the Mapping over an ImageCollection section. Learn more about feature collections from the FeatureCollection section.