影像圖斑統(tǒng)計功能實現(xiàn)
主要功能
對SRTM數(shù)據(jù)的特定范圍完成空間統(tǒng)計,輸出指定矩形范圍內(nèi)的最大值
代碼
// 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);
步驟分析
- 創(chuàng)建ee對象,獲取SRTM數(shù)據(jù)
- 創(chuàng)建ee對象,創(chuàng)建矩形地理要素(兩點)
- 空間統(tǒng)計
- 輸出結(jié)果
主要方法
- 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
創(chuàng)建一個ee的地理要素對象,形狀為矩形的多邊形。為了方便,允許使用兩點法創(chuàng)建EPSG:4326投影下的矩形,輸入(最小經(jīng)度,最小緯度,最大經(jīng)度,最大緯度)。
輸入?yún)?shù):
輸入坐標(biāo)(矩形兩點坐標(biāo),使用GeoJSON格式的點坐標(biāo),或者一個包含兩個點的list,或者包含四個值的list,依次為xMin, yMin, xMax, yMax)
投影:(默認(rèn)為EPSG:4326)
geodesic:
evenOdd:
- 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
對指定區(qū)域內(nèi)的所有像素執(zhí)行一個空間統(tǒng)計。輸入的reducer必須與影像波段數(shù)相同,或者只輸入一個,但是對所有影像波段重復(fù)執(zhí)行。
輸入?yún)?shù):
輸入影像對象,ruducer,geomtry(掩膜范圍,默認(rèn)是輸入影像第一波段范圍),scale,crs,crsTransform,bestEffort,maxPixels,tileScale
- 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
輸出最大值,如果輸入的參數(shù)大于1,輸入對應(yīng)排序的值