使用非零 errorMargin
对于可能的几何运算,在给定计算精度的情况下,尽可能使用最大的误差容限。误差幅度指定在几何操作期间(例如在重新投影期间)允许的最大允许误差(以米为单位)。指定较小的误差幅度可能会导致需要对几何图形(带坐标)进行密集化,这可能会占用大量内存。为您的计算指定尽可能大的误差范围是一种很好的做法:
var ecoregions = ee.FeatureCollection('RESOLVE/ECOREGIONS/2017'); var complexCollection = ecoregions.limit(10); Map.centerObject(complexCollection); Map.addLayer(complexCollection); var expensiveOps = complexCollection.map(function(f) { return f.buffer(10000, 200).bounds(200); }); Map.addLayer(expensiveOps, {}, 'expensiveOps');
使用小规模比例来进行reduceToVectors()
如果要将栅格转换为矢量,请使用适当的比例。指定一个非常小的比例会大大增加计算成本。将比例设置得尽可能高,以获得所需的精度。例如,要获取代表全球陆地的多边形:
var etopo = ee.Image('NOAA/NGDC/ETOPO1'); // 估算陆地边界大于-100米的 var bounds = etopo.select(0).gt(-100); // Non-geodesic polygon.请注意在全局缩减中使用非测地线多边形。 var almostGlobal = ee.Geometry.Polygon({ coords: [[-180, -80], [180, -80], [180, 80], [-180, 80], [-180, -80]], geodesic: false }); Map.addLayer(almostGlobal, {}, 'almostGlobal'); var vectors = bounds.selfMask().reduceToVectors({ reducer: ee.Reducer.countEvery(), geometry: almostGlobal, // 将比例设置为给定的最大可能 // 计算所需的精度。 scale: 50000,//这里你可以尝试分辨率设置小一些,发现计算时间会陡增 }); Map.addLayer(vectors, {}, 'vectors');
不要reduceToVectors()与reduceRegions()
不要使用FeatureCollection返回的reduceToVectors()作为的输入reduceRegions()。相反,在调用之前添加要reduce的波段reduceToVectors():
var etopo = ee.Image('NOAA/NGDC/ETOPO1'); var mod11a1 = ee.ImageCollection('MODIS/006/MOD11A1'); // 大致的陆地边界。 var bounds = etopo.select(0).gt(-100); // Non-geodesic polygon. var almostGlobal = ee.Geometry.Polygon({ coords: [[-180, -80], [180, -80], [180, 80], [-180, 80], [-180, -80]], geodesic: false }); var lst = mod11a1.first().select(0); var means = bounds.selfMask().addBands(lst).reduceToVectors({ reducer: ee.Reducer.mean(), geometry: almostGlobal, scale: 1000, maxPixels: 1e10 }); print(means.limit(10));
请注意,减少另一个区域内一个图像的像素的其他方法包括 reduceConnectedComponents() 和/或分组 reducers。