配置选项

本页讨论GDAL的运行时配置选项。这些选项与构建时配置脚本的选项不同。运行时配置选项适用于所有平台,并在运行时进行评估。它们可以通过编程、命令行开关或用户在环境中进行设置。

配置选项通常用于更改GDAL/OGR驱动程序的默认行为,在某些情况下还用于更改GDAL/OGR核心。它们本质上是用户可以设置的全局变量。

如何设置配置选项?

选项是一个配置示例 GDAL_CACHEMAX 选项。它控制GDAL块缓存的大小(以兆字节为单位)。可以在Unix(bash/bourne)shell上的环境中进行如下设置:

export GDAL_CACHEMAX=64

或者只是为了这个命令,像这样:

GDAL_CACHEMAX=64 gdal_translate 64 in.tif out.tif

在DOS/Windows命令行程序中,执行如下操作:

set GDAL_CACHEMAX=64

它也可以在命令行上为大多数GDAL和OGR实用程序设置 --config 开关,尽管在少数情况下,这些开关没有及时评估以影响行为。

gdal_translate --config GDAL_CACHEMAX 64 in.tif out.tif

在C/C++中,配置开关可以编程方式设置。 CPLSetConfigOption()

#include "cpl_conv.h"
...
    CPLSetConfigOption( "GDAL_CACHEMAX", "64" );

通常,配置选项适用于程序中活动的所有线程,但它们只能限于具有 CPLSetThreadLocalConfigOption()

CPLSetThreadLocalConfigOption( "GTIFF_DIRECT_IO", "YES" );

对于布尔选项,可以使用“是”、“真”或“开”值来打开该选项;使用“否”、“假”或“关”来关闭该选项。

GDAL configuration file

3.3 新版功能.

On driver registration, loading of configuration is attempted from a set of predefined files.

The following locations are tried by CPLLoadConfigOptionsFromPredefinedFiles():

  • the location pointed by the environment variable (or configuration option) GDAL_CONFIG_FILE is attempted first. If it set, the next steps are not attempted

  • for Unix builds, the location pointed by ${sysconfdir}/gdal/gdalrc is first attempted (where ${sysconfdir} evaluates to ${prefix}/etc, unless the --sysconfdir switch of ./configure has been invoked). Then $(HOME)/.gdal/gdalrc is tried, potentially overriding what was loaded with the sysconfdir

  • for Windows builds, the location pointed by $(USERPROFILE)/.gdal/gdalrc is attempted.

A configuration file is a text file in a .ini style format, that lists configuration options and their values. Lines starting with # are comment lines.

例子:

[configoptions]
# set BAR as the value of configuration option FOO
FOO=BAR

Configuration options set in the configuration file can later be overridden by calls to CPLSetConfigOption() or CPLSetThreadLocalConfigOption(), or through the --config command line switch.

The value of environment variables set before GDAL starts will be used instead of the value set in the configuration files.

配置选项列表及其应用位置

备注

这个名单是不完整的。这取决于文档中其他地方提到的配置选项的正确注释。如果您想帮助扩展它,请使用 :decl_configoption:`NAME `提到配置选项的地方的语法。