跟着知乎大佬 无形的风 学GEE
大纲:文件下载、Export
学习了一下可能比较常用的结果导出方法
一、下载文件
一般用于下载矢量数据和栅格数据,(FeatureCollection、Image)方法:getDownloadURL
1、下载经过筛选的数据集
//首先将矢量数据转换为toList的FeatureCollection
var FeatureCollection = ee.FeatureCollection(sfc.toList(sfc.size()));
var url = FeatureCollection.getDownloadURL({
format:"kml",
//"csv","json","kmz"
selectors:["cc"],
//筛选矢量数据属性,默认包含全部属性
filename:"image"
//下载文件的名称
});
print("url :", url);
2、使用经纬确定ROI下载区域
var roi = ee.Geometry.Polygon([[[115,40],[...,...],[...,...],[...,...],[...,...]]]);
// 四点确定roi范围
var roi_col = ee.FeatureCollection(roi);
var url = roi_col.getDownloadURL({
format:"json",
filename:"bounds"
});
print("url is ",url);
3、下载影像
方法:ee.Image.getDownloadURL()
//首先确定下载感兴趣区域范围
var roi = ee.Geometry.Polygon([[[],[],[],[],[]]]);
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT_TOA").filterBounds(roi).filterDate("2017-01-01","2018-01-01").map(ee.Algorithms.Landsat.simpleCloudScore).map(function(img){
img = img.updateMask(img.select("cloud").lt(1));
return img
})
.sort("system:time_start");
var landsat = l8.mosaic().clip(roi);
//首先获取roi信息
var roiInfo = roi.getInfo();
var region1 = JSON.stringify(roiInfo);
//或者(推荐)
var region2 = ee.Geometry(roi).toGeoJSONString();
var url1 = landsat.select('B1').getDownloadURL({scale:30,
region:region1,
name:"landsat8-B1"})
var url2 = landsat.select('B2').getDownloadURL({scale:100,
region:region1,
name:"landsat8-B2"});
var url3 = landsat.select(["B3","B2","B1"]).getDownloadURL({scale:30,
region:region2,
name:"landsat8-rgb"});
二、Export方法
1、Export.image
.toAsset({image:l8img.select([“B3”,“B2”,“B1”]),
description:‘l8ImageAsset’,
assetId:‘l8ImageAsset’,
scale:30,
region:roi,
pyramidingPolicy:{
‘B3’:‘mean’,
‘B2’:‘sample’,
‘B1’:‘max’
}
}); // pyramidingPolicy 一般用默认值,指定各波段计算方法
.toCloudStorage
.toDrive({
image:l8Img.select([“B3”,“B2”,“B1”]),
description:“l8ImageDrive”,
fileNamePrefix:“l8Img”,//资源名称
scale:30,
region:roi,
maxPixels:1e13 //导出影像最大像素个数,防报错
});
2、Export.map
.toCloudStorage
3、Export.table
.toCloudStorage
.toDrive({
collection:taiwan,
description"taiwan",
fileNamePrefix:“taiwan”,
fileFormat:“KML”,//一般格式为“CSV”/“GeoJSON”/“KML”/KMZ",也可以选导出SHP,但是如果里面有汉字的话会变成??导致部分内容缺失
selectors:[“cc”]
});
4、Export.video
.toCloudStorage
.toDrive
5、Export.videoMap
.toCloudStorage
可以看到导出一般是到Assets资源空间(Docs旁边)、Google Drive(https://drive.google.com/drive/my-drive)、Google Cloud Storage