GIS足迹

用地图装点生活的每个角落。MSN:gisfoot@hotmail.com。QQ交流群1:42019368(已满);QQ交流群2:85857545。

« GIS开源程序收集[zt]Flex开发地图应用教程(一) »

gdal库常见用法

对于一个图像库来说,最为常见的几种操作莫过于:打开图像、读取数据、获取相关信息、创建新的文件。
下面,结合下面一个例子来说明:
运行环境:ubuntu 7.10 编译器:gcc
库文件: gdal 1.5.0

#include "gdal_priv.h"
#include <string>
#include <iostream>

using namespace std;

// #info should show the info's name
#define show( info) cout << #info <<" : " << info << endl;
int main()
{
   GDALDataset *poDataset;

   GDALAllRegister();

   string pszFilename = "cea.tif";

   //GDALDataset* GDALOpenShared(const char* pszFilename, GDALAccess eAccess)
   poDataset = (GDALDataset *) GDALOpen( pszFilename.c_str(), GA_ReadOnly );
   if( poDataset != NULL )
   {
      //Fetch the data type :GTiff means GeoTiff
      show(poDataset->GetDriver()->GetDescription() );
    
      //affine transformation coefficients
      double adfGeoTransform[6];
 
      //Fetch the number of raster bands on this dataset
      //GetRasterYsize() and GetRasterCount()
      show(poDataset->GetRasterXSize() );
      show(poDataset->GetRasterYSize() );
      show(poDataset->GetRasterCount() );

      //Fetch single metadata item
      if(poDataset->GetMetadataItem( GDAL_DMD_LONGNAME) != NULL)
      {
         show(poDataset->GetMetadataItem( GDAL_DMD_LONGNAME) );
      }

      //Fetch the projection definition string for this dataset
      show(poDataset->GetProjectionRef() );

      //Fetch the value
      if (poDataset->GetGeoTransform( adfGeoTransform) == CE_None)
      {
         for(int i=0; i<6; ++i)
         {
             show(adfGeoTransform[i]);
         }
      }
   }

   return 0;
}


结果与说明:
//获取文件信息
poDataset->GetDriver()->GetDescription() : GTiff
//获取X,Y坐标
poDataset->GetRasterXSize() : 514
poDataset->GetRasterYSize() : 515
//获取波段数
poDataset->GetRasterCount() : 1
//获取坐标信息
poDataset->GetProjectionRef() : PROJCS["unnamed",GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.9786982138982,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],
PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433],AUTHORITY["EPSG","4267"]],
PROJECTION["Cylindrical_Equal_Area"],PARAMETER["standard_parallel_1",33.75],
PARAMETER["central_meridian",-117.333333333333],PARAMETER["false_easting",0],
PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]

adfGeoTransform[i] : -28493.2
adfGeoTransform[i] : 60.0221 
adfGeoTransform[i] : 0       
adfGeoTransform[i] : 4.25588e+06
adfGeoTransform[i] : 0
adfGeoTransform[i] : -60.0221

/*
 * when set the data information,
 * sorry, i should check the adfGeoTransform[2]
 * don't forget set the adfGeoTransform[2] and adfGeoTransform[5]
   adfGeoTransform[0] // top left x
   adfGeoTransform[1] // w-e pixel resolution
   adfGeoTransform[2] // rotation, 0 if image is "north up"
   adfGeoTransform[3] // top left y
   adfGeoTransform[4] // rotation, 0 if image is "north up"
   adfGeoTransform[5] // n-s pixel resolution
*/

使用gdal库前,必须使用GDALAllRegister()函数
打开图像,返回GDALDataset *对象。
GDALDatasetH GDALOpen      (      const char *        pszFilename,
        GDALAccess      eAccess     )

至于GDALDataset里面的对象:
This is the complete list of members for GDALDataset, including all inherited members.
AddBand(GDALDataType eType, char **papszOptions=NULL) GDALDataset [virtual]
AdviseRead(int nXOff, int nYOff, int nXSize, int nYSize, int nBufXSize, int nBufYSize, GDALDataType eDT, int nBandCount, int *panBandList, char **papszOptions) GDALDataset [virtual]
bForceCachedIO (defined in GDALDataset) GDALDataset [protected]
BlockBasedFlushCache() (defined in GDALDataset) GDALDataset [protected]
BlockBasedRasterIO(GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int *, int, int, int) (defined in GDALDataset) GDALDataset [protected]
bShared (defined in GDALDataset) GDALDataset [protected]
BuildOverviews(const char *, int, int *, int, int *, GDALProgressFunc, void *) GDALDataset
 
