ee.Image.pixelArea()
生成一個影像值,影像值是計算像素的平方米,傳回一個單波段影像"area."
Generate an image in which the value of each pixel is the area of that pixel in square meters. The returned image has a single band called "area."
No arguments.
Returns: Image
很多時候我們需要計算區域統計面積,内置函數ee.Image.pixelArea()十分簡單友善,通過将單個像素的面積乘以構成對象的像素數(由 确定
connectedPixelCount()
)來計算對象面積。像素區域由生成的圖像提供
ee.Image.pixelArea()
。
代碼:
// Make an area of interest geometry centered on San Francisco.
var point = ee.Geometry.Point(-122.1899, 37.5010);
var aoi = point.buffer(10000);
// Import a Landsat 8 image, subset the thermal band, and clip to the
// area of interest.
var kelvin = ee.Image('LANDSAT/LC08/C01/T1_TOA/LC08_044034_20140318')
.select(['B10'], ['kelvin'])
.clip(aoi);
// Display the thermal band.
Map.centerObject(point, 13);
Map.addLayer(kelvin, {min: 288, max: 305}, 'Kelvin');
// Threshold the thermal band to set hot pixels as value 1, mask all else.
var hotspots = kelvin.gt(303)
.selfMask()
.rename('hotspots');
// Display the thermal hotspots on the Map.
Map.addLayer(hotspots, {palette: 'FF0000'}, 'Hotspots');
// Uniquely label the hotspot image objects.
var objectId = hotspots.connectedComponents({
connectedness: ee.Kernel.plus(1),
maxSize: 128
});
// Display the uniquely ID'ed objects to the Map.
Map.addLayer(objectId.randomVisualizer(), null, 'Objects');
// Compute the number of pixels in each object defined by the "labels" band.
var objectSize = objectId.select('labels')
.connectedPixelCount({
maxSize: 128, eightConnected: false
});
// Display object pixel count to the Map.
Map.addLayer(objectSize, null, 'Object n pixels');
// Get a pixel area image.
var pixelArea = ee.Image.pixelArea();
print("pixelArea",pixelArea)
//.
var objectArea = objectSize.multiply(pixelArea);
print("objectArea",objectArea)
// Display object area to the Map.
Map.addLayer(objectArea,
{min: 0, max: 30000, palette: ['0000FF', 'FF00FF']},
'Object area m^2');