如何解决在Google Earth Engine中提取多边形中所有像素的值
我定义了一个多边形
var polygon = ee.Geometry.polygon([114,0.37,114,2.04,112,0.37]);
以及上述多边形需要处理的数据集
var dataset = ee.ImageCollection('NASA/NEX-GDDP');
在选定日期
var startDate = ee.Date('1980-01-01');
var endDate = ee.Date('1980-01-02');
数据集具有3个波段pr
,tasmax
和tasmin
,我正在选择需要处理的波段
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
.filter(ee.Filter.date(startDate,endDate))
.filter(ee.Filter.bounds(polygon))
.select('tasmax');
Map.addLayer(dataset)
我想导出多边形下所有网格的数据 以及它们各自的纬度长。由于一天有21个功能(GCM), 我期望最终数据的行数等于多边形X 21要素(GCM)中的网格数
var dailyImg = dataset.toBands();
Export.table.toDrive({
collection: dailyImg,description: 'hist_tx',fileFormat: 'CSV',});
当我尝试执行此操作时,出现错误
错误:无效的参数:'collection'必须是FeatureCollection。
我该如何解决?此外,即使将我的空间区域限制为多边形,地图仍然 显示整个地球的数据?为什么会这样?
解决方法
错误:无效的参数:'collection'必须是FeatureCollection。
Export.table
用于导出表,也称为FeatureCollection
。您有一张图片,没有一张桌子。
从地球引擎中获取数据的最有效的方法是使用Export.image
,然后转换下载的GeoTIFF以适合您的R程序。但是,由于该数据集非常小,因此可以将其下载为CSV即可正常工作,并且该工具的ee.Image.sample
可以将Image
的区域转换为FeatureCollection
。>
var collection = dailyImg.sample({
region: polygon,geometries: true,// This specifies that you want the lat-long,rather
// than image samples without any position information.
});
如果导出此内容,您将在GeoJSON格式的单列中获得职位。那可能不是您想要的,所以我们可以将其转换为列:
var collection_with_latlon = collection.map(function (feature) {
var coordinates = feature.geometry().transform('epsg:4326').coordinates();
return feature.set('lon',coordinates.get(0),'lat',coordinates.get(1));
});
Here's everything put together as a working example:
var polygon = ee.Geometry.Polygon([114,0.37,114,2.04,112,0.37]);
var startDate = ee.Date('1980-01-01');
var endDate = ee.Date('1980-01-02');
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
.filter(ee.Filter.date(startDate,endDate))
.filter(ee.Filter.bounds(polygon))
.select('tasmax');
Map.addLayer(polygon);
var dailyImg = dataset.toBands();
var collection = dailyImg.sample({
region: polygon,// This specifies that you want the lat-long.
});
// Break point coordinates up into properties (table columns) explicitly.
var collection_with_latlon = collection.map(function (feature) {
var coordinates = feature.geometry().transform('epsg:4326').coordinates();
return feature.set('lon',coordinates.get(1));
});
print(collection_with_latlon);
Export.table.toDrive({
collection: collection_with_latlon,description: 'hist_tx',fileFormat: 'CSV',});
此外,即使在将我的空间区域限制为多边形之后,地图仍然显示整个地球的数据吗?为什么会这样?
仅将集合过滤为仅几何图形忽略不与几何图形相交的图像。在这种情况下,图像会覆盖整个地球,因此不会滤除任何图像。为了将图像剪切到集合中,您必须指定该图像,例如:
var dailyImg = dataset.toBands().clip(polygon);
但是,如果您使用.sample()
,则不需要这样做,因为该操作具有其自己的region参数,并且不会使用多边形外的任何像素。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。