将栅格转换为多边形在 Google Earht Engine 上重新分类 NDVI 栅格

Convert raster to polygon a reclassify NDVI raster on Google Earht Engine

这是我用来估算 NDVI 的所有代码。

初始值

var roi =/* color: #98ff00 *//* displayProperties: [{"type": "rectangle"}] */
    ee.Geometry.Polygon(
        [[[-72.3734130976651, -13.430548306629259],
          [-72.3734130976651, -14.326448420293916],
          [-70.7254638789151, -14.326448420293916],
          [-70.7254638789151, -13.430548306629259]]], null, false);
var startDate = ee.Date('2018-08-23');
var endDate = ee.Date('2018-12-21');
var cloud = 20

Select 石英石 0 : (Jun 23, 2015 - Jul 17, 2019) Sentinel 2 Level 1C

var selector = 0;
var Sentinel = "";

NDVI

function getNDVI(image){
    var isLandsat75 = (selector !== 0);
    var NDVI = image.expression('(nir - red)/(nir + red)', 
    {'nir':image.select(isLandsat75 ? 'B4' : 'B8'), 
    'red':image.select(isLandsat75 ? 'B8' : 'B4')}); 
    //print(NDVI);
    return NDVI;
}

选择卫星

switch(selector){ case 0: Sentinel =  'COPERNICUS/S2'}

collection

var collection = ee.ImageCollection(Sentinel) 
  .filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE", cloud))
  .filterDate(startDate, endDate)
  .filterBounds(roi);
print(collection) 

计算 NDVI

var ndviFiltered = collection.map(getNDVI).qualityMosaic('B8').clip(roi);

重新分类栅格

var DTstring = ['1) root 9999 9999 9999',
'2) B8<=0.2 9999 9999 1 *',
'3) B8>0.2 9999 9999 9999',
'6) B8<=0.4 9999 9999 2 *',
'7) B8>0.4 9999 9999 9999',
'14) B8<=0.6 9999 9999 3 *',
'15) B8>0.6 9999 9999 9999',
'30) B8<=0.8 9999 9999 4 *',
'31) B8>0.8 9999 9999 5 *'].join("\n");

var classifier = ee.Classifier.decisionTree(DTstring);
var reclass = ndviFiltered.select('B8').classify(classifier);
print(reclass)

Map.addLayer(reclass,{min:1,max:5}, 'Reclass');

转换为矢量

var vectors = ndviFiltered.reduceToVectors({
  geometry: roi,
  scale: 1000,
  geometryType: 'polygon',
  reducer: ee.Reducer.countEvery()
});
print(vectors)

这里我得到这个错误“FeatureCollection(错误) Image.reduceToVectors: 图像的第一个波段 ('B8') 必须是完整的" B8乐队已经是积分

我遇到了类似的问题。
NDVI值是连续值,无法转换成这种格式的向量。
您必须定义离散区域并用空图像掩盖它。
看到这个 link.