GDAL_API教程GDAL_API教程
GDAL API Tutorial
Before opening a GDAL supported raster datastore it is necessary to register drivers.
在打开一个GDAL支持的栅格资料之前,必需要注册驱动。
There is a driver for each supported format.
每个驱动对应各自支持的格式。
Normally this is accomplished with the GDALAllRegister() function which attempts to register all known drivers, including those auto-loaded from .so files using GDALDriverManager::AutoLoadDrivers().
通常这个会被GDALAllRegister()函数完成,试图去注册所有已知的驱动包括使用GDALDriverManager::AutoLoadDrivers()从.so文件来加载。
If for some applications it is necessary to limit the set of drivers it may be helpful to review the code from gdalallregister.cpp.
如果一些程序有必要去限制驱动集合,检查gdalallregister.cpp的代码将会有所帮助,
Python automatically calls GDALAllRegister() when the gdal module is imported.
当gdal模块被导入时,Python会自动调用GDALAllRegister()。
Once the drivers are registered, the application should call the free standing GDALOpen() function to open a dataset, passing the name of the dataset and the access desired (GA_ReadOnly or GA_Update).
一但驱动被注册,程序将会调用独立的GDALOpen()函数通过dataset的名称和需要的存取方式(GA_ReadOnly或GA_Update)来打开dataset.
#include "gdal_priv.h"
int main()
{
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
if( poDataset == NULL )
{
...;
}
Note that if GDALOpen() returns NULL it means the open failed, and that an error messages will already have been emitted via CPLError().
注意 如果GDALOpen()返回NULL,意味着打开失败了,这个错误信息将会通过CPLError()释放出。
If you want to control how errors are reported to the user review the CPLError() documentation.
如果你想控制错误怎样被报告给用户,参考CPLError文档。
Generally speaking all of GDAL uses CPLError() for error reporting.
一般而言,所有的GDAL都是用CPLError()来报告错误。
Also, note that pszFilename need not actually be the name of a physical file (though it usually is).
同样,注意pszFilename 不需要确实是物理文件名称(尽管通常都是如此)。
It's interpretation is driver dependent, and it might be an URL, a filename with additional parameters added at the end controlling the open