【问题标题】:Extract pixel values by points and convert to a table in Google Earth Engine按点提取像素值并转换为 Google Earth Engine 中的表格
【发布时间】:2018-04-15 16:11:09
【问题描述】:

我正在开展一个项目,该项目将火灾严重程度的现场测量与火灾前后从 Landsat 图像中得出的波段值和光谱指数联系起来。我目前正在使用 Google Earth Engine 从一组 Landsat 图像中提取表面反射率值。我使用的方法将我的现场位置(点数据)导入为要素集合,并使用 getRegion 函数从每个点的 Landsat 图像集合中提取波段值。代码如下:

//IMPORT SAMPLE POINTS
var pts =     ee.FeatureCollection('ft:1N9Hb01uCSHqGpz262K_f9VzWedxvTiV0g6tJwfw4');

//IMPORT LANDSAT IMAGE
var L82014pre = ee.ImageCollection('LANDSAT/LC8_SR') //Landsat 8 Surface   reflectance
.filter(ee.Filter.eq('wrs_path', 94))
.filter(ee.Filter.eq('wrs_row', 86)) 
.filterDate(ee.Date.fromYMD(2013,12,13), ee.Date.fromYMD(2014,1,15)) 

//EXTRACT BY SAMPLE POINTS
var sample = L82014pre.getRegion(pts, 30);

我的问题是如何将生成的“样本”变量(列表列表)转换为可以导出到谷歌驱动器的表格?或者有没有更好的方法在 Google 地球引擎中按点提取图像数据?

我是 Google 地球引擎和 Java 编程语言的新手,所以如果这个问题的答案是显而易见的,我深表歉意。我花了很多时间试图找到解决这个问题的方法,但我觉得我无处可去。

谢谢,

卢克

