微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在Google Earth Engine中提取多边形中所有像素的值

如何解决在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个波段prtasmaxtasmin,我正在选择需要处理的波段

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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?