很多时候我们需要注意导出的错误信息,这里我们看到首先第一个错误就是我们选择波段的时候并没有按照指定的波段名称来进行,同时,我们不能直接导出影像集合,所以这里在导出的过程中又出现了将影像集合导出的低级错误。
错误代码分析:
代码语言:javascript复制var data=ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.select('Band 1 (ultra blue, coastal aerosol) surface reflectance');
var roi= ee.Geometry.Rectangle(79.197, 9.2171,79.197, 9.2171);
Map.addLayer(roi);
Export.image.toDrive({
image: data,
scale: 65455,
description: 'Landcover',
region : roi
});
首先我们这里需要改正的是我们选择波段的问题,这里需要我们重新理解select函数的使用,同时我们需要查看export函数如何正确使用,首先来看看函数:
select(var_args)
Selects bands from an image.这里提示我们要选择的是一个影像的波段名称,而不是其他的。
Returns an image with the selected bands.返回值就是你所选择影像的波段
Arguments:
this:image (Image):
The Image instance.
var_args (VarArgs<Object>):
One of two possibilities:
- Any number of non-list arguments. All of these will be interpreted as band selectors. These can be band names, regexes, or numeric indices. E.g. selected = image.select('a', 'b', 3, 'd');
- Two lists. The first will be used as band selectors and the second as new names for the selected bands. The number of new names must match the number of selected bands. E.g. selected = image.select(['a', 4], ['newA', 'newB']);
Returns: Image
Export.image.toDrive(image, description, folder, fileNamePrefix, dimensions, region, scale, crs, crsTransform, maxPixels, shardSize, fileDimensions, skipEmptyTiles, fileFormat, formatOptions)
Creates a batch task to export an Image as a raster to Drive. Tasks can be started from the Tasks tab. "crsTransform", "scale", and "dimensions" are mutually exclusive.
Arguments:
image (Image):
The image to export. 这里我们需要注意的是我们需要的对象是影像,而不是影像集合,所以我们这里一定要将影像集合处理为影像再来将其填充作为image参数使用。
description (String, optional):
A human-readable name of the task. May contain letters, numbers, -, _ (no spaces). Defaults to "myExportImageTask".
folder (String, optional):
The Google Drive Folder that the export will reside in. Note: (a) if the folder name exists at any level, the output is written to it, (b) if duplicate folder names exist, output is written to the most recently modified folder, (c) if the folder name does not exist, a new folder will be created at the root, and (d) folder names with separators (e.g. 'path/to/file') are interpreted as literal strings, not system paths. Defaults to Drive root.
fileNamePrefix (String, optional):
The filename prefix. May contain letters, numbers, -, _ (no spaces). 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.
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.
shardSize (Number, optional):
Size in pixels of the tiles in which this image will be computed. Defaults to 256.
fileDimensions (List<Number>|Number, optional):
The dimensions in pixels of each image file, if the image is too large to fit in a single file. May specify a single number to indicate a square shape, or an array of two dimensions to indicate (width,height). Note that the image will still be clipped to the overall image dimensions. Must be a multiple of shardSize.
skipEmptyTiles (Boolean, optional):
If true, skip writing empty (i.e. fully-masked) image tiles. Defaults to false.
fileFormat (String, optional):
The string file format to which the image is exported. Currently only 'GeoTIFF' and 'TFRecord' are supported, defaults to 'GeoTIFF'.
formatOptions (ImageExportFormatConfig, optional):
A dictionary of string keys to format specific options.
我们来看争取的代码:
代码语言:javascript复制//替换掉我们原来的波段描述,这里我们使用波段争取的波段名称
var data = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2")
.select('SR_B1');
// 这里我们到处影像可以选择第一景影像,或者以其他reduce形式的聚合或者镶嵌后的结果
var image = data.first();
//加载指定点,用来加载地图中心点位置
var roi = ee.Geometry.Rectangle(79.197, 9.2171,79.197, 9.2171);
Map.addLayer(roi);
//到处影像
Export.image.toDrive({
image: image,
scale: 65455,
description: 'Landcover',
region: roi
});