ee.Geometry.coveringGrid

傳回涵蓋這個幾何圖形的特徵集合,其中每個特徵都是指定投影所定義格線中的矩形。

用量傳回
Geometry.coveringGrid(proj, scale)FeatureCollection
引數類型詳細資料
this: geometry幾何圖形結果是與這個區域相交的格線儲存格。
proj預測值要建構格線的投影。系統會為每個與「geometry」相交的格線儲存格產生特徵,其中儲存格的角落位於投影中的整數值位置。如果投影是以公尺為單位縮放,點會位於真實比例的該大小格線。
scale浮點值,預設值:null如果提供投影比例,則會覆寫該比例。如果投影尚未縮放,可能需要此屬性。

示例

程式碼編輯器 (JavaScript)

// Define the coordinate reference system (CRS) to be used for grid alignment.
// WGS 84 / UTM zone 36S.
var epsg = 'EPSG:32736';

// Create a point geometry to serve as the center for the analysis.
var point = ee.Geometry.Point(31.6, -8.54);

Map.addLayer(point, {color: 'orange'}, 'Center');
Map.centerObject(point, 8);

// Create a circular buffer of 100,000 meters (100 km) around the point to
// define the study area.
var areaOfInterest = point.buffer(100000);
Map.addLayer(areaOfInterest, {color: 'purple'}, 'Area of interest');

// Calculate a scale value to determine the size of the grid cells.
// Use a power of 2 for best GeoTIFF tiling, e.g., assuming that we'll use the
// grid cell to define image export regions, 2**14 -> 16384.
var scale = Math.pow(2, 14);

// Generate a FeatureCollection of grid cells that covers the buffered area
// using the specified projection and scale.
var grid = areaOfInterest.coveringGrid({proj: epsg, scale: scale});
Map.addLayer(grid, {color: 'blue'}, 'Covering Grid', true, 0.5);

// Define the specific index string of the grid cell to be extracted.
var cellOfInterest = '18,551';
// Filter the grid collection to find the feature matching the index and
// retrieve it as an ee.Feature.
var feature =
    ee.Feature(grid.toList(10000)
                   .filter(ee.Filter.eq('system:index', cellOfInterest))
                   .get(0));
Map.addLayer(feature, {color: 'red'}, 'grid cell', true, 0.5);

// One common use of coveringGrid is to tile operations such as exports.
// This often involves iterating through grid cells on the client-side to
// submit tasks for each cell. Here we print each cell ID using evaluate().
print('Grid cell IDs:');
grid.aggregate_array('system:index').evaluate(function(cellIds) {
  cellIds.forEach(function(cellId) {
    print(cellId);
  });
});