GEE(9):区域面积统计(使用connectedPixelCount和ee.Image.pixelArea())

在GEE(Google Earth Engine)中如果想根据需要筛选区域,并计算区域面积,可以使用connectedPixelCountee.Image.pixelArea()来进行计算。


connectedPixelCount:生成一个图像,其中每个像素包含 4 或 8 领域内像素(包括其自身)的数量,4邻域为边邻域的对象,8邻域包括边邻域和角邻域的对象。

ee.Image.pixelArea():返回单个像素的面积。


connectedPixelCountee.Image.pixelArea()二者的乘积便是区域的统计面积。
下面介绍实现代码:

1. 首先加载温度数据,并筛选大于303的数据,这里的温度数据单位为开尔文

// 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/C02/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');

在这里插入图片描述

2.使用connectedPixelCount统计所筛选的区域的像素数量

// Compute the number of pixels in each object defined by the "labels" band.
var objectSize = hotspots
  .connectedPixelCount({
    maxSize: 128, eightConnected: false
  });

// Display object pixel count to the Map.
Map.addLayer(objectSize, null, 'Object n pixels');

在这里插入图片描述

3.计算筛选区域的面积,单位为㎡

// Get a pixel area image.
var pixelArea = ee.Image.pixelArea();

// Multiply pixel area by the number of pixels in an object to calculate
// the object area. The result is an image where each pixel
// of an object relates the area of the object in m^2.
var objectArea = objectSize.multiply(pixelArea);

// Display object area to the Map.
Map.addLayer(objectArea,
             {min: 0, max: 30000, palette: ['0000FF', 'FF00FF']},
             'Object area m^2');

4.根据计算面积值的大小筛选区域

// Threshold the `objectArea` image to define a mask that will mask out
// objects below a given size (1 hectare in this case).
var areaMask = objectArea.gte(10000);

// Update the mask of the `objectId` layer defined previously using the
// minimum area mask just defined.
objectId = objectId.updateMask(areaMask);
Map.addLayer(objectId, null, 'Large hotspots');

小结:connectedPixelCount这一函数主要是用于上述中类似的情况,返回的是一影像,包含了每个像素相邻近的个数,参数中的maxSize 是指每个像素邻域的最大值,可根据需要进行设置。常用于比如根据反射率大小或其他因素筛选出来了区域,想要统计区域的面积;或者在筛选出区域后,根据像素邻域数量的值的大小进一步筛选成片的区域,即连接度较高的区域,该方法也常用在水体的提取上。

  • 4
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GISerQ.

你的鼓励将是我创作的最大动力。

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值