gdal_translate

在不同格式之间转换栅格数据。

简介

gdal_translate [--help-general]
    [-ot {Byte/Int16/UInt16/UInt32/Int32/UInt64/Int64/Float32/Float64/
            CInt16/CInt32/CFloat32/CFloat64}] [-strict]
    [-if format]* [-of format]
    [-b band]* [-mask band] [-expand {gray|rgb|rgba}]
    [-outsize xsize[%]|0 ysize[%]|0] [-tr xres yres]
    [-r {nearest,bilinear,cubic,cubicspline,lanczos,average,rms,mode}]
    [-unscale] [-scale[_bn] [src_min src_max [dst_min dst_max]]]* [-exponent[_bn] exp_val]*
    [-srcwin xoff yoff xsize ysize] [-epo] [-eco]
    [-projwin ulx uly lrx lry] [-projwin_srs srs_def]
    [-a_srs srs_def] [-a_coord_epoch <epoch>]
    [-a_ullr ulx uly lrx lry] [-a_nodata value]
    [-a_scale value] [-a_offset value]
    [-nogcp] [-gcp pixel line easting northing [elevation]]*
    |-colorinterp{_bn} {red|green|blue|alpha|gray|undefined}]
    |-colorinterp {red|green|blue|alpha|gray|undefined},...]
    [-mo "META-TAG=VALUE"]* [-q] [-sds]
    [-co "NAME=VALUE"]* [-stats] [-norat] [-noxmp]
    [-oo NAME=VALUE]*
    src_dataset dst_dataset

描述

这个 gdal_translate 该实用程序可用于在不同格式之间转换栅格数据,可能在处理过程中执行一些操作,如子设置、重采样和重缩放像素。

-ot <type>

强制输出图像带具有驱动程序支持的特定数据类型,该数据类型可以是以下类型之一: ByteUInt16Int16UInt32Int32Float32Float64CInt16CInt32CFloat32CFloat64 .

-strict

当转换为输出格式时,不要原谅不匹配和丢失的数据。

-if <format>

试图打开输入文件的格式/驱动程序名称。通常不需要指定它,但当它无法选择适当的驱动程序时,可以使用它跳过自动驱动程序检测。此选项可以重复多次以指定多个候选驱动程序。

3.2 新版功能.

-of <format>

选择输出格式。从GDAL 2.3开始,如果未指定,则从扩展名猜测格式(以前是GTiff)。使用短格式名称。

-b <band>

选择输入波段 band 输出。乐队从1开始编号。多重 -b 开关可用于选择一组输入频带以写入输出文件,或对频带重新排序。 band 也可以设置为“mask,1”(或仅“mask”),表示输入数据集的第一个频带的掩码频带。

-mask <band>

选择输入波段 band 创建输出数据集掩码带区。乐队从1开始编号。 band 可以设置为“无”,以避免复制输入数据集(如果存在)的全局掩码。否则默认情况下会复制它(“auto”),除非掩码是alpha通道,或者如果它被显式地用作输出数据集的常规频带(“-b mask”)。 band 也可以设置为“mask,1”(或仅“mask”),表示输入数据集的第1个波段的掩码频带。

-expand gray|rgb|rgba

将带颜色表的带1个色带的数据集公开为带3个(RGB)或4个(RGB a)色带的数据集。适用于不支持颜色索引数据集的输出驱动程序,如JPEG、JPEG2000、MrSID、ECW。“gray”值允许使用仅包含灰色级别的颜色表将数据集扩展到灰色索引数据集。

-outsize <xsize>[%]|0 <ysize>[%]|0

设置输出文件的大小。超大是以像素和线条表示的,除非附加“%”,在这种情况下,它只是输入图像大小的一小部分。如果两个值中的一个设置为0,则其值将从另一个值中确定,同时保持源数据集的纵横比。

-tr <xres> <yres>

设定目标分辨率。这些值必须用地理参考单位表示。两者都必须是正值。这与 -outsize-a_ullr .

-r {nearest (default),bilinear,cubic,cubicspline,lanczos,average,rms,mode}

选择重采样算法。

nearest 应用近邻(简单采样)重采样器

average 计算所有非NODATA贡献像素的平均值。从gdal3.1开始,这是一个加权平均值,适当地考虑了源像素的权重对目标像素的影响。

rms 计算所有非NODATA贡献像素的均方根/二次平均值(GDAL>=3.3)

bilinear 应用双线性卷积核。

cubic 应用三次卷积核。

cubicspline 应用B样条卷积核。

lanczos 应用Lanczos窗口sinc卷积核。

mode 选择在所有采样点中最常出现的值。

-scale [src_min src_max [dst_min dst_max]]

Rescale the input pixels values from the range src_min to src_max to the range dst_min to dst_max. If omitted the output range is 0 to 255. If omitted the input range is automatically computed from the source data. Note that these values are only used to compute a scale and offset to apply to the input raster values. In particular, src_min and src_max are not used to clip input values. -scale can be repeated several times (if specified only once, it also applies to all bands of the output dataset), so as to specify per band parameters. It is also possible to use the "-scale_bn" syntax where bn is a band number (e.g. "-scale_2" for the 2nd band of the output dataset) to specify the parameters of one or several specific bands.

-exponent <exp_val>

