(源代码)Qt GDAL C++ 遥感图像显示 处理

  • l6_526710
    了解作者
  • 1.8MB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-05-13 09:49
    上传日期
曾经的程序源代码,运行环境:Qt5.12,GDAL2.3.1,纯C++编写
ourgis.zip
  • ourgis
  • gdalvector.ui
    4.6KB
  • processwidget.h
    918B
  • mainwindow.ui
    10.1KB
  • histogram.h
    640B
  • 天空.png
    1.4MB
  • shp2raster.cpp
    1.7KB
  • load-button.png
    19KB
  • graphicsitem.h
    612B
  • sharpening.h
    597B
  • graphicsscene.cpp
    3.7KB
  • graphicsview.cpp
    6.4KB
  • processsform.h
    1.4KB
  • infortable.h
    305B
  • newline.h
    665B
  • cprocessbase.cpp
    234B
  • line.png
    14.5KB
  • shp2raster.ui
    3.9KB
  • lutstretch.cpp
    6.5KB
  • backjpg.qrc
    299B
  • smoothform.ui
    2.6KB
  • gdalvector.h
    1.4KB
  • mainwindow.cpp
    18.4KB
  • 减号.png
    7.4KB
  • cprocessbase.h
    1.9KB
  • processwidget.cpp
    1.7KB
  • resampling.cpp
    8.5KB
  • saveshp.h
    923B
  • graphicsitem.cpp
    1.1KB
  • gdal_priv.h
    55.8KB
  • save.png
    26.6KB
  • sharpening.ui
    3KB
  • main.cpp
    183B
  • processsform.cpp
    2.6KB
  • raster2shp.cpp
    5.3KB
  • sharpening.cpp
    16.9KB
  • gdalvector.cpp
    8.8KB
  • graphicsscene.h
    1.2KB
  • smoothform.cpp
    5.9KB
  • openimag.png
    81.9KB
  • infortable.cpp
    1.3KB
  • 加号.png
    12.5KB
  • lutstretch.ui
    2.6KB
  • ourgis.pro
    3.9KB
  • infortable.ui
    562B
  • saveshp.cpp
    2.5KB
  • polygon.png
    23.1KB
  • graphicsview.h
    925B
  • shp2raster.h
    560B
  • histogram.ui
    2.6KB
  • drag.png
    144.3KB
  • lutstretch.h
    641B
  • histogram.cpp
    6.2KB
  • mainwindow.h
    2.5KB
  • ourgis.pro.user
    23.4KB
  • smoothform.h
    607B
  • raster2shp.ui
    4.1KB
  • raster2shp.h
    822B
  • resampling.ui
    8.3KB
  • resampling.h
    1.5KB
  • newline.cpp
    1.3KB
