GEE案例

GEE区域统计

2019-01-03  本文已影响0人  赤豆冰棍

影像图斑统计功能实现

主要功能

对SRTM数据的特定范围完成空间统计,输出指定矩形范围内的最大值

代码

// Image.reduceRegion example
//
// Computes a simple reduction over a region of an image.  A reduction
// is any process that takes an arbitrary number of inputs (such as
// all the pixels of an image in a given region) and computes one or
// more fixed outputs.  The result is a dictionary that contains the
// computed values, which in this example is the maximum pixel value
// in the region.

// This example shows how to print the resulting dictionary to the
// console, which is useful when developing and debugging your
// scripts, but in a larger workflow you might instead use the
// Dicitionary.get() function to extract the values you need from the
// dictionary for use as inputs to other functions.

// The input image to reduce, in this case an SRTM elevation map.
var image = ee.Image('CGIAR/SRTM90_V4');

// The region to reduce within.
var poly = ee.Geometry.Rectangle([-109.05, 41, -102.05, 37]);

// Reduce the image within the given region, using a reducer that
// computes the max pixel value.  We also specify the spatial
// resolution at which to perform the computation, in this case 200
// meters.
var max = image.reduceRegion({
  reducer: ee.Reducer.max(),
  geometry: poly,
  scale: 200
});

// Print the result (a Dictionary) to the console.
print(max);

步骤分析

  1. 创建ee对象,获取SRTM数据
  2. 创建ee对象,创建矩形地理要素(两点)
  3. 空间统计
  4. 输出结果

主要方法

  1. ee.Geometry.Rectangle()

Constructs an ee.Geometry describing a rectangular polygon.
For convenience, varargs may be used when all arguments are numbers. This allows creating EPSG:4326 Polygons given exactly four coordinates, e.g. ee.Geometry.Rectangle(minLng, minLat, maxLng, maxLat).
Arguments:
coords (List<Geometry>|List<List<Number>>|List<Number>):
The minimum and maximum corners of the rectangle, as a list of two points each in the format of GeoJSON 'Point' coordinates, or a list of two ee.Geometry describing a point, or a list of four numbers in the order xMin, yMin, xMax, yMax.
proj (Projection, optional):
The projection of this geometry. If unspecified, the default is the projection of the input ee.Geometry, or EPSG:4326 if there are no ee.Geometry inputs.
geodesic (Boolean, optional):
If false, edges are straight in the projection. If true, edges are curved to follow the shortest path on the surface of the Earth. The default is the geodesic state of the inputs, or true if the inputs are numbers.
evenOdd (Boolean, optional):
If true, polygon interiors will be determined by the even/odd rule, where a point is inside if it crosses an odd number of edges to reach a point at infinity. Otherwise polygons use the left- inside rule, where interiors are on the left side of the shell's edges when walking the vertices in the given order. If unspecified, defaults to true.
Returns: Geometry.Rectangle

创建一个ee的地理要素对象,形状为矩形的多边形。为了方便,允许使用两点法创建EPSG:4326投影下的矩形,输入(最小经度,最小纬度,最大经度,最大纬度)。
输入参数:
输入坐标(矩形两点坐标,使用GeoJSON格式的点坐标,或者一个包含两个点的list,或者包含四个值的list,依次为xMin, yMin, xMax, yMax)
投影:(默认为EPSG:4326)
geodesic:
evenOdd:

  1. ee.Image.reduceRegion()
    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 used to reduce aggregation tile size; using a larger tileScale (e.g. 2 or 4) may enable computations that run out of memory with the default.
    Returns: Dictionary

对指定区域内的所有像素执行一个空间统计。输入的reducer必须与影像波段数相同,或者只输入一个,但是对所有影像波段重复执行。
输入参数:
输入影像对象,ruducer,geomtry(掩膜范围,默认是输入影像第一波段范围),scale,crs,crsTransform,bestEffort,maxPixels,tileScale

  1. ee.Reducer.max()
    Creates a reducer that outputs the maximum value of its (first) input. If numInputs is greater than one, also outputs the corresponding values of the additional inputs.
    Arguments:
    numInputs (Integer, default: 1):
    The number of inputs.
    Returns: Reducer

输出最大值,如果输入的参数大于1,输入对应排序的值

上一篇下一篇

猜你喜欢

热点阅读