gdal库的学习和使用

1、windows下的编译

  1.1、解压后打开nmake.opt,设置GDAL_HOME

  1.2、进入vs的command promot,进入正常的那个即可,64位的没试过,可以参考gdal官网

  1.3、nmake /f makefile.vc

  1.4、nmake /f makefile.vc install

  1.5、nmake /f makefile.vc devinstall

2、编译proj 

  #PROJ_FLAGS =-DPROJ_STATIC

  #PROJ_INCLUDE =-Id:\projects\proj.4\src

  #PROJ_LIBRARY =d:\projects\proj.4\src\proj_i.lib

  修改为:

  #PROJ_FLAGS =-DPROJ_STATIC

  PROJ_INCLUDE =-IF:\Work\3rdPart\proj-4.7.0\src

  PROJ_LIBRARY =F:\Work\3rdPart\proj-4.7.0\src\proj_i.lib

  具体参见http://blog.csdn.net/liminlu0314/article/details/6937194

  最上面的PROJ_FLAGS的作用经试验表明是这样子:

  如果取消注释,那么运行的时候会主动提示确实proj.dll;如果加上注释,那么会输出Unable to load PROJ.4 library (proj.dll) (太假了)

2、打开文件

#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()

int main()
{
    GDALDataset  *poDataset;

    GDALAllRegister();

    poDataset = (GDALDataset *) GDALOpen( pszFilename, GA_ReadOnly );
    if( poDataset == NULL )
    {
        ...;
    }

gdal中文路径的问题

不改变GDAL源代码,在自己调用GDALRegisterAll()和OGRAllRegiser()函数后,加上下面一句即可。
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");
3、获取数据集合信息
    adfGeoTransform[0] /* top left x */
    adfGeoTransform[1] /* w-e pixel resolution */
    adfGeoTransform[2] /* 0 */
    adfGeoTransform[3] /* top left y */
    adfGeoTransform[4] /* 0 */
    adfGeoTransform[5] /* n-s pixel resolution (negative value) */
    double        adfGeoTransform[6];

    printf( "Driver: %s/%s\n",
            poDataset->GetDriver()->GetDescription(), 
            poDataset->GetDriver()->GetMetadataItem( GDAL_DMD_LONGNAME ) );

    printf( "Size is %dx%dx%d\n", 
            poDataset->GetRasterXSize(), poDataset->GetRasterYSize(),
            poDataset->GetRasterCount() );

    if( poDataset->GetProjectionRef()  != NULL )
        printf( "Projection is `%s'\n", poDataset->GetProjectionRef() );

    if( poDataset->GetGeoTransform( adfGeoTransform ) == CE_None )
    {
        printf( "Origin = (%.6f,%.6f)\n",
                adfGeoTransform[0], adfGeoTransform[3] );

        printf( "Pixel Size = (%.6f,%.6f)\n",
                adfGeoTransform[1], adfGeoTransform[5] );
    }

 

posted @ 2014-05-18 15:25  summerwinterwang  阅读(3934)  评论(0编辑  收藏  举报