使用Google Earth Engine (GEE)实现MODIS数据批量下载

使用Google Earth Engine GEE实现MODIS数据批量下载

关注公众号,分享GIS知识、ArcGIS教程、SCI论文与科研日常等

前言

在这里插入图片描述上图是GEE代码编辑器界面,使用JavaScript脚本代码可以编程获取数据进行数据处理等一系列操作。使用GEE:网址链接

使用GEE之前需要对 JavaScript语法 有一定了解,同时,GEE对JavaScript进行了二次封装,包含了自己的各种方法,具体使用是有些差别,其中,GEE在Docs一栏也提供了API文档,可以在编程时方便查看相关函数及参数。如果只是想利用GEE下载个数据啥的,直接网上copy代码就行了。
在这里插入图片描述
另外,Asset栏是自己的资产,可以将自己的矢量文件、栅格文件等数据上传到此处。之后就可以使用上传的数据进行后续操作了,比如想获得China范围的MODIS数据。

在这里插入图片描述
或者通过界面下方的地图绘制自己需要的区域(geometry变量)导入到工程。

在这里插入图片描述

下载数据代码

下面是下载2018-10-10至2018-12-01时间内,geometry4(我自己画的),MOD13A2.006产品的NDVI波段的代码示例。

当然,不止MODIS,GEE中提供了很多数据集的下载。下载的数据输出的是指定分辨率、格式和投影的数据,非常方便。

// get data collection you need and filtered by date and bound infomation and select the NDVI band  
var mod13a2NDVI = ee.ImageCollection('MODIS/006/MOD13A2')
  .filterBounds(geometry4)
  .filterDate('2018-10-10', '2018-12-01')
  .select('NDVI');
  
print('Collection: ', mod13a2NDVI);
// num是collection 中的个数,大点没关系,不能比collection中image个数少
var num = 23;
// convert the collection to image list
var list = mod13a2NDVI.toList(num);
print(list);

// get the size of image list
// 这里只用list.size()是不对的,还要通过getInfo()获取相应的属性信息,如果没有getInfo(),虽然也能输出count,但是下面的循环不执行,不知道为啥。
var count = list.size().getInfo();
print(count)
// var i = 0 

// loop to output all images
for(var i=0;i<count;i++)
{
  // get the single image from list
  var image = ee.Image(list.get(i));
  print(i,image);
  // get the id property as the part of filenames
  var id=image.id();
  print(id);
  
  // out name
  var name2="NDVI_"+id.getInfo();
  
  
  print(name2)
   
   // export the image to your google drive
   /*各个参数及含义
    image (Image):
    The image to export.
    
    description (String, optional):
    A human-readable name of the task. Defaults to "myExportImageTask".
    
    folder (String, optional):
    The Google Drive Folder that the export will reside in.
    
    fileNamePrefix (String, optional):
    The Google Drive filename for the export. Defaults to the description.
    
    dimensions (Number|String, optional):
    The dimensions to use for the exported image. Takes either a single positive integer as the maximum dimension or
    
    "WIDTHxHEIGHT" where WIDTH and HEIGHT are each positive integers.
    
    region (Geometry.LinearRing|Geometry.Polygon|String, optional):
    A LinearRing, Polygon, or coordinates representing region to export. These may be specified as the Geometry objects or coordinates serialized as a string. If not specified, the region defaults to the viewport at the time of invocation.
    
    scale (Number, optional):
    Resolution in meters per pixel. Defaults to 1000.
    
    crs (String, optional):
    CRS to use for the exported image.
    
    crsTransform (List<Number>|String, optional):
    Affine transform to use for the exported image. Requires "crs" to be defined.
    
    maxPixels (Number, optional):
    Restrict the number of pixels in the export. By default, you will see an error if the export exceeds 1e8 pixels. Setting this value explicitly allows one to raise or lower this limit.
    
    fileFormat:
    
    formatOptions
   */
  Export.image.toDrive({
    image: image, // 
    description: 'imageToCOGeoTiffExample',
    fileNamePrefix: name2,
    scale: 1000,
    maxPixels: 999999999999,
    // crs:'EPSG:32649',
    region: geometry4,
    fileFormat: 'GeoTIFF',
    formatOptions: {
      cloudOptimized: true
    }
  }); 
}

批量执行run任务

当批量下载的图像很多时,代码运行后会生成很多run任务,需要点击后将数据保存下来,这时候一个一个点就比较麻烦。提供一个博客介绍的批量执行run任务的方法:博客地址

评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cshgiser

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值