内容介绍
#include "mainwindow.h" #include "ui_mainwindow.h" #include <string> QStandardItemModel *MainWindow::table = new QStandardItemModel; int MainWindow::wid = 0; int MainWindow::hei = 0; MainWindow *MainWindow::mainui = nullptr; bool MainWindow::isdrag = false; bool MainWindow::isdraw = false; bool MainWindow::isline = false; bool MainWindow::ispolygen = false; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); mainui = this; ui->tabWidget->setTabEnabled(2,false); this->image = new QImage(); graphicsview = new graphicsVIEW(this); graphicsview->move(285,65); scale = 1; wid = width() - 285; hei = height() - 130; connect(ui->action,SIGNAL(clicked()),this,SLOT(fullScreen())); connect(ui->action_O,SIGNAL(clicked()),this,SLOT(aboutopenimage())); connect(ui->information,SIGNAL(clicked()),this,SLOT(informa())); connect(ui->action_2,SIGNAL(clicked()),this,SLOT(drawlinemode())); connect(ui->actionExit,SIGNAL(clicked()),this,SLOT(exit())); connect(ui->actionDrag,SIGNAL(clicked()),this,SLOT(dragmode())); connect(ui->actionDrag,SIGNAL(clicked()),graphicsview,SLOT(dragmode())); connect(ui->actionsave,SIGNAL(triggered()),graphicsview,SLOT(mid())); connect(ui->actionline,SIGNAL(triggered()),this,SLOT(drawlinemode())); connect(ui->actionpolygen,SIGNAL(triggered()),this,SLOT(drawlinemode())); connect(ui->action_3,SIGNAL(triggered()),this,SLOT(savefile())); connect(ui->action_4,SIGNAL(clicked()),this,SLOT(raster2shp())); connect(ui->action_5,SIGNAL(clicked()),this,SLOT(smooth())); connect(ui->actionsharp,SIGNAL(clicked()),this,SLOT(sharping())); connect(ui->action_6,SIGNAL(clicked()),this,SLOT(histogramanalys())); connect(ui->action_7,SIGNAL(clicked()),this,SLOT(Lutstretch())); connect(ui->action_8,SIGNAL(clicked()),this,SLOT(resample())); //table view 表格设置 // this->table = new QStandardItemModel(); this->tree = new QStandardItemModel(); table->setColumnCount(2); table->setHeaderData(0,Qt::Horizontal,QString::fromLocal8Bit("Information")); table->setHeaderData(1,Qt::Horizontal,QString::fromLocal8Bit("Data")); connect(tree,&QStandardItemModel::itemChanged,this,&MainWindow::checkchanged); connect(tree,&QStandardItemModel::itemChanged,this,&MainWindow::onlyband); ui->statusBar->showMessage(tr("欢迎访问Qt开源社区!")); } void MainWindow::fullScreen() { if (isfullscreen == false) { this->showFullScreen(); isfullscreen = true; } else { if (isfullscreen == true) { this->showNormal(); isfullscreen = false; } } } void MainWindow::paintshp() { if (isfullscreen == false) { this->showFullScreen(); isfullscreen = true; } // gdalvector *gdalVector = new gdalvector; // gdalVector->show(); } void MainWindow::aboutopenimage() { if(only != 0) { if(fileName != nullptr && poDataset != nullptr) { GDALClose(poDataset); } } fileName = QFileDialog::getOpenFileName( this, "open image file", "C:\\Users\\lll\\Desktop", "Image files (*.bmp *.jpg *.pbm *.pgm *.png *.ppm *.xbm *.xpm *.tif);;All files (*.*)"); if(fileName == nullptr) { return; } else { readimg(fileName); } } void MainWindow::readimg(const QString imgPath) { GDALAllRegister(); //用GDAL显示图像 CPLSetConfigOption("GDAL_FIILENAME_IS_UTF8","NO"); poDataset = (GDALDataset*)GDALOpen(imgPath.toStdString().c_str(), GA_ReadOnly); //如果图像文件并非三个波段,则默认只显示第一波段灰度图像 if (poDataset->GetRasterCount() != 3) { m_showColor = false; ShowBand(poDataset->GetRasterBand(1)); } else { m_showColor = true; QList<GDALRasterBand*> bandList; bandList.append(poDataset->GetRasterBand(1)); bandList.append(poDataset->GetRasterBand(2)); bandList.append(poDataset->GetRasterBand(3)); openimage(&bandList); } } void MainWindow::ShowBand(GDALRasterBand *band) { //显示单波段图像 if (band == nullptr) { return; } QList<GDALRasterBand*> myBand; myBand.append(band); myBand.append(band); myBand.append(band); openimage(&myBand); } void MainWindow::openimage(QList<GDALRasterBand *>* imgband) { if (imgband->size() != 3) { return; } int imgWidth = imgband->at(0)->GetXSize(); int imgHeight = imgband->at(0)->GetYSize(); scale = this->height() * 2.8/imgHeight; int iscalewidth = (int)(imgWidth *scale - 1); int iscaleheight = (int)(imgHeight *scale -1); GDALDataType dataType = imgband->at(0)->GetRasterDataType(); //首先分别读取RGB三个波段 float *rband = new float[iscalewidth * iscaleheight]; float *gband = new float[iscalewidth * iscaleheight]; float *bband = new float[iscalewidth * iscaleheight]; unsigned char *rbandUC, *gbandUC, *bbandUC; //根据是否显示彩色图像,判断RGB三个波段的组成方式,并分别读取 if ( m_showColor == true ) { imgband->at( 0 )->RasterIO(GF_Read, 0, 0, imgWidth, imgHeight, rband , iscalewidth, iscaleheight,GDT_Float32, 0, 0 ); imgband->at( 1 )->RasterIO(GF_Read, 0, 0, imgWidth, imgHeight, gband, iscalewidth, iscaleheight,GDT_Float32, 0, 0 ); imgband->at( 2 )->RasterIO(GF_Read, 0, 0, imgWidth, imgHeight, bband, iscalewidth, iscaleheight,GDT_Float32, 0, 0 ); // 分别拉伸每个波段并将Float转换为unsigned char rbandUC = imgsketch( rband,imgband->at( 0 ), iscalewidth * iscaleheight, imgband->at( 0)->GetNoDataValue() ); gbandUC = imgsketch( gband,imgband->at( 1 ), iscalewidth * iscaleheight, imgband->at( 1)->GetNoDataValue() ); bbandUC = imgsketch( bband,imgband->at( 2 ), iscalewidth * iscaleheight, imgband->at( 2)->GetNoDataValue() ); } else { imgband->at( 0 )->RasterIO(GF_Read, 0, 0, imgWidth, imgHeight, rband , iscalewidth, iscaleheight,GDT_Float32, 0, 0 ); rbandUC = imgsketch( rband,imgband->at( 0 ), iscalewidth * iscaleheight, imgband->at( 0)->GetNoDataValue() ); gbandUC = rbandUC; bbandUC = rbandUC; } // 将三个波段组合起来 int bytePerLine = ( iscalewidth * 24 + 31 )/ 8; unsigned char* allBandUC = new unsigned char[bytePerLine * iscaleheight * 3]; for( int h = 0; h < iscaleheight; h++ ) { for( int w = 0; w < iscalewidth; w++) { allBandUC[h * bytePerLine + w * 3 +0] = rbandUC[h * iscalewidth + w]; allBandUC[h * bytePerLine + w * 3 +1] = gbandUC[h * iscalewidth + w]; allBandUC[h * bytePerLine + w * 3 +2] = bbandUC[h * iscalewidth + w]; } } //获取图像仿射变换参数 double adf[6]; poDataset->GetGeoTransform(adf); memcpy(graphicsItem::adftrans,adf,sizeof(adf)); // 构造图像并显示 graphicsview->Openimages(QImage(allBandUC, iscalewidth, iscaleheight, bytePerLine,QImage::Format_RGB888)); graphicsview->show(); // 输出图像的格式信息 table->setItem(0,1,new QStandardItem(poDataset->GetDriver()->GetDescription())); table->setItem(1,1,new QStandardItem(poDataset->GetDriver()->GetMetadataItem(GDAL_DMD_LONGNAME))); //输出图像的大小和波段数 table->setItem(2,1,new QStandardItem(GDALGetDataTypeName((poDataset->GetRaster
评论
    相关推荐
    • C++ Primer
      C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。 对C++基本概念和技术全面而且权威的阐述,对...
    • c++课件
      c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件c++课件
    • C++ PRrimer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • C++
      C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++
    • C++ primer
      本文档具有C++ primer 以及 C++ primer 标准答案各一份,内容清晰充实!希望与热爱C++的学友们一起同舟共济,努力学习!
    • C++ primer
      本书是久负盛名的C++经典教程,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++。本版对前一版进行了彻底的...
    • c++yuyanbiancheng
      这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!这是C和C++集成的编程环境!
    • effective C++
      有关C++编程方面的检验性介绍,对由C转向C++,和有C++编程基础的程序员有帮助,不过是英文版
    • C++ Primer
      这本处适合各个阶段的C++程序员,这本书可以帮助初学者快速入门,里面有最实用,最容易理解的代码;同时这也是有经验的C++程序员最好的一本参考手册
    • C++ Primer
      本书是久负盛名的C++经典教程引,其内容是C++大师Stanley B. Lippman丰富的实践经验和C++标准委员会原负责人Josée Lajoie对C++标准深入理解的完美结合,已经帮助全球无数程序员学会了C++