美文网首页
GDALWarp()解析

GDALWarp()解析

作者: NullUser | 来源:发表于2023-04-12 19:24 被阅读0次

基本

在gdal_utils.h中提供GDALWarp()接口对图像进行重投影和变换。

/**
 * Image reprojection and warping function.
 *
 * This is the equivalent of the <a href="/programs/gdalwarp.html">gdalwarp</a> utility.
 *
 * GDALWarpAppOptions* must be allocated and freed with GDALWarpAppOptionsNew()
 * and GDALWarpAppOptionsFree() respectively.
 * pszDest and hDstDS cannot be used at the same time.
 *
 * @param pszDest the destination dataset path or NULL.
 * @param hDstDS the destination dataset or NULL.
 * @param nSrcCount the number of input datasets.
 * @param pahSrcDS the list of input datasets.
 * @param psOptionsIn the options struct returned by GDALWarpAppOptionsNew() or NULL.
 * @param pbUsageError pointer to a integer output variable to store if any usage error has occurred, or NULL.
 * @return the output dataset (new dataset that must be closed using GDALClose(), or hDstDS if not NULL) or NULL in case of error.
 *
 * @since GDAL 2.1
 */

GDALDatasetH GDALWarp( const char *pszDest, GDALDatasetH hDstDS,
                       int nSrcCount,
                       GDALDatasetH *pahSrcDS,
                       const GDALWarpAppOptions *psOptionsIn,
                       int *pbUsageError );

参数

该接口除了输入输出等基本参数外,栅格化的具体参数都放入了形参const GDALWarpAppOptions *psOptionsIn中,而参数形式同GDAL App中的gdal_warp相同(gdal_warp)
设置参数可参考:

    char** papszArgv = nullptr;
    papszArgv = CSLAddString(papszArgv, "-t_srs");
    papszArgv = CSLAddString(papszArgv, "EPSG:4326");
    GDALWarpAppOptions* options = GDALWarpAppOptionsNew(papszArgv, nullptr);
    CSLDestroy(papszArgv);
  • -b <n>
  • -srcband <n>
    指定输入波段,如果没有指定,则应用于所有波段。
    可以同时指定多个波段:-b 3 -b 2 -b 1。
  • -dstband <n>
    指定输出波段,实际应用中,此选项仅在更新现有数据集时才有用。
    如:
gdalwarp in_red.tif out_rgb.tif -srcband 1 -dstband 1
gdalwarp in_green.tif out_rgb.tif -srcband 1 -dstband 2
gdalwarp in_blue.tif out_rgb.tif -srcband 1 -dstband 3
  • -s_srs <srs def>
    指定源空间参考系,如果没指定,则从输入源中获取。<srs_def>可以使用WKT 文本,PROJ.4,EPSG:n或者一个包含WKT的文件。

  • -s_coord_epoch <epoch>
    指定坐标历元。

  • -t_srs <srs def>
    指定目标空间参考,必须有源SRS用于重投影。

  • -t_coord_epoch <epoch>
    指定坐标历元。

  • -ct
    (Coordinate transformation)。A PROJ string (single step operation or multiple step string starting with +proj=pipeline), a WKT2 string describing a CoordinateOperation, or a urn:ogc:def:coordinateOperation:EPSG::XXXX URN overriding the default transformation from the source to the target CRS. It must take into account the axis order of the source and target CRS.
    New in version 3.0.

  • -te <xmin ymin xmax ymax>
    设置输出文件的地理范围。(默认是目标SRS,或者用-te_srs指定)。

  • -te_srs
    指定输出范围使用的坐标系。

  • -tr <xres> <yres> | -tr square
    设置输出文件的分辨率(使用目标地理单位)。

  • -tap
    (target aligned pixels)将输出文件的范围坐标与-tr参数对齐。

  • -ts <width> <height>
    设置输出文件的尺寸(宽、高)。

  • -ot <type>
    指定输出的波段数据类型。

  • -r <resampling_method>
    重采样方法:
    near:最近邻重采样
    bilinear:双线性重采样
    cubic:cubic resampling
    cubicspline:cubic spline resampling
    lanczos:Lanczos windowed sinc resampling.
    average:average resampling, computes the weighted average of all non-NODATA contributing pixels.
    rms:root mean square / quadratic mean of all non-NODATA contributing pixels (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:maximum resampling, selects the maximum value from all non-NODATA contributing pixels.
    min:minimum resampling, selects the minimum value from all non-NODATA contributing pixels.
    med:median resampling, selects the median value of all non-NODATA contributing pixels.
    q1:first quartile resampling, selects the first quartile value of all non-NODATA contributing pixels.
    q3:third quartile resampling, selects the third quartile value of all non-NODATA contributing pixels.
    sum:compute the weighted sum of all non-NODATA contributing pixels (since GDAL 3.1)

相关文章

网友评论

      本文标题:GDALWarp()解析

      本文链接:https://www.haomeiwen.com/subject/mljoddtx.html