GEE——如何统计研究区像素数量

举报
此星光明 发表于 2023/01/08 18:36:50 2023/01/08
【摘要】 ​很多时候我们想统计研究区的像素数量,但是用错了函数,本来用ee.reducer.sum(), ee.reducer.count()混淆使用,我们发现有很多人要统计像素数量,但却统计成了总量,所以我们首先要看下两个函数如何使用:ee.Reducer.sum()Returns a Reducer that computes the (weighted) sum of its inputs.No...

很多时候我们想统计研究区的像素数量,但是用错了函数,本来用ee.reducer.sum(), ee.reducer.count()混淆使用,我们发现有很多人要统计像素数量,但却统计成了总量,所以我们首先要看下两个函数如何使用:

ee.Reducer.sum()

Returns a Reducer that computes the (weighted) sum of its inputs.

No arguments.

Returns: Reducer

ee.Reducer.count()

Returns a Reducer that computes the number of non-null inputs.

No arguments.

Returns: Reducer

reduceRegion(reducer, geometryscalecrscrsTransformbestEffortmaxPixelstileScale)

Apply a reducer to all the pixels in a specific region.

Either the reducer must have the same number of inputs as the input image has bands, or it must have a single input and will be repeated for each band.

Returns a dictionary of the reducer's outputs.

Arguments:

this:image (Image):

The image to reduce.

reducer (Reducer):

The reducer to apply.

geometry (Geometry, default: null):

The region over which to reduce data. Defaults to the footprint of the image's first band.

scale (Float, default: null):

A nominal scale in meters of the projection to work in.

crs (Projection, default: null):

The projection to work in. If unspecified, the projection of the image's first band is used. If specified in addition to scale, rescaled to the specified scale.

crsTransform (List, default: null):

The list of CRS transform values. This is a row-major ordering of the 3x2 transform matrix. This option is mutually exclusive with 'scale', and replaces any transform already set on the projection.

bestEffort (Boolean, default: false):

If the polygon would contain too many pixels at the given scale, compute and use a larger scale which would allow the operation to succeed.

maxPixels (Long, default: 10000000):

The maximum number of pixels to reduce.

tileScale (Float, default: 1):

A scaling factor between 0.1 and 16 used to adjust aggregation tile size; setting a larger tileScale (e.g. 2 or 4) uses smaller tiles and may enable computations that run out of memory with the default.

Returns: Dictionary

代码:

var image = ee.Image("projects/ee-cananhamzaolu/assets/Sr_connect0");

Map.addLayer(image,{}, 'Grayscale_Otsu')
Map.centerObject(image);
var s=image.selfMask().reduceRegion({
            reducer: ee.Reducer.sum(),
            scale:100
    })
print(s)


var s = image.selfMask().reduceRegion({
  reducer: ee.Reducer.count(),
  maxPixels: 1e16,
});
print(s);

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。