Javascript 如何将几何体传递给GEE中的映射函数?

Javascript 如何将几何体传递给GEE中的映射函数?,javascript,google-earth-engine,Javascript,Google Earth Engine,我正在尝试使用Google Earth引擎中的Map功能将图像集合剪裁到几何体上。我有多个感兴趣的领域(AOI),因此希望多次应用通用剪辑函数(对于每个AOI)。但是,当我使用两个参数(图像和几何体)创建一个要映射的函数时,会出现错误image.clip不是一个函数。当只使用一个参数(图像)的函数时,它工作得很好,但是我需要编写两个(或可能更多)函数来完成完全相同的任务(即将图像剪切到特定的几何体) 我在帖子中尝试过这些解决方案,但都不起作用 关于如何解决这个问题有什么想法吗 代码: // Ge

我正在尝试使用Google Earth引擎中的
Map
功能将图像集合剪裁到几何体上。我有多个感兴趣的领域(AOI),因此希望多次应用通用剪辑函数(对于每个AOI)。但是,当我使用两个参数(图像和几何体)创建一个要映射的函数时,会出现错误
image.clip不是一个函数
。当只使用一个参数(图像)的函数时,它工作得很好,但是我需要编写两个(或可能更多)函数来完成完全相同的任务(即将图像剪切到特定的几何体)

我在帖子中尝试过这些解决方案,但都不起作用

关于如何解决这个问题有什么想法吗

代码:

// Get NTL data
var ntl = ee.ImageCollection("NOAA/VIIRS/DNB/MONTHLY_V1/VCMSLCFG");

// Define start and end year
var startYear = 2015;
var endYear = 2018;

// Filter montly and select 'avg_rad' band
var ntlMonthly = ntl.filter(ee.Filter.calendarRange(startYear, endYear, 'year'))
  .filter(ee.Filter.calendarRange(1,12,'month'))
  .select(['avg_rad']);  

// Create geometries of AOIs
// -- Create a geometry of Venezuela 
var geomVenezuela = ee.Geometry.Rectangle([-73.341258, 13.363291, -59.637555, -0.372893]);
// -- Create a geometry of Caracas (Venezuela's capital)
var geomCaracas = ee.Geometry.Rectangle([-67.062383, 10.558489, -66.667078, 10.364908]);

// Functions to crop to Venezuela (nationwide) and Caracas (local) resp.
var clipImageToGeometry  = function(image, geom) {
  return image.clip(geom);
}

// Apply crop function to the ImageCollection 
var ntlMonthly_Venezuela = ntlMonthly.map(clipImageToGeometry.bind(null, geomVenezuela));
var ntlMonthly_Caracas = ntlMonthly.map(clipImageToCaracas.bind(null, geomCaracas));

// Convert ImageCollection to single Image (for exporting to Drive)
var ntlMonthly_Venezuela_image = ntlMonthly_Venezuela.toBands();
var ntlMonthly_Caracas_image = ntlMonthly_Caracas.toBands();

// Check geometry in map
Map.addLayer(geomCaracas, {color: 'red'}, 'planar polygon');
Map.addLayer(ntlMonthly_Caracas_image);

// Store scale (m. per pixel) in variable
var VenezuelaScale = 1000;
var CaracasScale = 100;

// Export the image, specifying scale and region.
Export.image.toDrive({
  image: ntlMonthly_Caracas_image,
  description: 'ntlMonthly_Caracas_'.concat(startYear, "_to_", endYear),
  folder: 'GeoScripting',
  scale: CaracasScale,
  fileFormat: 'GeoTIFF',
  maxPixels: 1e9
});

如果我正确理解了你的问题:

如果要将
ImageCollection
中的每个图像裁剪为几何体,只需执行以下操作即可

var ntlMonthly_委内瑞拉=ntlMonthly.map(函数(图像){返回ee.image(图像).clip(委内瑞拉)})
对其他AOI重复以上步骤

如果要将其强制转换为函数:

var clipImageCollection=函数(ic、geom){
返回ic.map(函数(图像){返回ee.image(图像).clip(geom)})
}
//将裁剪功能应用于ImageCollection
var ntlMonthly_委内瑞拉=clipImageCollection(ntlMonthly,委内瑞拉);
var ntlMonthly_Caracas=clipImageCollection(ntlMonthly,加拉加斯);

请分享您的脚本或可复制的示例。您提供的代码无法运行,因为您是对的,添加了完整的脚本。谢谢!这确实是我努力实现的目标;我没有想到把map函数直接放在自定义函数中。。。