用幂函数作非线性标度。exp_val是幂函数的指数(必须为正)。此选项必须与-scale选项一起使用。如果只指定一次,-指数将应用于输出图像的所有波段。它可以重复多次,以便指定每个频带的参数。还可以使用“-exponent_bn”语法,其中bn是一个带号(例如,对于输出数据集的第二个带,“exponent_2”)来指定一个或多个特定带的参数。

-unscale

应用标注栏的缩放/偏移元数据,将缩放的值转换为未缩放的值。通常还需要使用 -ot 开关。

-srcwin <xoff> <yoff> <xsize> <ysize>

根据像素/线位置从源图像中选择要复制的子窗口。

-projwin <ulx> <uly> <lrx> <lry>

从源图像中选择要复制的子窗口(如 -srcwin )但角点以地理参考坐标表示(默认情况下以数据集的SRS表示)。可以更改为 -projwin_srs

备注

在GDAL 2.1.0和2.1.1中,在坐标与像素不对齐的情况下使用-projwin将导致亚像素偏移。这已在以后的版本中更正。当选择非最近邻重采样时,从GDAL 2.1.0开始,使用亚像素精度来获得更好的结果。

-projwin_srs <srs_def>

指定用于解释给定坐标的SRS -projwin . <srs_def>可以是任何常见的GDAL/OGR形式、完整的WKT、PROJ.4、EPSG:n或包含WKT的文件。

警告

这不会导致数据集重新投影到指定的SRS。

-epo

(部分在外部时出错)如果设置了此选项, -srcwin-projwin 部分落在源栅格范围之外的值将被视为错误。默认行为是接受这样的请求,当它们以前被视为错误时。

-eco

(完全在外部时出错)与 -epo ,但出错的标准是请求完全位于源栅格范围之外。

-a_srs <srs_def>

Override the projection for the output file.

The coordinate reference systems that can be passed are anything supported by the OGRSpatialReference.SetFromUserInput() call, which includes EPSG Projected, Geographic or Compound CRS (i.e. EPSG:4296), a well known text (WKT) CRS definition, PROJ.4 declarations, or the name of a .prj file containing a WKT CRS definition.

备注

No reprojection is done.

-a_coord_epoch <epoch>

3.4 新版功能.

Assign a coordinate epoch, linked with the output SRS. Useful when the output SRS is a dynamic CRS.

-a_scale <value>

Set band scaling value (no modification of pixel values is done)

2.3 新版功能.

-a_offset<value>

设置波段偏移值(不修改像素值)

2.3 新版功能.

-a_ullr <ulx> <uly> <lrx> <lry>

指定/覆盖输出文件的地理参考边界。这会将地理参考边界指定给输出文件,忽略从源文件派生的边界。因此,这不会导致对指定SRS的重新投影。

-a_nodata <value>

Assign a specified nodata value to output bands. It can be set to none to avoid setting a nodata value to the output file if one exists for the source file. Note that, if the input dataset has a nodata value, this does not cause pixel values that are equal to that nodata value to be changed to the value specified with this option.

-colorinterp_X <red|green|blue|alpha|gray|undefined>

覆盖波段X的颜色解释(其中X是有效的波段号,从1开始)

2.3 新版功能.

-colorinterp <red|green|blue|alpha|gray|undefined[,red|green|blue|alpha|gray|undefined]*>

覆盖所有指定标注栏的颜色解释。例如-colorinterp红色、绿色、蓝色、alpha,用于4波段输出数据集。

2.3 新版功能.

-mo META-TAG=VALUE

如果可能,传递要在输出数据集上设置的元数据键和值。

-co <NAME=VALUE>

许多格式都有一个或多个可选的创建选项,可用于控制所创建文件的详细信息。例如,GeoTIFF驱动程序支持创建选项来控制压缩,以及是否应该平铺文件。

可用的创建选项因格式驱动程序而异,有些简单格式根本没有创建选项。格式支持的选项列表可以与 --formats 命令行选项,但该格式的文档是有关驱动程序创建选项的最终信息源。见 栅格驱动器 每种格式的法律创建选项的特定格式文档。

-nogcp

不要将源数据集中的gcp复制到输出数据集中。

-gcp <pixel> <line> <easting> <northing> <elevation>

将指定的地面控制点添加到输出数据集。可多次提供此选项以提供一组GCP。

-q

抑制进度监视器和其他非错误输出。

-sds

将此文件的所有子数据集复制到各个输出文件。与具有子数据集的HDF等格式一起使用。

-stats

统计的强制(重新)计算。

-norat

不要将源RAT复制到目标数据集中。

-noxmp

当驱动程序能够复制源数据集中的XMP元数据时,不要将其复制到输出数据集中。

3.2 新版功能.

-oo NAME=VALUE

数据集打开选项(特定于格式)

<src_dataset>

源数据集名称。它可以是文件名、数据源的URL或多数据集文件的子数据集名称。

<dst_dataset>

目标文件名。

计算机辅助编程接口

此实用程序也可以通过 GDALTranslate() .

2.1 新版功能.

实例

gdal_translate -of GTiff -co "TILED=YES" utm.tif utm_tiled.tif

从RGBA数据集创建带内部掩码的JPEG压缩TIFF

gdal_translate rgba.tif withmask.tif -b 1 -b 2 -b 3 -mask 4 -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR --config GDAL_TIFF_INTERNAL_MASK YES

从带有掩码的RGB数据集创建RGB a数据集

gdal_translate withmask.tif rgba.tif -b 1 -b 2 -b 3 -b mask