GEE:获取sentinel2指定区域多个单景影像的值(样本点提取)

简介: GEE:获取sentinel2指定区域多个单景影像的值(样本点提取)

简介

本教程的主要目的是获取指定单景影像,然后获取指定波段的影像值,按照获取指定波段的影像进行值提取至点,因为这里暂时没有好的方法对哨兵数据的具体属性值进行提取,所以在筛选哨兵影像的时候,需要手动获取每一景影像的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波段的属性值

相关文章
|
6月前
|
定位技术 TensorFlow API
Google Earth Engine (GEE)——张量流水灾模型数据集(Sentinel-1)
Google Earth Engine (GEE)——张量流水灾模型数据集(Sentinel-1)
150 0
|
6月前
|
编解码 算法 定位技术
GEE时序——利用sentinel-2(哨兵-2)数据进行地表物候学分析(时间序列平滑法估算和非平滑算法代码)
GEE时序——利用sentinel-2(哨兵-2)数据进行地表物候学分析(时间序列平滑法估算和非平滑算法代码)
518 3
|
6月前
|
API
GEE案例分析——利用sentinel-3数据计算空气污染指数(Air Pollution Index,简称API)
GEE案例分析——利用sentinel-3数据计算空气污染指数(Air Pollution Index,简称API)
199 0
|
6月前
|
传感器 编解码 区块链
Google Earth Engine(GEE)——Landsat8/modis/sentinel2 NDVI时序影像差异对比分析图表
Google Earth Engine(GEE)——Landsat8/modis/sentinel2 NDVI时序影像差异对比分析图表
169 0
|
6月前
|
算法 数据挖掘 定位技术
GEE 案例——如何计算sentinel-2中每一个单景影像的波段的DN值并绘制直方图
GEE 案例——如何计算sentinel-2中每一个单景影像的波段的DN值并绘制直方图
119 5
|
6月前
|
存储 编解码 人工智能
GEE数据集——哨兵2号Sentinel-2 云概率数据集
GEE数据集——哨兵2号Sentinel-2 云概率数据集
359 2
|
6月前
|
数据处理
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
Google Earth Engine(GEE)——sentinel-1数据处理过程中出现错误Dictionary does not contain key: bucketMeans
110 0
|
6月前
|
人工智能 atlas
Google Earth Engine(GEE)RADD - RAdar for Detecting Deforestation-基于Sentinel-1的10米空间尺度的湿润热带森林扰动预警数据集
Google Earth Engine(GEE)RADD - RAdar for Detecting Deforestation-基于Sentinel-1的10米空间尺度的湿润热带森林扰动预警数据集
64 0
|
6月前
Google Earth Engine(GEE)——Sentinel-2影像在同一区域同一时间段有多个不同的ID影像,如何进行筛选其中单景影像
Google Earth Engine(GEE)——Sentinel-2影像在同一区域同一时间段有多个不同的ID影像,如何进行筛选其中单景影像
138 0
Google Earth Engine(GEE)——sentinel-1数据中乌克兰附近数据缺失轨道36缺失
Google Earth Engine(GEE)——sentinel-1数据中乌克兰附近数据缺失轨道36缺失
145 0
Google Earth Engine(GEE)——sentinel-1数据中乌克兰附近数据缺失轨道36缺失