ImageCollection
是图像的堆叠或序列。您可以通过将 Earth Engine 资产 ID 粘贴到 ImageCollection
构造函数中来加载 ImageCollection
。您可以在数据目录中找到 ImageCollection
ID。例如,如需加载 Sentinel-2 地表反射率集合,请执行以下操作:
Code Editor (JavaScript)
var sentinelCollection = ee.ImageCollection('COPERNICUS/S2_SR');
import ee import geemap.core as geemap
Colab (Python)
sentinel_collection = ee.ImageCollection('COPERNICUS/S2_SR')
此集合包含公开目录中的每张 Sentinel-2 图像。有很多。 通常,您需要按此处或此处所示过滤合集。
除了使用 Earth Engine 集合 ID 加载 ImageCollection
之外,Earth Engine 还提供了创建图像集合的方法。构造函数 ee.ImageCollection()
或便捷方法 ee.ImageCollection.fromImages()
可根据图片列表创建图片集合。您还可以通过合并现有图库来创建新的图库。
例如:
Code Editor (JavaScript)
// Create arbitrary constant images. var constant1 = ee.Image(1); var constant2 = ee.Image(2); // Create a collection by giving a list to the constructor. var collectionFromConstructor = ee.ImageCollection([constant1, constant2]); print('collectionFromConstructor: ', collectionFromConstructor); // Create a collection with fromImages(). var collectionFromImages = ee.ImageCollection.fromImages( [ee.Image(3), ee.Image(4)]); print('collectionFromImages: ', collectionFromImages); // Merge two collections. var mergedCollection = collectionFromConstructor.merge(collectionFromImages); print('mergedCollection: ', mergedCollection); // Create a toy FeatureCollection var features = ee.FeatureCollection( [ee.Feature(null, {foo: 1}), ee.Feature(null, {foo: 2})]); // Create an ImageCollection from the FeatureCollection // by mapping a function over the FeatureCollection. var images = features.map(function(feature) { return ee.Image(ee.Number(feature.get('foo'))); }); // Print the resultant collection. print('Image collection: ', images);
import ee import geemap.core as geemap
Colab (Python)
# Create arbitrary constant images. constant_1 = ee.Image(1) constant_2 = ee.Image(2) # Create a collection by giving a list to the constructor. collection_from_constructor = ee.ImageCollection([constant_1, constant_2]) display('Collection from constructor:', collection_from_constructor) # Create a collection with fromImages(). collection_from_images = ee.ImageCollection.fromImages( [ee.Image(3), ee.Image(4)] ) display('Collection from images:', collection_from_images) # Merge two collections. merged_collection = collection_from_constructor.merge(collection_from_images) display('Merged collection:', merged_collection) # Create a toy FeatureCollection features = ee.FeatureCollection( [ee.Feature(None, {'foo': 1}), ee.Feature(None, {'foo': 2})] ) # 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')))) # Display the resultant collection. display('Image collection:', images)
请注意,在此示例中,ImageCollection
是通过将返回 Image
的函数映射到 FeatureCollection
而创建的。如需详细了解映射,请参阅“映射 ImageCollection”部分。
如需详细了解地图项集合,请参阅 FeatureCollection 部分。
您还可以使用 Cloud Storage 中的 GeoTiff 创建 ImageCollection
。例如:
Code Editor (JavaScript)
// All the GeoTiffs are in this folder. var uriBase = 'gs://gcp-public-data-landsat/LC08/01/001/002/' + 'LC08_L1GT_001002_20160817_20170322_01_T2/'; // List of URIs, one for each band. var uris = ee.List([ uriBase + 'LC08_L1GT_001002_20160817_20170322_01_T2_B2.TIF', uriBase + 'LC08_L1GT_001002_20160817_20170322_01_T2_B3.TIF', uriBase + 'LC08_L1GT_001002_20160817_20170322_01_T2_B4.TIF', uriBase + 'LC08_L1GT_001002_20160817_20170322_01_T2_B5.TIF', ]); // Make a collection from the list of images. var images = uris.map(ee.Image.loadGeoTIFF); var collection = ee.ImageCollection(images); // Get an RGB image from the collection of bands. var rgb = collection.toBands().rename(['B2', 'B3', 'B4', 'B5']); Map.centerObject(rgb); Map.addLayer(rgb, {bands: ['B4', 'B3', 'B2'], min: 0, max: 20000}, 'rgb');
import ee import geemap.core as geemap
Colab (Python)
# All the GeoTiffs are in this folder. uri_base = ( 'gs://gcp-public-data-landsat/LC08/01/001/002/' + 'LC08_L1GT_001002_20160817_20170322_01_T2/' ) # List of URIs, one for each band. uris = ee.List([ uri_base + 'LC08_L1GT_001002_20160817_20170322_01_T2_B2.TIF', uri_base + 'LC08_L1GT_001002_20160817_20170322_01_T2_B3.TIF', uri_base + 'LC08_L1GT_001002_20160817_20170322_01_T2_B4.TIF', uri_base + 'LC08_L1GT_001002_20160817_20170322_01_T2_B5.TIF', ]) # Make a collection from the list of images. images = uris.map(lambda uri: ee.Image.loadGeoTIFF(uri)) collection = ee.ImageCollection(images) # Get an RGB image from the collection of bands. rgb = collection.toBands().rename(['B2', 'B3', 'B4', 'B5']) m = geemap.Map() m.center_object(rgb) m.add_layer(rgb, {'bands': ['B4', 'B3', 'B2'], 'min': 0, 'max': 20000}, 'rgb') m