Qt + gdal读取geotiff头文件

Qt + gdal 读取geotiff头文件

.pro文件增加:

INCLUDEPATH += E:/opencv/build/include
CONFIG(debug, debug|release):{
LIBS += -LE:/opencv/build/x86/vc10/lib \
-lopencv_core2411d \
-lopencv_imgproc2411d \
-lopencv_highgui2411d \
-lopencv_ml2411d \
-lopencv_video2411d \
-lopencv_features2d2411d \
-lopencv_calib3d2411d \
-lopencv_objdetect2411d \
-lopencv_contrib2411d \
-lopencv_legacy2411d \
-lopencv_flann2411d
}
else:CONFIG(release, debug|release): {
LIBS += -LE:/opencv/build/x86/vc10/lib \
-lopencv_core2411 \
-lopencv_imgproc2411 \
-lopencv_highgui2411 \
-lopencv_ml2411 \
-lopencv_video2411 \
-lopencv_features2d2411 \
-lopencv_calib3d2411 \
-lopencv_objdetect2411 \
-lopencv_contrib2411 \
-lopencv_legacy2411 \
-lopencv_flann2411
}


win32: LIBS += -LE:/GDAL/lib/ -lgdal_i
INCLUDEPATH +=E:/GDAL/include
DEPENDPATH +=E:/GDAL/include

代码

#pragma execution_cha
racter_set("utf-8")
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "gdal_priv.h"
#include 
#include < QTextCodec >
#include < QFile >

using namespace std;

void main(int argc, char *argv[])
{
    GDALAllRegister();
    CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
    GDALDataset *pData=NULL;
    QString filename = "H:/SAR_1_8.tif";
    QFile ff(filename);
    if(!ff.exists())
    {
        qDebug()<<"原始数据文件读取失败";
//        QMessageBox::information(NULL, "Information", "原始数据头文件读取失败", QMessageBox::Yes, QMessageBox::Yes);
        return  ;

    }
    else{
         qDebug()<<"原始数据文件读取ok";
    }

    filename.replace("/","\\");
    //QByteArray ba =filename.toLatin1(); // must
    QByteArray ba = filename.toLocal8Bit();
    char* ch=ba.data();
    pData=(GDALDataset*)GDALOpen(ch,GA_ReadOnly);
    if(pData==NULL)
    {
        qDebug()<<"原始数据头文件读取失败";
//        QMessageBox::information(NULL, "Information", "原始数据读取失败", QMessageBox::Yes, QMessageBox::Yes);
        return ;
    }
    else{
          qDebug()<<"原始数据头文件读取ok";
    }

    int nBand=pData->GetRasterCount();//波段数
    qDebug()<<"nBand"<GetRasterXSize();
    qDebug()<<"行数"<GetRasterYSize();
    double adfGeoTransform[6];
    pData->GetGeoTransform( adfGeoTransform);

    qDebug()<<"5"<< adfGeoTransform[5];
    qDebug()<<"1"<< adfGeoTransform[1];
    qDebug()<<"3"<< adfGeoTransform[3];
    
    return  ;
}

你可能感兴趣的:(图像处理)