gdalwarp

图像重投影和扭曲实用程序

简介

gdalwarp [--help-general] [--formats]
    [-s_srs srs_def] [-t_srs srs_def] [-ct string] [-to "NAME=VALUE"]* [-vshift | -novshift]
    [[-s_coord_epoch epoch] | [-t_coord_epoch epoch]]
    [-order n | -tps | -rpc | -geoloc] [-et err_threshold]
    [-refine_gcps tolerance [minimum_gcps]]
    [-te xmin ymin xmax ymax] [-te_srs srs_def]
    [-tr xres yres] [-tap] [-ts width height]
    [-ovr level|AUTO|AUTO-n|NONE] [-wo "NAME=VALUE"] [-ot Byte/Int16/...] [-wt Byte/Int16]
    [-srcnodata "value [value...]"] [-dstnodata "value [value...]"]
    [-srcalpha|-nosrcalpha] [-dstalpha]
    [-r resampling_method] [-wm memory_in_mb] [-multi] [-q]
    [-cutline datasource] [-cl layer] [-cwhere expression]
    [-csql statement] [-cblend dist_in_pixels] [-crop_to_cutline]
    [-if format]* [-of format] [-co "NAME=VALUE"]* [-overwrite]
    [-nomd] [-cvmd meta_conflict_value] [-setci] [-oo NAME=VALUE]*
    [-doo NAME=VALUE]*
    srcfile* dstfile

描述

这个 gdalwarp 实用程序是一种图像拼接、重投影和扭曲实用程序。该程序可以重新投影到任何支持的投影,也可以应用与图像一起存储的gcp,如果图像是带有控制信息的“原始”图像。

-s_srs <srs def>

Set source spatial reference. If not specified the SRS found in the input dataset will be used.

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.

Starting with GDAL 2.2, if the SRS has an explicit vertical datum that points to a PROJ.4 geoidgrids, and the input dataset is a single band dataset, a vertical correction will be applied to the values of the dataset.

-s_coord_epoch <epoch>

3.4 新版功能.

Assign a coordinate epoch, linked with the source SRS. Useful when the source SRS is a dynamic CRS. Only taken into account if -s_srs is used.

Currently -s_coord_epoch and -t_coord_epoch are mutually exclusive, due to lack of support for transformations between two dynamic CRS.

-t_srs <srs_def>

设置目标空间参考。

A source SRS must be available for reprojection to occur. The source SRS will be by default the one found in the input dataset when it is available, or as overridden by the user with -s_srs

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.

Starting with GDAL 2.2, if the SRS has an explicit vertical datum that points to a PROJ.4 geoidgrids, and the input dataset is a single band dataset, a vertical correction will be applied to the values of the dataset.

-t_coord_epoch <epoch>

3.4 新版功能.

Assign a coordinate epoch, linked with the target SRS. Useful when the target SRS is a dynamic CRS. Only taken into account if -t_srs is used.

Currently -s_coord_epoch and -t_coord_epoch are mutually exclusive, due to lack of support for transformations between two dynamic CRS.

-ct <string>

PROJ字符串(以+PROJ=pipeline开头的单步操作或多步字符串)、描述CoordinateOperation的WKT2字符串或urn:ogc:def:CoordinateOperation:EPSG::XXXX urn重写从源到目标CRS的默认转换。它必须考虑源和目标CRS的轴顺序。

3.0 新版功能.

-to <NAME=VALUE>

Set a transformer option suitable to pass to GDALCreateGenImgProjTransformer2(). See GDALCreateRPCTransformerV2() for RPC specific options.

-vshift

Force the use of vertical shift. This option is generally not necessary, except when using an explicit coordinate transformation (-ct), and not specifying an explicit source and target SRS.

3.4 新版功能.

-novshift

Disable the use of vertical shift when one of the source or target SRS has an explicit vertical datum, and the input dataset is a single band dataset.

备注

this option was named -novshiftgrid in GDAL 2.2 to 3.3.

3.4 新版功能.

-order <n>

用于翘曲的多项式的阶数(1到3)。默认值是根据gcp的数量选择多项式顺序。

-tps

基于现有GCPs的薄板样条变压器的受力分析。

-rpc

强制使用RPCs。

-geoloc

强制使用地理定位阵列。

-et <err_threshold>

Error threshold for transformation approximation (in pixel units - defaults to 0.125, unless, starting with GDAL 2.1, the RPC_DEM transformer option is specified, in which case, an exact transformer, i.e. err_threshold=0, will be used).

