0

我对 Earth Engine 和 Javascript 非常陌生,所以如果我的问题的解决方案非常简单,我不会感到惊讶。无论如何,我这几天一直在尝试解决这个问题,但我并没有做得更好。

我正在尝试获取美国沿海一些感兴趣区域和一些潮汐测量仪之间的累积成本距离。为此,我首先根据国家高程图计算了像素成本。然后,我通过内置函数计算了累积成本cumulativeCost。一切都很顺利。现在我正在尝试提取潮位计位置的累积成本值。为此,有人建议我使用该reduceRegions方法。我尝试了以下代码,但没有成功。

我将发布我的整个代码,以便可以复制。请注意,我遇到问题的部分是第二个。

提前非常感谢。

// IMPORTS
var imageCollection =    
ee.ImageCollection("users/brazzolanicoletta/sourceRasters"),
sourceVis = {"opacity":1,"bands":["b1"],"min":1,"max":1,"gamma":1},
DEMVis = {"opacity":1,"bands":
["elevation"],"min":-73.50744474674659,"max":374.555654458347,"gamma":1},
imageVisParam = {"opacity":1,"bands":
["elevation"],"min":-0.02534169006347656,"max":3.6601884765625,"palette":
["0345ff","000000"]},
imageVisParam2 = {"opacity":1,"bands":
["elevation"],"min":-0.02534169006347656,"max":3.6601884765625,"palette":
["0345ff","000000"]},
cosVisParam = {"opacity":1,"bands":
["cumulative_cost"],"max":4170.014060708561,"palette":
["ff0303","efff05","4eff05","002bff","ff01f7","000000"]},
imageVisParam3 = {"opacity":1,"bands":
["cumulative_cost"],"max":4028.1446098656247,"gamma":1};


//get IDs for images in image collection 
var getID = function(image){ return image.set('ID', image.id());};
var okID = imageCollection.map(function(image) { return image.set('ID', 
image.id());});

// Set general estethic parameters 
var dem_vis = {bands:"elevation", min:0, max:0.05,         
palette:"#0345ff,#000000"};
var cost_vis = {bands:"cumulative_cost", min:0, max:10000,     
palette:"ff0303,efff05,4eff05,002bff,ff01f7,000000"}

// PART 1: Cumulative Cost based on source rasters
 //import elevation map 
var dem = ee.Image('USGS/NED');

// pixel cost calculation 
var elThreshold = ee.Number(5); //set elevation threshold
var subDEM = dem.updateMask(dem.lt(elThreshold)); //mask pixel above 
elevation threshold
var costDEM = (subDEM.add(30)).divide(1000); //calculate the cost of each 
pixel (height + width pixel (30m)) in km 

// Add DEM to the map
Map.addLayer(costDEM, dem_vis, "SRTM");

// Cumulative cost
var calcCumCost = function(img) {
return costDEM.cumulativeCost({
source:img,
maxDistance:1E5});
}; //write a function that perform the cumulative cost calculation for each 
image given the cost of the pixel 

var demCost = ee.ImageCollection(okID.map(calcCumCost)); // caulcuate     
cumulative cost for each source raster in the image collection 

// PART 2 - Reduce Region: extract cumulative cost for tide gauges 

var tideGauges = 
ee.FeatureCollection('ft:1e1ik7ZklKbRSRVS50Ml_prHBTZ0WbNgW73fw7Ald'); 
//import fusion table of tide gauges

// WORK IN PROGRESS
// Empty Collection to fill
var ft = ee.FeatureCollection(ee.List([]));

// function that extract values from cumulative cost rasters and reduce it 
for points region
var fill = function(img) {
 // gets the values for the points in the current img
var ft2 = img.reduceRegions(tideGauges, ee.Reducer.first(),30);
// set ID
var ID = ee.Feature(null, {'id':img.id()});

// writes the ID in each feature
 var ft3 = ft2.map(function(f){return f.set("id", ID)});
// merges the FeatureCollections
return ft.merge(ft3);
};

// Apply the function to each image in the ImageCollection
var newft = ee.FeatureCollection(demCost.map(fill));
print(newft, 'Potentially: region-reduced cost');
4

1 回答 1

0

累积成本函数上的 maxDistance 转换为 3000 像素的邻域(在 30m 处),这意味着每个图块需要引入 4400 万个相邻像素,这实在是太多的内存。您将不得不降低 maxDistance 或增加 reduceRegion 的规模。

于 2017-12-05T13:58:03.357 回答