我有一个 SHP(名为“vect”的表),我想从 S2 图像集合(按多云百分比、日期和云量过滤)中提取通用索引的值(每个点)。
当我运行它时,我有这个错误:
“地图中的FeatureCollection(错误)错误(ID = 10):Image.reduceRegions:无法找到crs。”
这是代码:
var mainFunction = function(startDate,endDate,cloud_perc,cloud_prob,B1, B2,timeStep,window,summarize,vect,scale,folder){
Map.addLayer(vect);
Map.centerObject(vect,4);
//import S2 collection and filter by date and cloud coverage
var sen2=ee.ImageCollection("COPERNICUS/S2")
.filterDate(ee.Date(startDate), ee.Date(endDate))//to filter by date
.filter(ee.Filter.lt("CLOUDY_PIXEL_PERCENTAGE",cloud_perc))//to filter by a propriety of the collection
//load S2_CLOUD_PROBABILITY dataset
var cloud_probability=ee.ImageCollection("COPERNICUS/S2_CLOUD_PROBABILITY")
//join the 2 collection
var s2cloudmask=ee.Join.saveFirst("cloud_mask").apply({
primary:sen2,
secondary:cloud_probability,
condition:ee.Filter.equals({leftField:"system:index",rightField:"system:index"})
})
//convert the list to an immage collection
s2cloudmask=ee.ImageCollection(s2cloudmask)
//define a function to mask out cloudy pixel in the s2 collection
var maskcloud= function(img){
var clouds=ee.Image(img.get("cloud_mask")).select("probability");
var noclouds=clouds.lt(cloud_prob);
return img.mask(noclouds);
}
//apply the function to all the images in the collection
var s2_masked= s2cloudmask.map(maskcloud)
///////INDEX///////
//function to create index
function addIndex(img) {
var Index=img.normalizedDifference([B1, B2]).rename("Index")
return img.addBands(Index)
}
//calculate index for all the collection
var s2_masked_index= s2_masked.map(addIndex)
var Index=s2_masked_index.select('Index')
Map.addLayer(Index.median(), {bands: 'Index', min: -1, max: 1,palette:["brown","yellow","green"]},"Median composite index");
Map.addLayer(composites.median(), {bands: 'Index', min: -1, max: 1,palette:["brown","yellow","green"]},"Moving median composite Index");
scale=ee.Number(scale)
//make the time series chart
var chart=ui.Chart.image.series({
imageCollection:composites.select("Index"),
region:vect,
reducer:ee.Reducer.median(),
scale:scale
}).setOptions({
lineWidth:1,
pointSize: 3,
title:"Index time series",
interpolateNulls:true,
vAxis:{title:"Index"},
hAxis:{title:'',format:'YYYY-MMM'}})
print(chart,"time series")
//make the doy time series chart
//var series1 = ui.Chart.image.doySeriesByYear(composites,"Index",geometry,ee.Reducer.median(),scale);
//print(series1,"time series-doy")
//extract index values from aoi
var reduced = composites.map(function(image){
return image.reduceRegions({
collection:vect ,
reducer:ee.Reducer.median(),
scale: scale
});
});
//turn collection of collection into table
var table = reduced.flatten();
print(table)
//export the table
Export.table.toDrive({collection:table,
description:"Index_time_series",
folder: folder,
fileFormat:"CSV"})
}
exports.mainFunction = mainFunction;