GDALRasterize()解析

2023-02-27  本文已影响0人  NullUser

基本

在gdal_utils.h中提供GDALRasterize()接口将矢量栅格化。函数原型:GDALRasterize()

/************************************************************************/
/*                             GDALRasterize()                          */
/************************************************************************/

/**
 * Burns vector geometries into a raster
 *
 * This is the equivalent of the <a href="/programs/gdal_rasterize.html">gdal_rasterize</a> utility.
 *
 * GDALRasterizeOptions* must be allocated and freed with GDALRasterizeOptionsNew()
 * and GDALRasterizeOptionsFree() 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 hSrcDataset the source dataset handle.
 * @param psOptionsIn the options struct returned by GDALRasterizeOptionsNew() 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 is not NULL) or NULL in case of error.
 *
 * @since GDAL 2.1
 */

GDALDatasetH GDALRasterize( const char *pszDest, GDALDatasetH hDstDS,
                            GDALDatasetH hSrcDataset,
                            const GDALRasterizeOptions *psOptionsIn, int *pbUsageError );

参数

该接口除了输入输出等基本参数外,栅格化的具体参数都放入了形参const GDALRasterizeOptions *psOptionsIn中(如分辨率、数据类型等),而参数形式同GDAL App中的gdal_rasterize相同(gdal_rasterize
设置参数可参考:

char **papszArgv  = nullptr;
papszArgv = CSLAddString(papszArgv, "-ts");
papszArgv = CSLAddString(papszArgv, "1277");
papszArgv = CSLAddString(papszArgv, "979");
papszArgv = CSLAddString(papszArgv, "-ot");
papszArgv = CSLAddString(papszArgv, "Byte");
GDALRasterizeOptions *psOptions = GDALRasterizeOptionsNew(papszArgv, nullptr);
CSLDestroy(papszArgv);
switch( eDataType )
    {
      case GDT_Unknown:
        return "Unknown";

      case GDT_Byte:
        return "Byte";

      case GDT_UInt16:
        return "UInt16";

      case GDT_Int16:
        return "Int16";

      case GDT_UInt32:
        return "UInt32";

      case GDT_Int32:
        return "Int32";

      case GDT_UInt64:
        return "UInt64";

      case GDT_Int64:
        return "Int64";

      case GDT_Float32:
        return "Float32";

      case GDT_Float64:
        return "Float64";

      case GDT_CInt16:
        return "CInt16";

      case GDT_CInt32:
        return "CInt32";

      case GDT_CFloat32:
        return "CFloat32";

      case GDT_CFloat64:
        return "CFloat64";

      default:
        return nullptr;
    }
上一篇下一篇

猜你喜欢

热点阅读