zoukankan      html  css  js  c++  java
  • GEE 代码片段

    ImageCollection转多波段Image

    // 1. 用toBands()内置函数
    var ndvi = finalImage.toBands();
    
    // 2. 遍历ImageCollection,并组合
    var ndvi = CollectionToImage(finalImage);
    function CollectionToImage(collection){
      var stack = ee.Image(collection.iterate(function(img, prev) {
        return ee.Image(prev).addBands(img);
      }, ee.Image(1)));
    
      stack = stack.select(ee.List.sequence(1, stack.bandNames().size().subtract(1)));
      return stack;
    }
    

    给feature编号

    trainPoints = trainPoints.map(function(feature) {
        return ee.Feature(feature.geometry(), {'id': feature.id()})
    })
    print(trainPoints)
    

    FeatureCollection的批量下载

    https://zhuanlan.zhihu.com/p/80340644

    var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR"); 
    var roi = /* color: #d63000 */ee.Geometry.Polygon( 
            [[[115.64960937499995, 39.112756306811285], 
              [116.28681640624995, 39.163883889810315], 
              [116.21540527343745, 39.58850167846649], 
              [115.70454101562495, 39.6054326422912]]]); 
    function rmL8Cloud(image) { 
      var cloudShadowBitMask = (1 << 3); 
      var cloudsBitMask = (1 << 5); 
      var qa = image.select('pixel_qa'); 
      var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0) 
                     .and(qa.bitwiseAnd(cloudsBitMask).eq(0)); 
      return image.updateMask(mask); 
    } 
    var l8Imgs = l8.filterBounds(roi) 
                   .filterDate("2018-1-1", "2018-3-1") 
                   .map(rmL8Cloud); 
    print("l8Imgs", l8Imgs); 
    Map.addLayer(l8Imgs, {min:0, max:3000, bands:["B4","B3","B2"]}, "l8Imgs"); 
    Map.addLayer(roi, {color: "red"}, "roi"); 
    
    //影像集合导出方法 
    function exportImageCollection(imgCol) { 
      var indexList = imgCol.reduceColumns(ee.Reducer.toList(), ["system:index"]) 
                            .get("list"); 
      indexList.evaluate(function(indexs) { 
        for (var i=0; i<indexs.length; i++) { 
          var image = imgCol.filter(ee.Filter.eq("system:index", indexs[i])).first(); 
          image = image.toInt16(); 
          Export.image.toDrive({ 
            image: image.clip(roi), 
            description: indexs[i], 
            fileNamePrefix: indexs[i], 
            region: roi, 
            scale: 30, 
            crs: "EPSG:4326", 
            maxPixels: 1e13 
          }); 
        } 
      }); 
    } 
    exportImageCollection(l8Imgs); 
    

    FeatureCollection属性求和、导出特定属性

    var yearbook = [35645.99,178861.26,3417100.00,1742220.00,3823900.00,2699308.33,4287242.00,5480666.67,1236.60,509760.00,
      63282.46,1234756.43,33053.93,47600.00,3871090.00,3818010.00,751991.20,384380.00,123140.00,596973.00,440929.20,1839360.00,
      501460.00,1802457.28,1179440.00,1000810.46,21370.00,322730.00,1051050.00,]
    var predict = ee.FeatureCollection(feature_list)
    
    predict = predict.flatten().aggregate_array("sum");
    predict.evaluate(function(predict_local) {
      var result = linearRegression(predict_local,yearbook)
      print(result)
      var chart = ui.Chart.array.values(predict_local, 0, yearbook)
      print(chart)
      }
    )
    var Feature_Collections = ee.FeatureCollection(feature_list).flatten()
    print(Feature_Collections)
    // print(Feature_Collections)
    Export.table.toDrive({
      collection: Feature_Collections,
      folder: '_ZonalStat',
      description: output_name,
      selectors:["PROVCODE","PROVCODE_D","PROVNAME","sum"],
      fileFormat: 'CSV'
    });
    

    下载哨兵RGB数据

    var district_geometry = geometry
    function maskS2clouds(image) {
      var qa = image.select('QA60');
      // Bits 10 and 11 are clouds and cirrus, respectively.
      var cloudBitMask = 1 << 10;
      var cirrusBitMask = 1 << 11;
      // Both flags should be set to zero, indicating clear conditions.
      var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
          .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
      return image.updateMask(mask).divide(10000);
    }
    var rgbVis = {
      min: 0.0,
      max: 0.3,
      bands: ['B4', 'B3', 'B2'],
    };
    var exportdataset = ee.ImageCollection('COPERNICUS/S2_SR')
                      .filterBounds(district_geometry)
                      .filterDate('2021-09-01', '2021-11-30')
                      // Pre-filter to get less cloudy granules.
                      .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 10))
                      .map(maskS2clouds)
                      .select(['B4', 'B3', 'B2']).median();
    Map.addLayer(exportdataset, rgbVis, 'RGB');
    Export.image.toDrive({
        image:exportdataset,
        description:'wuhan',
        scale:10,
        maxPixels: 1e13,
        region:district_geometry,
        fileFormat: 'GeoTIFF',
        crs:"EPSG:4326",
        fileDimensions:2048,
        formatOptions: {
          cloudOptimized: true
        }
      });
    
    
  • 相关阅读:
    scan chain的原理和实现——3.Tester Timing
    pattern——serial/paralel
    Scan and ATPG (Tessent)----1.基础概念
    ipdb介绍及Tensor
    pytorch简介
    Python 之map、filter、reduce
    分类器、logistic回归
    机器学习方法、距离度量、K_Means
    动态规划、图
    T分布
  • 原文地址:https://www.cnblogs.com/geoli/p/15730746.html
Copyright © 2011-2022 走看看