【问题讨论】:

    标签: extraction google-earth-engine


    【解决方案1】:

    我无法访问您的融合表,因此我为示例编了一些随机点。 我很确定还有其他方法可以做到这一点。 GEE 有很多功能,有时使用起来有点棘手。这将是我的方式:

    // As I can't access your FusionTable,
    // I make random points and create a FeatureCollection
    var p1 = ee.Geometry.Point([142.36083984375, -37.466138602344046])
    var p2 = ee.Geometry.Point([143.23974609375, -37.04640889969956])
    var pts = ee.FeatureCollection(ee.List([ee.Feature(p1),ee.Feature(p2)]))
    
    //IMPORT LANDSAT IMAGE
    var L82014pre = ee.ImageCollection('LANDSAT/LC8_SR') //Landsat 8 Surface   reflectance
    .filter(ee.Filter.eq('wrs_path', 94))
    .filter(ee.Filter.eq('wrs_row', 86)) 
    .filterDate(ee.Date.fromYMD(2013,12,13), ee.Date.fromYMD(2014,1,15))
    
    // Empty Collection to fill
    var ft = ee.FeatureCollection(ee.List([]))
    
    var fill = function(img, ini) {
      // type cast
      var inift = ee.FeatureCollection(ini)
    
      // gets the values for the points in the current img
      var ft2 = img.reduceRegions(pts, ee.Reducer.first(),30)
    
      // gets the date of the img
      var date = img.date().format()
    
      // writes the date in each feature
      var ft3 = ft2.map(function(f){return f.set("date", date)})
    
      // merges the FeatureCollections
      return inift.merge(ft3)
    }
    
    // Iterates over the ImageCollection
    var newft = ee.FeatureCollection(L82014pre.iterate(fill, ft))
    
    // Export
    Export.table.toDrive(newft,
    "anyDescription",
    "anyFolder",
    "anyNameYouWant")
    

    【讨论】:

    • 你好刚刚改变了点坐标,它没有给出波段的值。为什么会发生这种情况?谢谢
    • 可能是因为集合被 PATH 和 ROW 过滤了。删除这 2 个过滤器,看看效果如何。
    • 非常感谢罗德里戈的回复。 Muchas gracias por la respuesta。祝你好运。
    【解决方案2】:

    @Rodrigo,感谢您的及时回复。点提取代码非常适合该示例。我尝试对另一组应用了云遮罩的图像进行点提取,发现如果集合中第一张图像的第一个点落在遮罩之外(即在分配了“空”值的像素上),导出的表将不包含任何点的波段数据。为了解决这个问题,我添加了一个过滤器,以在包含“null”值的点与特征集合合并之前删除它们。

    下面的代码包含一个示例,其中包含不删除“null”值的失败提取和删除“null”值的成功提取。

    //cloud mask ------------------------------------------------------  
    var maskCloudShadow = function(image){
    var cfmask = image.select('cfmask');
    return image.updateMask(cfmask.lt(1));   // keep clear (0) pixels
    };
    
    //select images from image collection -----------------------------
    //extract filtered collection of Landsat 5 Surface Reflection
    var L5fs1998post = ee.ImageCollection('LANDSAT/LT5_SR') //Landsat 5 Surface reflectance
    .filterDate('1998-1-9', '1998-2-27') //filter to date bounds 
    .filter(ee.Filter.eq('wrs_path', 91))//filter to path and row
    .filter(ee.Filter.eq('wrs_row', 86))
    .map(maskCloudShadow); //apply cloud and cloud shadow mask function
    print(L5fs1998post);
    
    //Create sample points --------------------------------------------
    //var pts = 
    ee.FeatureCollection('ft:1lfLgiQQSIIOpgjuZV5MZJno9_kLyQC49w6u3Hf9W');
    var p1 = ee.Geometry.Point([146.84341192245483, -37.47371711676642]);
    var p2 = ee.Geometry.Point([146.84167385101318, -37.4]);
    var pts = ee.FeatureCollection(ee.List([ee.Feature(p1),ee.Feature(p2)]));
    
    // Empty Collection to fill
    var ft = ee.FeatureCollection(ee.List([]));
    
    //Without removal of null values ----------------------------------
    //Function to extract values from image collection based on point file and export as a table 
    var fill = function(img, ini) {
    // type cast
    var inift = ee.FeatureCollection(ini);
    
    // gets the values for the points in the current img
    var ft2 = img.reduceRegions(pts, ee.Reducer.first(),30);
    
    // gets the date of the img
    var date = img.date().format();
    
    // writes the date in each feature
    var ft3 = ft2.map(function(f){return f.set("date", date)});
    
    // merges the FeatureCollections
    return inift.merge(ft3);
    };
    
    // Iterates over the ImageCollection
    var newft = ee.FeatureCollection(L5fs1998post.iterate(fill, ft));
    print(newft);
    
    // Export
    Export.table.toDrive(newft,
    "anyDescription",
    "EarthEngine",
    "sample_include_null");
    
    //With removal of null values ------------------------------------------
    //Function to extract values from image collection based on point file and export as a table 
    var fill = function(img, ini) {
    // type cast
    var inift = ee.FeatureCollection(ini);
    
    // gets the values for the points in the current img
    var ft2 = img.reduceRegions(pts, ee.Reducer.first(),30);
    
    // gets the date of the img
    var date = img.date().format();
    
    // writes the date in each feature
    var ft3 = ft2.map(function(f){return f.set("date", date)});
    
    // merges the FeatureCollections
    
    var ft3a = ft3.filter(ee.Filter.neq('B1', null));//filter first to remove null values
    return inift.merge(ft3a);
    };
    
    // Iterates over the ImageCollection
    var newft_remove_null = ee.FeatureCollection(L5fs1998post.iterate(fill, ft));
    print(newft_remove_null);
    
    // Export
    Export.table.toDrive(newft_remove_null,
    "anyDescription",
    "EarthEngine",
    "sample_remove_null");
    
    //plot cloudy scene and sample points ------------------------------------
    var scene = ee.Image('LANDSAT/LT5_SR/LT50910861998042');
    Map.setCenter(147, -37.5, 9);
    Map.addLayer(scene, {bands: ['B3', 'B2', 'B1'], min: 0, max: 2000}, 'false-color composite');
    Map.addLayer(pts);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 2023-01-18
      • 1970-01-01
      相关资源
      最近更新 更多