欢迎您来到GIS动力

加入收藏 免费注册 用户登陆 帮助中心
首页 新闻动态 技术专栏 银杏树下 学习考研 软件下载 求职招聘 许愿瓶 节日祝福 用户中心 精彩推荐 资源搜索 地图
专栏导航: AO开发 | SO开发 | ArcGIS桌面 | 超图桌面 | 开发语言 | 数据库 | WebGIS | 银杏文学 | 研究生考题 | FreeMap FreeTalk
   您现在位于: 首页技术专栏地理信息技术 → 正文
测试GDAL用法的一些函数
07-10-16 09:06:22 作者:flyingfish 出处:flyingfish
1  /*
  2  =========================================================================================
  3                      以下是一些测试GDAL用法的函数
  4  =========================================================================================
  5  */
  6 
  7  // 描述:测试某类型是否支持CreateCopy和Create
  8  // 参数:pszFormat-驱动格式,比如“GTIFF”
  9  // 输出:结果打印到命令行
 10  void  ISCanCreate( const   char   * pszFormat)
 11  {
 12       // determine if a particular format supports Create or CreateCopy it is possible to check the 
 13       // DCAP_CREATE and DCAP_CREATECOPY metadata on the format driver object.
 14 
 15      GDALDriver  * poDriver;
 16       char   ** papszMetadata;
 17      GDALAllRegister();
 18      poDriver  =  GetGDALDriverManager() -> GetDriverByName(pszFormat);
 19 
 20       if ( poDriver  ==  NULL )
 21          exit(  1  );
 22 
 23       char  message[ 100 ];
 24      papszMetadata  =  poDriver -> GetMetadata();
 25       if ( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE ) )
 26          sprintf(message,  " Driver %s supports Create() method.\n " , pszFormat );
 27       if ( CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATECOPY, FALSE ) )
 28          sprintf(message,  " Driver %s supports CreateCopy() method.\n " , pszFormat );
 29 
 30      AfxMessageBox(message);
 31  }
 32 
 33  // 描述:测试读取到DataSet并输出图像的基本信息
 34  // 参数:pszFilename-文件名称
 35  // 输出:信息打印到命令行
 36  bool  OpenFileToDataSet( char *  pszFilename)
 37  {    
 38      GDALDataset   * poDataset;
 39 
 40      poDataset  =  (GDALDataset  * ) GDALOpen( pszFilename, GA_ReadOnly );
 41       if ( poDataset  !=  NULL )
 42      {
 43           double   adfGeoTransform[ 6 ];
 44           char  message[ 100 ];
 45          
 46          sprintf(message,  " Driver: %s/%s\n " ,
 47                  poDataset -> GetDriver() -> GetDescription(), 
 48                  poDataset -> GetDriver() -> GetMetadataItem( GDAL_DMD_LONGNAME ) );
 49 
 50          sprintf(message,  " Size is %dx%dx%d\n "
 51                  poDataset -> GetRasterXSize(), poDataset -> GetRasterYSize(),
 52                  poDataset -> GetRasterCount() );
 53 
 54           if ( poDataset -> GetProjectionRef()   !=  NULL )
 55              sprintf(message,  " Projection is `%s'\n " , poDataset -> GetProjectionRef());
 56 
 57           if ( poDataset -> GetGeoTransform( adfGeoTransform )  ==  CE_None )
 58          {
 59              sprintf(message,  " Origin = (%.6f,%.6f)\n " ,
 60                      adfGeoTransform[ 0 ], adfGeoTransform[ 3 ] );
 61 
 62              sprintf(message,  " Pixel Size = (%.6f,%.6f)\n " ,
 63                      adfGeoTransform[ 1 ], adfGeoTransform[ 5 ] );
 64          }
 65          
 66          AfxMessageBox(message);
 67           return   true ;
 68      } else
 69           return   false ;
 70  }
 71 
 72  // 描述:测试读取一个BAND并输出基本信息
 73  // 参数:poDataset-数据集
 74  // 输出:信息打印到命令行
 75  void  ReadBandInf(GDALDataset *  poDataset)
 76  {
 77      GDALRasterBand   * poBand;
 78       int              nBlockXSize, nBlockYSize;
 79       int              bGotMin, bGotMax;
 80       double           adfMinMax[ 2 ];
 81       char  message[ 100 ];
 82      
 83       poBand  =  poDataset -> GetRasterBand(  1  );
 84      poBand -> GetBlockSize(  & nBlockXSize,  & nBlockYSize );
 85      sprintf(message,   " Block=%dx%d Type=%s, ColorInterp=%s\n " ,
 86              nBlockXSize, nBlockYSize,
 87              GDALGetDataTypeName(poBand -> GetRasterDataType()),
 88              GDALGetColorInterpretationName(
 89                  poBand -> GetColorInterpretation()) );
 90 
 91      adfMinMax[ 0 =  poBand -> GetMinimum(  & bGotMin );
 92      adfMinMax[ 1 =  poBand -> GetMaximum(  & bGotMax );
 93       if !  (bGotMin  &&  bGotMax) )
 94          GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
 95&n
9 7 3 1 2 4 8 :

(本文已被浏览 次)
发布人:admin
推荐给好友:发送给好友
上篇新闻:
下篇新闻:
相关评论
发表我的评论
  • 尊重网上道德,遵守《全国人大常委会关于维护互联网安全的决定》及中华人民共和国其他各项有关法律法;
  • 本站有权保留或删除您发表的任何评论内容;
  •   相关文章  

    关于我们友情链接 ┋ 与我在线 ┋ 管理 ┋ TOP
     
    网站当前版本:GisPower CMS V3.0
    『GIS 动力』- http://www.gispower.org/
    联系我们:webmaster#gispower.org
    Copyright (c) 2003-2007 GisPOwer.Org. All Rights Reserved.
     

                   滇ICP备05006901号