-refine_gcps <tolerance minimum_gcps>

通过自动消除异常值来优化gcp。异常值将被消除,直到留下最小的GCP或没有异常值被检测到。当GCP被消除时,通过公差进行调整。并不是说GCP求精只适用于多项式插值。如果没有可用的投影,则公差以像素单位表示,否则以SRS单位表示。如果未提供最小gcps,则使用多项式模型中的最小gcps。

-te <xmin ymin xmax ymax>

设置要创建的输出文件的地理参考范围(默认情况下在目标SRS中,或在使用 -te_srs

-te_srs <srs_def>

指定要在其中解释用-te给出的坐标的SRS。<srs_def>可以是任何常见的GDAL/OGR形式、完整的WKT、PROJ.4、EPSG:n或包含WKT的文件。这不能与-t_srs混淆,后者是输出数据集的目标srs。 -te_srs 是一种方便,例如,当知道大地测量长/纬度SRS中的输出坐标时,但仍希望得到投影坐标系的结果。

-tr <xres> <yres>

设置输出文件分辨率(以目标地理参考单位为单位)。

如果没有指定(或者没有从-te和-ts推导),gdalwarp将生成一个xres=yres的输出栅格,即使在不涉及重投影的场景中使用gdalwarp也是如此。

-tap

(target aligned pixels) align the coordinates of the extent of the output file to the values of the -tr, such that the aligned extent includes the minimum extent. Alignment means that xmin / resx, ymin / resy, xmax / resx and ymax / resy are integer values.

-ts <width> <height>

设置输出文件大小(以像素和行为单位)。如果“宽度”或“高度”设置为0,则将根据计算的分辨率猜测其他尺寸。请注意 -ts 不能与一起使用 -tr

-ovr <level|AUTO|AUTO-n|NONE>

指定必须使用的源文件的概述级别。默认选择“自动”将选择其分辨率最接近目标分辨率的概述级别。指定一个整数值(基于0,即0=第一个概述级别)以选择特定级别。指定AUTO-n,其中n是大于或等于1的整数,以选择AUTO级别下的概述级别。或者指定“无”以强制使用基础分辨率(如果使用低质量重采样方法生成俯视图,并且使用高质量重采样方法完成扭曲,则此选项非常有用)。

-wo `"NAME=VALUE"`

设置扭曲选项。这个 GDALWarpOptions::papszWarpOptions 文档显示所有选项。多重 -wo 可能会列出选项。

-ot <type>

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

-wt <type>

工作像素数据类型。源图像和目标图像缓冲区中像素的数据类型。

-r <resampling_method>

要使用的重采样方法。可用的方法有:

near :近邻重采样(默认、最快算法、最差插值质量)。

bilinear :双线性重采样。

cubic :立方重采样。

cubicspline :三次样条线重采样。

lanczos :Lanczos窗口sinc重新采样。

average :平均重采样,计算所有非节点数据贡献像素的加权平均值。

rms 所有非节点数据贡献像素的均方根/二次平均值(GDAL>=3.3)

mode: mode resampling, selects the value which appears most often of all the sampled points. In the case of ties, the first value identified as the mode will be selected.

max :最大重采样,从所有非节点数据贡献像素中选择最大值。

min :最小重采样,从所有非节点数据贡献像素中选择最小值。

med :中值重采样,选择所有非节点数据贡献像素的中值。

q1 :第一个四分位重采样,选择所有非节点数据贡献像素的第一个四分位值。

q3 :第三个四分位重采样,选择所有非节点数据贡献像素的第三个四分位值。

sum :计算所有非NODATA贡献像素的加权和(从GDAL 3.1开始)

-srcnodata <value [value...]>

Set nodata masking values for input bands (different values can be supplied for each band). If more than one value is supplied all values should be quoted to keep them together as a single operating system argument. Masked values will not be used in interpolation. Use a value of None to ignore intrinsic nodata settings on the source dataset.

When this option is set to a non-None value, it causes the UNIFIED_SRC_NODATA warping option (see GDALWarpOptions::papszWarpOptions) to be set to YES, if it is not explicitly set.

If -srcnodata is not explicitly set, but the source dataset has nodata values, they will be taken into account, with UNIFIED_SRC_NODATA at PARTIAL by default.

-dstnodata <value [value...]>

为输出频带设置nodata值(每个频带可以提供不同的值)。如果提供了多个值,则应引用所有值,以便将它们作为单个操作系统参数放在一起。新文件将初始化为该值,如果可能,nodata值将记录在输出文件中。使用值 None 以确保未定义nodata。如果不使用此参数,则将从源数据集中复制nodata值。

-srcalpha

强制将源图像的最后一个波段视为源alpha波段。

-nosrcalpha

防止将源图像的alpha波段视为alpha波段(它将被扭曲为常规波段)

2.2 新版功能.

-dstalpha

创建一个输出alpha波段来标识nodata(未设置/透明)像素。

-wm <memory_in_mb>

设置允许warp API用于缓存的内存量。如果值小于10000,则该值将被解释为以兆字节为单位。对于大于等于10000的值,这将解释为字节。

-multi

使用多线程扭曲实现。两个线程将用于处理图像块并同时执行输入/输出操作。注意,计算本身不是多线程的。为此,您可以使用 -wo NUM_THREADS=val/ALL_CPU选项,可以与 -multi

-q

安静点。

-if <format>

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

3.2 新版功能.

-of <format>

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

-co <NAME=VALUE>

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

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

-cutline <datasource>

启用名称OGR support datasource中的混合剪切线。

-cl <layername>

从剪切线数据源中选择命名图层。

-cwhere <expression>

基于属性查询限制所需的剖切线特征。

-csql <query>

使用SQL查询而不是从具有 -cl .

-cblend <distance>

设置用于在剪切线上混合的混合距离(以像素为单位)。

-crop_to_cutline

将目标数据集的范围裁剪到剪切线的范围。

-overwrite

Overwrite the target dataset if it already exists. Overwriting must be understood here as deleting and recreating the file from scratch. Note that if this option is not specified and the output file already exists, it will be updated in place.

-nomd

不要复制元数据。如果没有此选项,数据集和标注栏元数据(以及某些标注栏信息)将从第一个源数据集中复制。源数据集之间不同的项将设置为*(请参见 -cvmd 选择权。

-cvmd <meta_conflict_value>

值设置源数据集之间冲突的元数据项(默认值为“*”)。使用“”删除冲突项。

-setci

从源数据集中设置目标数据集的色带的颜色解释。

-oo <NAME=VALUE>

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

-doo <NAME=VALUE>

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

2.1 新版功能.

<srcfile>

源文件名。

<dstfile>

目标文件名。

如果输出文件已经存在,则支持镶嵌到现有输出文件中。不会修改现有文件的空间范围以容纳新数据,因此在这种情况下,您可能必须将其删除,或者使用-overwrite选项。

多边形剪切线可用作遮罩,以限制可能更新的目标文件的区域,包括混合。如果包含剪切线要素的OGR层没有显式SRS,则剪切线要素必须位于目标文件的SRS中。当写入尚未存在的目标数据集时,其范围将是原始栅格的范围,除非指定了-te或-crop_to_剪切线。

从GDAL 3.1开始,可以使用只支持CreateCopy操作的驱动程序作为输出格式。这可能在内部意味着创建一个临时文件。

实例

  • 基本转换:

gdalwarp -t_srs EPSG:4326 input.tif output.tif
  • 例如,一个存储在GeoTIFF中的8位spot场景,其控制点将角点映射到lat/long,可以使用如下命令将其扭曲为UTM投影:

gdalwarp -t_srs '+proj=utm +zone=11 +datum=WGS84' -overwrite raw_spot.tif utm11.tif
  • 例如,存储在HDF中的ASTER图像的第二个通道(带有将角点映射到lat/long的控制点)可以使用如下命令扭曲为UTM投影:

    2.2 新版功能.

gdalwarp -overwrite HDF4_SDS:ASTER_L1B:"pg-PR1B0000-2002031402_100_001":2 pg-PR1B0000-2002031402_100_001_2.tif
  • 要在非地理参考图像上应用剪切线并从像素(220,60)剪裁到像素(1160690),请执行以下操作:

gdalwarp -overwrite -to SRC_METHOD=NO_GEOTRANSFORM -to DST_METHOD=NO_GEOTRANSFORM -te 220 60 1160 690 -cutline cutline.csv in.png out.tif

其中cutline.csv内容如下:

id,WKT
1,"POLYGON((....))"
  • 要将DEM从大地水准面高程(使用EGM96)转换为WGS84椭球高度:

    2.2 新版功能.

gdalwarp -overwrite in_dem.tif out_dem.tif -s_srs EPSG:4326+5773 -t_srs EPSG:4979

也见

Wiki page discussing options and behaviours of gdalwarp