CreateMaskBand(int nFlags) (defined in GDALDataset) GDALDataset [virtual]
Dereference() GDALDataset
 
eAccess (defined in GDALDataset) GDALDataset [protected]
FlushCache(void) GDALDataset [virtual]
GDALDataset(void) (defined in GDALDataset) GDALDataset [protected]
GDALDefaultOverviews (defined in GDALDataset) GDALDataset [friend]
GDALDriver (defined in GDALDataset) GDALDataset [friend]
GDALMajorObject() (defined in GDALMajorObject) GDALMajorObject
 
GDALOpen(const char *, GDALAccess) GDALDataset [friend]
GDALOpenShared(const char *, GDALAccess) GDALDataset [friend]
GDALRasterBand (defined in GDALDataset) GDALDataset [friend]
GetAccess() (defined in GDALDataset) GDALDataset [inline]
GetDescription() const GDALMajorObject [virtual]
GetDriver(void) GDALDataset [virtual]
GetFileList(void) GDALDataset [virtual]
GetGCPCount() GDALDataset [virtual]
GetGCPProjection() GDALDataset [virtual]
GetGCPs() GDALDataset [virtual]
GetGeoTransform(double *) GDALDataset [virtual]
GetInternalHandle(const char *) GDALDataset [virtual]
GetMetadata(const char *pszDomain="") GDALMajorObject [virtual]
GetMetadataItem(const char *pszName, const char *pszDomain="") GDALMajorObject [virtual]
GetMOFlags() (defined in GDALMajorObject) GDALMajorObject
 
GetOpenDatasets(int *pnDatasetCount) GDALDataset [static]
GetProjectionRef(void) GDALDataset [virtual]
GetRasterBand(int) GDALDataset
 
GetRasterCount(void) GDALDataset
 
GetRasterXSize(void) GDALDataset
 
GetRasterYSize(void) GDALDataset
 
GetShared() GDALDataset
 
IBuildOverviews(const char *, int, int *, int, int *, GDALProgressFunc, void *) (defined in GDALDataset) GDALDataset [protected, virtual]
IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int *, int, int, int) (defined in GDALDataset) GDALDataset [protected, virtual]
MarkAsShared() GDALDataset
 
nBands (defined in GDALDataset) GDALDataset [protected]
nFlags (defined in GDALMajorObject) GDALMajorObject [protected]
nRasterXSize (defined in GDALDataset) GDALDataset [protected]
nRasterYSize (defined in GDALDataset) GDALDataset [protected]
nRefCount (defined in GDALDataset) GDALDataset [protected]
oMDMD (defined in GDALMajorObject) GDALMajorObject [protected]
oOvManager (defined in GDALDataset) GDALDataset [protected]
papoBands (defined in GDALDataset) GDALDataset [protected]
poDriver (defined in GDALDataset) GDALDataset [protected]
RasterInitialize(int, int) (defined in GDALDataset) GDALDataset [protected]
RasterIO(GDALRWFlag, int, int, int, int, void *, int, int, GDALDataType, int, int *, int, int, int) GDALDataset
 
Reference() GDALDataset
 
sDescription (defined in GDALMajorObject) GDALMajorObject [protected]
SetBand(int, GDALRasterBand *) (defined in GDALDataset) GDALDataset [protected]
SetDescription(const char *) GDALMajorObject [virtual]
SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, const char *pszGCPProjection) GDALDataset [virtual]
SetGeoTransform(double *) GDALDataset [virtual]
SetMetadata(char **papszMetadata, const char *pszDomain="") GDALMajorObject [virtual]
SetMetadataItem(const char *pszName, const char *pszValue, const char *pszDomain="") GDALMajorObject [virtual]
SetMOFlags(int nFlags) (defined in GDALMajorObject) GDALMajorObject
 
SetProjection(const char *) GDALDataset [virtual]
~GDALDataset() GDALDataset [virtual]
~GDALMajorObject() (defined in GDALMajorObject) GDALMajorObject [virtual]

 
  • 相关文章:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新评论及回复

最近发表

Powered By Z-Blog 1.8 Devo Build 80201  Theme By Bokezhuti.cn

ICP备案号正在申请。Copyright ©2009 gis足迹. All Rights Reserved.