gdal_api教程

上传人:第*** 文档编号:34209840 上传时间:2018-02-21 格式:DOC 页数:22 大小:182.50KB
返回 下载 相关 举报
gdal_api教程_第1页
第1页 / 共22页
gdal_api教程_第2页
第2页 / 共22页
gdal_api教程_第3页
第3页 / 共22页
gdal_api教程_第4页
第4页 / 共22页
gdal_api教程_第5页
第5页 / 共22页
点击查看更多>>
资源描述

《gdal_api教程》由会员分享,可在线阅读,更多相关《gdal_api教程(22页珍藏版)》请在金锄头文库上搜索。

1、GDAL API TutorialBefore 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 driver

2、s, 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 gdalallre

3、gister.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 datas

4、et, 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.hint main()GDALDataset *poDataset;GDALAllRegister();poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_

5、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 C

6、PLError() 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 不需要确实是物理文件名称(尽管通常都是如此)

7、。Its interpretation is driver dependent, and it might be an URL, a filename with additional parameters added at the end controlling the open or almost anything. 这个解释了驱动的依赖性,它可能是一个 URL, 带有加在最后的额外的参数的文件名,控制了打开或是其他行为。Please try not to limit GDAL file selection dialogs to only selecting physical files.请

8、不要去限制 GDAL 文件选择对话框去仅仅选择物理文件。Getting Dataset InformationAs described in the GDAL Data Model, a GDALDataset contains a list of raster bands, all pertaining to the same area, and having the same resolution.作为在 GDAL Data model 的描述,一个 GDALDataset 包含了一个栅格波段列表,都属于相同区域,并且有相同分辨率。It also has metadata, a coord

9、inate system, a georeferencing transform, size of raster and various other information.也同样含有元数据,坐标系统,地理参考坐标系转换,栅格大小和多种多样的其他数据。adfGeoTransform0 /* top left x */adfGeoTransform1 /* w-e pixel resolution */adfGeoTransform2 /* rotation, 0 if image is north up */adfGeoTransform3 /* top left y */adfGeoTran

10、sform4 /* rotation, 0 if image is north up */adfGeoTransform5 /* n-s pixel resolution */If we wanted to print some general information about the dataset we might do the following:如果我们想要输出一些关于 dataset 的主要信息,我们可以按以下所说的做:In C+: double adfGeoTransform6;printf( Driver: %s/%sn,poDataset-GetDriver()-GetDes

11、cription(), poDataset-GetDriver()-GetMetadataItem( GDAL_DMD_LONGNAME ) );printf( Size is %dx%dx%dn, poDataset-GetRasterXSize(), poDataset-GetRasterYSize(),poDataset-GetRasterCount() );if( poDataset-GetProjectionRef() != NULL )printf( Projection is %sn, poDataset-GetProjectionRef() );if( poDataset-Ge

12、tGeoTransform( adfGeoTransform ) = CE_None )printf( Origin = (%.6f,%.6f)n,adfGeoTransform0, adfGeoTransform3 );printf( Pixel Size = (%.6f,%.6f)n,adfGeoTransform1, adfGeoTransform5 );Fetching a Raster BandAt this time access to raster data via GDAL is done one band at a time.这时通过 GDAL 存取栅格数据,每次只完成一个波

13、段。Also, there is metadata, blocksizes, color tables, and various other information available on a band by band basis.同样以波段为基础的元数据,区块,颜色表和其他可见的信息The following codes fetches a GDALRasterBand object from the dataset (numbered 1 through GetRasterCount() and displays a little information about it.下面的代码从

14、dataset(通过 GetRasterCount()被记为 1)中获取 GDALRasterBand 对象,并显示一些有关的信息。In C+: GDALRasterBand *poBand;int nBlockXSize, nBlockYSize;int bGotMin, bGotMax;double adfMinMax2;poBand = poDataset-GetRasterBand( 1 );poBand-GetBlockSize( printf( Block=%dx%d Type=%s, ColorInterp=%sn,nBlockXSize, nBlockYSize,GDALGet

15、DataTypeName(poBand-GetRasterDataType(),GDALGetColorInterpretationName(poBand-GetColorInterpretation() );adfMinMax0 = poBand-GetMinimum( adfMinMax1 = poBand-GetMaximum( if( ! (bGotMin & bGotMax) )GDALComputeRasterMinMax(GDALRasterBandH)poBand, TRUE, adfMinMax);printf( Min=%.3fd, Max=%.3fn, adfMinMax

16、0, adfMinMax1 );if( poBand-GetOverviewCount() 0 )printf( Band has %d overviews.n, poBand-GetOverviewCount() );if( poBand-GetColorTable() != NULL )printf( Band has a color table with %d entries.n, poBand-GetColorTable()-GetColorEntryCount() );Reading Raster DataThere are a few ways to read raster data, but the mo

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号