天天看點

GEE筆記(二):影像篩選和加載

1. 篩選影像

  • 可以用工具選擇自己所需的區域,編輯器會自動導入你所選的位置資訊。變量名可以自己修改。我修改為"guanting"
    GEE筆記(二):影像篩選和加載
//按照時間和位置篩選影像,加載的T1_SR影像,已經過大氣校正。
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR').filterBounds(guanting)
.filterDate('2020-06-01','2020-09-17');
// 按照雲量排序
var sorted = collection.sort('CLOUD_COVER');
var scene = sorted.first();
print('collection',collection);
print('sorted',sorted);
print('scene',scene);
var visParams = {bands:['B4','B3','B2'],min:0,max:2000};
Map.addLayer(scene,visParams,'432');
           

T1_SR 資料已經過大氣校正

var need = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
	.filterDate('2020-01-01', '2020-09-17')
	.filterBounds(guanting);
	print('need',need);
           

2. 影像可視化

可以使用

Map.addLayer()

可視化圖像。 如果在沒有任何其他參數的情況下向地圖添加圖層,則預設情況下,代碼編輯器會将前三個波段分别配置設定給紅色,綠色和藍色。 預設範圍是基于波段中的資料類型(例如,浮點數以[0,1]進行拉伸,16位資料被擴充為可能的值的整個範圍),這可能合适也可能不合适。 為了獲得理想的可視化效果,可以向

Map.addLayer()

提供可視化參數。 具體來說,這些參數是:

Parameter Description Type
bands Comma-delimited list of three band names to be mapped to RGB list
min Value(s) to map to 0 number or list of three numbers, one for each band
max Value(s) to map to 255 number or list of three numbers, one for each band
gain Value(s) by which to multiply each pixel value number or list of three numbers, one for each band
bias Value(s) to add to each DN number or list of three numbers, one for each band
gamma Gamma correction factor(s) number or list of three numbers, one for each band
palette List of CSS-style color strings (single-band images only) comma-separated list of hex strings
opacity The opacity of the layer (0.0 is fully transparent and 1.0 is fully opaque) number
format Either “jpg” or “png” string
Map.addLayer(image, {min: 0, max: 3000, palette: ['blue', 'green', 'red']},
    'custom palette');
           

a. RGB 合成

// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');

// Define the visualization parameters.
var vizParams = {
  bands: ['B5', 'B4', 'B3'],
  min: 0,
  max: 0.5,
  gamma: [0.95, 1.1, 1]
};

// Center the map and display the image.
Map.setCenter(-122.1899, 37.5010, 10); // San Francisco Bay
Map.addLayer(image, vizParams, 'false color composite');
           

b. 調色闆

// Load an image.
var image = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318');

// Create an NDWI image, define visualization parameters and display.
var ndwi = image.normalizedDifference(['B3', 'B5']);
var ndwiViz = {min: 0.5, max: 1, palette: ['00FFFF', '0000FF']};
Map.addLayer(ndwi, ndwiViz, 'NDWI', false);
           

c. 掩膜

// Mask the non-watery parts of the image, where NDWI < 0.4.
var ndwiMasked = ndwi.updateMask(ndwi.gte(0.4));
Map.addLayer(ndwiMasked, ndwiViz, 'NDWI masked');
           

d. 可視化圖像

// Create visualization layers.
var imageRGB = image.visualize({bands: ['B5', 'B4', 'B3'], max: 0.5});
var ndwiRGB = ndwiMasked.visualize({
  min: 0.5,
  max: 1,
  palette: ['00FFFF', '0000FF']
});
           

3. 循環

使用

map()

周遊集合中的項目。

map()

函數可以應用于ImageCollection,FeatureCollection或List并接受function作為其參數。 函數的自變量是映射到集合的元素。 這對于以相同方式修改集合的每個元素(例如添加)很有用。 例如,以下代碼将NDVI波段添加到“ ImageCollection”中的每個圖像:

// This function gets NDVI from Landsat 8 imagery.
var addNDVI = function(image) {
  return image.addBands(image.normalizedDifference(['B5', 'B4']));
};

// Load the Landsat 8 raw data, filter by location and date.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1')
  .filterBounds(ee.Geometry.Point(-122.262, 37.8719))
  .filterDate('2014-06-01', '2014-10-01');

// Map the function over the collection.
var ndviCollection = collection.map(addNDVI);