简介
本教程的主要目的是获取指定单景影像,然后获取指定波段的影像值,按照获取指定波段的影像进行值提取至点,因为这里暂时没有好的方法对哨兵数据的具体属性值进行提取,所以在筛选哨兵影像的时候,需要手动获取每一景影像的id,然后按照单一影像多波段的组合来实现整体的值提取至点,这里的需要提前准备好你所需提取的矢量数据集合.
函数
reduceRegions(collection, reducer, scale, crs, crsTransform, tileScale)
Apply a reducer over the area of each feature in the given collection.
The reducer must have the same number of inputs as the input image has bands.
Returns the input features, each augmented with the corresponding reducer outputs.
Arguments:
this:image (Image):
The image to reduce.
collection (FeatureCollection):
The features to reduce over.
reducer (Reducer):
The reducer to apply.
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 will replace any transform already set on the projection.
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: FeatureCollection
需要获取的单景影像名称
代码:
var training = ee.FeatureCollection("projects/ee-bqt2000204051/assets/classfication_tree-points") print("training trree",training) function maskS2clouds(image) { var qa = image.select('QA60'); // Bits 10 and 11 are clouds and cirrus, respectively. var cloudBitMask = 1 << 10; var cirrusBitMask = 1 << 11; // Both flags should be set to zero, indicating clear conditions. var mask = qa.bitwiseAnd(cloudBitMask).eq(0) .and(qa.bitwiseAnd(cirrusBitMask).eq(0)); return image.updateMask(mask).divide(10000); } function renameS2_SR(img) { return img.select( ["B2", "B3", "B4", "B8", "B11", "B12",'QA60'], ['Blue', 'Green', 'Red', 'NIR', 'SWIR1', 'SWIR2', 'QA_PIXEL']); } //--------------------4.所有常用的指数公式------------------------- function calVI(img) { var ndvi = img.normalizedDifference(['NIR', 'Red']).rename('NDVI'); //Mcfeeters 1996 var ndwi=img.normalizedDifference(["Green", "NIR"]).rename("NDWI"); var ndbi=img.normalizedDifference(["SWIR1", "NIR"]).rename("NDBI"); var rvi = img.expression( 'NIR / RED ', { 'NIR': img.select("NIR"), 'RED': img.select("Red") }).rename('RVI'); var dvi = img.expression( 'NIR - RED ', { 'NIR': img.select('NIR'), 'RED': img.select('Red') }).rename('DVI'); return img.addBands(ndvi).addBands(ndwi).addBands(ndbi).addBands(rvi).addBands(dvi); } var s2 = ee.ImageCollection('COPERNICUS/S2_SR') .filterDate('2022-01-01', '2022-12-31') .filterBounds(training) .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',5)) .map(maskS2clouds).map(renameS2_SR).map(calVI)//.select(["B1"]).median().clip(roi1); // print(s2.first()) print(s2) print(s2.size()) //ee.ImageCollection.fromImages([image1]) var image1=ee.Image("COPERNICUS/S2_SR/20220115T032101_20220115T032101_T49SEA").select(["B1"]) //print(image1) var image2=ee.Image("COPERNICUS/S2_SR/20220405T031541_20220405T032316_T49SEA").select(["B1"]) var image3=ee.Image("COPERNICUS/S2_SR/20220410T031539_20220410T032318_T49SEA").select(["B1"]) // var listimage = ee.List([image1,image2,image3]) // print(listimage.get(0)) var imagess = image1.addBands(image2).addBands(image3) var values = imagess.reduceRegions({ collection:training, reducer:ee.Reducer.mean(), scale:10, // crs:null, // crsTransform:null, // tileScale:true, }) print(i+"image values", values ) Export.table.toDrive({ collection:values, // description:, // folder:, // fileNamePrefix:, // fileFormat:, // selectors:, // maxVertices:, }) }
提取3景影像的B1波段的属性值