修复合并影像bug
parent
7f29679055
commit
15aac6e236
|
@ -141,9 +141,6 @@
|
|||
<ProjectReference Include="..\ImageshowTool\ImageshowTool.vcxproj">
|
||||
<Project>{8c8ca066-a93a-4098-9a46-b855efeaadf2}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\LAMPDataProcessEXE\LAMPDataProcessEXE.vcxproj">
|
||||
<Project>{4e6e79a3-048c-4fb4-bbb0-43c518a3e6d4}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\RasterProcessToolWidget\RasterProcessTool.vcxproj">
|
||||
<Project>{7ef67daa-dbc0-4b7f-80e8-11b4d2cb7ec2}</Project>
|
||||
</ProjectReference>
|
||||
|
|
|
@ -2156,8 +2156,6 @@ void clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long m
|
|||
|
||||
ErrorCode MergeRasterProcess(QVector<QString> filepaths, QString outfileptah, QString mainString, MERGEMODE mergecode, bool isENVI, ShowProessAbstract* dia )
|
||||
{
|
||||
|
||||
|
||||
// 参数检查
|
||||
if (!isExists(mainString)) {
|
||||
qDebug() << QString::fromStdString(errorCode2errInfo(ErrorCode::FILENOFOUND) )<< "\t" << mainString;
|
||||
|
@ -2873,7 +2871,14 @@ long GetEPSGFromRasterFile(QString filepath)
|
|||
|
||||
std::cout << pszProjection << std::endl;
|
||||
|
||||
long epsgCode = atoi(oSRS.GetAuthorityCode(nullptr)); // 获取EPSG代码
|
||||
const char* epscodestr = oSRS.GetAuthorityCode(nullptr);
|
||||
if (NULL == epscodestr || nullptr == epscodestr) {
|
||||
qDebug() << "EPSG code string could not be determined from the spatial reference.";
|
||||
GDALClose(poDataset);
|
||||
|
||||
return -1;
|
||||
}
|
||||
long epsgCode = atoi(epscodestr); // 获取EPSG代码
|
||||
|
||||
if (epsgCode != 0) {
|
||||
GDALClose(poDataset);
|
||||
|
@ -3439,3 +3444,126 @@ void testOutAntPatternTrans(QString antpatternfilename, double* antPatternArr,
|
|||
}
|
||||
|
||||
|
||||
void MergeTiffs(QList<QString> inputFiles, QString outputFile) {
|
||||
GDALAllRegister();
|
||||
|
||||
if (inputFiles.isEmpty()) {
|
||||
fprintf(stderr, "No input files provided.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Open the first file to determine the data type and coordinate system
|
||||
GDALDataset* poFirstDS = (GDALDataset*)GDALOpen(inputFiles.first().toUtf8().constData(), GA_ReadOnly);
|
||||
if (poFirstDS == nullptr) {
|
||||
fprintf(stderr, "Failed to open the first file %s\n", inputFiles.first().toUtf8().constData());
|
||||
return;
|
||||
}
|
||||
|
||||
double adfGeoTransform[6];
|
||||
CPLErr eErr = poFirstDS->GetGeoTransform(adfGeoTransform);
|
||||
if (eErr != CE_None) {
|
||||
fprintf(stderr, "Failed to get GeoTransform for the first file %s\n", inputFiles.first().toUtf8().constData());
|
||||
GDALClose(poFirstDS);
|
||||
return;
|
||||
}
|
||||
|
||||
int nXSize = 0;
|
||||
int nYSize = 0;
|
||||
double minX = std::numeric_limits<double>::max();
|
||||
double minY = std::numeric_limits<double>::max();
|
||||
double maxX = std::numeric_limits<double>::lowest();
|
||||
double maxY = std::numeric_limits<double>::lowest();
|
||||
double pixelWidth = adfGeoTransform[1];
|
||||
double pixelHeight = adfGeoTransform[5];
|
||||
|
||||
// Determine the bounding box and size of the output raster
|
||||
for (const QString& inputFile : inputFiles) {
|
||||
GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile.toUtf8().constData(), GA_ReadOnly);
|
||||
if (poSrcDS == nullptr) {
|
||||
fprintf(stderr, "Failed to open %s\n", inputFile.toUtf8().constData());
|
||||
continue;
|
||||
}
|
||||
|
||||
double adfThisTransform[6];
|
||||
eErr = poSrcDS->GetGeoTransform(adfThisTransform);
|
||||
if (eErr != CE_None) {
|
||||
fprintf(stderr, "Failed to get GeoTransform for %s\n", inputFile.toUtf8().constData());
|
||||
GDALClose(poSrcDS);
|
||||
continue;
|
||||
}
|
||||
|
||||
minX = std::min(minX, adfThisTransform[0]);
|
||||
minY = std::min(minY, adfThisTransform[3] + adfThisTransform[5] * poSrcDS->GetRasterYSize());
|
||||
maxX = std::max(maxX, adfThisTransform[0] + adfThisTransform[1] * poSrcDS->GetRasterXSize());
|
||||
maxY = std::max(maxY, adfThisTransform[3]);
|
||||
|
||||
GDALClose(poSrcDS);
|
||||
}
|
||||
|
||||
nXSize = static_cast<int>(std::ceil((maxX - minX) / pixelWidth));
|
||||
nYSize = static_cast<int>(std::ceil((maxY - minY) / (-pixelHeight)));
|
||||
|
||||
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
|
||||
if (poDriver == nullptr) {
|
||||
fprintf(stderr, "GTiff driver not available.\n");
|
||||
GDALClose(poFirstDS);
|
||||
return;
|
||||
}
|
||||
|
||||
char** papszOptions = nullptr;
|
||||
GDALDataset* poDstDS = poDriver->Create(outputFile.toUtf8().constData(), nXSize, nYSize, 1, poFirstDS->GetRasterBand(1)->GetRasterDataType(), papszOptions);
|
||||
if (poDstDS == nullptr) {
|
||||
fprintf(stderr, "Creation of output file failed.\n");
|
||||
GDALClose(poFirstDS);
|
||||
return;
|
||||
}
|
||||
|
||||
poDstDS->SetGeoTransform(adfGeoTransform);
|
||||
|
||||
const OGRSpatialReference* oSRS = poFirstDS->GetSpatialRef( );
|
||||
poDstDS->SetSpatialRef(oSRS);
|
||||
|
||||
float fillValue = std::numeric_limits<float>::quiet_NaN();
|
||||
void* pafScanline = CPLMalloc(GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * nXSize);
|
||||
memset(pafScanline, 0, GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * nXSize);
|
||||
|
||||
// Initialize all pixels to NaN
|
||||
for (int iY = 0; iY < nYSize; ++iY) {
|
||||
GDALRasterBand* poBand = poDstDS->GetRasterBand(1);
|
||||
poBand->RasterIO(GF_Write, 0, iY, nXSize, 1, pafScanline, nXSize, 1, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0);
|
||||
}
|
||||
|
||||
CPLFree(pafScanline);
|
||||
|
||||
// Read each source image and write into the destination image
|
||||
for (const QString& inputFile : inputFiles) {
|
||||
GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile.toUtf8().constData(), GA_ReadOnly);
|
||||
if (poSrcDS == nullptr) {
|
||||
fprintf(stderr, "Failed to open %s\n", inputFile.toUtf8().constData());
|
||||
continue;
|
||||
}
|
||||
|
||||
double adfThisTransform[6];
|
||||
poSrcDS->GetGeoTransform(adfThisTransform);
|
||||
|
||||
int srcXSize = poSrcDS->GetRasterXSize();
|
||||
int srcYSize = poSrcDS->GetRasterYSize();
|
||||
|
||||
int dstXOffset = static_cast<int>(std::round((adfThisTransform[0] - minX) / pixelWidth));
|
||||
int dstYOffset = static_cast<int>(std::round((maxY - adfThisTransform[3]) / (-pixelHeight)));
|
||||
|
||||
GDALRasterBand* poSrcBand = poSrcDS->GetRasterBand(1);
|
||||
GDALRasterBand* poDstBand = poDstDS->GetRasterBand(1);
|
||||
|
||||
void* pafBuffer = CPLMalloc(GDALGetDataTypeSizeBytes(poFirstDS->GetRasterBand(1)->GetRasterDataType()) * srcXSize * srcYSize);
|
||||
poSrcBand->RasterIO(GF_Read, 0, 0, srcXSize, srcYSize, pafBuffer, srcXSize, srcYSize, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0);
|
||||
|
||||
poDstBand->RasterIO(GF_Write, dstXOffset, dstYOffset, srcXSize, srcYSize, pafBuffer, srcXSize, srcYSize, poFirstDS->GetRasterBand(1)->GetRasterDataType(), 0, 0);
|
||||
|
||||
CPLFree(pafBuffer);
|
||||
GDALClose(poSrcDS);
|
||||
}
|
||||
|
||||
GDALClose(poDstDS);
|
||||
GDALClose(poFirstDS);
|
||||
}
|
|
@ -26,6 +26,7 @@
|
|||
#include <cpl_conv.h> // for CPLMalloc()
|
||||
#include "LogInfoCls.h"
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
|
||||
enum ProjectStripDelta {
|
||||
Strip_6, // 6度带
|
||||
|
@ -277,7 +278,8 @@ enum MERGEMODE
|
|||
MERGE_GEOCODING,
|
||||
};
|
||||
|
||||
|
||||
void BASECONSTVARIABLEAPI MergeTiffs(QList<QString> inputFiles, QString outputFile);
|
||||
|
||||
ErrorCode BASECONSTVARIABLEAPI MergeRasterProcess(QVector<QString> filepath, QString outfileptah, QString mainString, MERGEMODE mergecode = MERGEMODE::MERGE_GEOCODING, bool isENVI = false, ShowProessAbstract* dia = nullptr);
|
||||
|
||||
|
||||
|
|
|
@ -109,6 +109,9 @@
|
|||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ALLRelease\ALLRelease.vcxproj">
|
||||
<Project>{8a71d19d-9ac6-42e9-81ec-9e82af8075b8}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\BaseCommonLibrary\BaseCommonLibrary.vcxproj">
|
||||
<Project>{872ecd6f-30e3-4a1b-b17c-15e87d373ff6}</Project>
|
||||
</ProjectReference>
|
||||
|
|
|
@ -51,124 +51,6 @@
|
|||
<item>
|
||||
<layout class="QGridLayout" name="infoLayout"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="mapCanvasLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QGroupBox" name="layersListGbx">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="downloadGbx">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>650</y>
|
||||
<width>171</width>
|
||||
<height>221</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>下载区域</string>
|
||||
</property>
|
||||
<widget class="QLineEdit" name="leftTopText">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>40</y>
|
||||
<width>151</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="leftTopBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>80</y>
|
||||
<width>151</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>点击开始选择左上角点</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>选择左上角</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="rightBottomText">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>12</x>
|
||||
<y>140</y>
|
||||
<width>151</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="rightBottomBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<width>151</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>点击开始选择右下角点</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>选择右下角</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="taskTab">
|
||||
|
@ -351,6 +233,141 @@ p, li { white-space: pre-wrap; }
|
|||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockWidget_2">
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>2</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="layersListGbx">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string/>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="downloadGbx">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>650</y>
|
||||
<width>171</width>
|
||||
<height>221</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>下载区域</string>
|
||||
</property>
|
||||
<widget class="QLineEdit" name="leftTopText">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>40</y>
|
||||
<width>151</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="leftTopBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>80</y>
|
||||
<width>151</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>点击开始选择左上角点</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>选择左上角</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="rightBottomText">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>12</x>
|
||||
<y>140</y>
|
||||
<width>151</width>
|
||||
<height>31</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="rightBottomBtn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>180</y>
|
||||
<width>151</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>点击开始选择右下角点</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>选择右下角</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QDockWidget" name="dockWidget_3">
|
||||
<attribute name="dockWidgetArea">
|
||||
<number>1</number>
|
||||
</attribute>
|
||||
<widget class="QWidget" name="dockWidgetContents_4">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="mapCanvasLayout"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<action name="tutorialAction">
|
||||
<property name="text">
|
||||
<string>使用教程</string>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
|
||||
QMergeRasterProcessDialog::QMergeRasterProcessDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
: QDialog(parent),ui(new Ui::QMergeRasterProcessDialogClass)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
|
@ -75,16 +75,18 @@ void QMergeRasterProcessDialog::acceptclick()
|
|||
{
|
||||
QToolProcessBarDialog* processdialog = new QToolProcessBarDialog(this);
|
||||
|
||||
QVector<QString> infile(ui->listWidgetRaster->count());
|
||||
QList<QString> infile;// (ui->listWidgetRaster->count());
|
||||
QString outstring = ui->lineEditOutPath->text();
|
||||
for (long i = 0; i < ui->listWidgetRaster->count(); i++) {
|
||||
infile[i] = ui->listWidgetRaster->item(i)->text();
|
||||
infile.append(ui->listWidgetRaster->item(i)->text());
|
||||
}
|
||||
processdialog->show();
|
||||
processdialog->showProcess(0.0,u8"ºÏ²¢Ó°Ïñ");
|
||||
|
||||
MergeRasterProcess(infile, outstring, infile[0], MERGEMODE::MERGE_GEOCODING, false, processdialog);
|
||||
|
||||
MergeTiffs(infile, outstring);
|
||||
//MergeRasterProcess(infile, outstring, infile[0], MERGEMODE::MERGE_GEOCODING, false, processdialog);
|
||||
processdialog->close();
|
||||
QMessageBox::information(this, u8"info", u8"completed!!!");
|
||||
}
|
||||
|
||||
void QMergeRasterProcessDialog::rejectclick()
|
||||
|
|
|
@ -156,6 +156,9 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditOutPath_2">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
|
@ -169,6 +172,9 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonSelect_2">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
|
@ -201,6 +207,9 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEditOutPath_3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
|
@ -214,6 +223,9 @@
|
|||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButtonSelect_3">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
|
|
Loading…
Reference in New Issue