增加了栅格坐标系转换工具

pull/4/head
陈增辉 2025-02-20 16:46:54 +08:00
parent 15aac6e236
commit 368e240c4d
9 changed files with 358 additions and 4 deletions

View File

@ -3566,4 +3566,64 @@ void MergeTiffs(QList<QString> inputFiles, QString outputFile) {
GDALClose(poDstDS);
GDALClose(poFirstDS);
}
}
bool ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode)
{
GDALAllRegister(); // 注册所有GDAL驱动
// 打开输入栅格
GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inRasterPath.toUtf8().constData(), GA_ReadOnly);
if (!poSrcDS) return false;
// 创建目标坐标系
OGRSpatialReference oTargetSRS;
oTargetSRS.importFromEPSG(outepsgcode);
char* pszTargetSRS = nullptr;
oTargetSRS.exportToWkt(&pszTargetSRS);
// 设置Warp选项
GDALWarpOptions* psWarpOptions = GDALCreateWarpOptions();
psWarpOptions->hSrcDS = poSrcDS;
psWarpOptions->hDstDS = nullptr;
psWarpOptions->nBandCount = poSrcDS->GetRasterCount();
psWarpOptions->panSrcBands = (int*)CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);
psWarpOptions->panDstBands = (int*)CPLMalloc(sizeof(int) * psWarpOptions->nBandCount);
for (int i = 0; i < psWarpOptions->nBandCount; ++i) {
psWarpOptions->panSrcBands[i] = i + 1;
psWarpOptions->panDstBands[i] = i + 1;
}
// 设置坐标转换参数
psWarpOptions->papszWarpOptions = CSLSetNameValue(nullptr, "INIT_DEST", "NO_DATA");
psWarpOptions->dfWarpMemoryLimit = 8000; // 内存限制8000MB
// 创建坐标转换器
psWarpOptions->pTransformerArg =
GDALCreateGenImgProjTransformer(poSrcDS, nullptr, nullptr, pszTargetSRS,
FALSE, 0, 1);
psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
// 创建输出文件
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset* poDstDS = poDriver->Create(
outRasterPath.toUtf8().constData(),
0, 0, 0, GDT_Unknown, nullptr);
// 执行坐标转换
GDALWarpOperation oOperation;
oOperation.Initialize(psWarpOptions);
oOperation.ChunkAndWarpImage(0, 0,
poSrcDS->GetRasterXSize(),
poSrcDS->GetRasterYSize());
// 清理资源
GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
GDALDestroyWarpOptions(psWarpOptions);
CPLFree(pszTargetSRS);
GDALClose(poSrcDS);
GDALClose(poDstDS);
return true;
}

View File

@ -269,8 +269,8 @@ int BASECONSTVARIABLEAPI saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString o
void BASECONSTVARIABLEAPI clipRaster(QString inRasterPath, QString outRasterPath, long minRow, long maxRow, long minCol, long maxCol);
// 坐标系转换
bool BASECONSTVARIABLEAPI ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode);
//--------------------- 图像合并流程 ------------------------------
enum MERGEMODE

View File

@ -9,7 +9,7 @@
#include "ToolBoxWidget.h"
#include "QDEMResampleDialog.h"
#include "DEMLLA2XYZTool.h"
#include "QConvertCoordinateSystemDialog.h"
GF3ImportDataToolButton::GF3ImportDataToolButton(QWidget* parent) :QToolAbstract(parent)
@ -144,3 +144,20 @@ void QDEMLLA2XYZToolToolButton::excute()
DEMLLA2XYZTool* dialog = new DEMLLA2XYZTool();
dialog->show();
}
QConvertCoordinateSystemToolButton::QConvertCoordinateSystemToolButton(QWidget* parent)
{
this->toolPath = QVector<QString>(0);
this->toolPath.push_back(u8"基础处理");
this->toolname = QString(u8"栅格坐标系转换");
}
QConvertCoordinateSystemToolButton::~QConvertCoordinateSystemToolButton()
{
}
void QConvertCoordinateSystemToolButton::excute()
{
QConvertCoordinateSystemDialog* dialog = new QConvertCoordinateSystemDialog();
dialog->show();
}

View File

@ -85,5 +85,15 @@ public slots:
};
class BASETOOLBOX_EXPORT QConvertCoordinateSystemToolButton : public QToolAbstract {
Q_OBJECT
public:
QConvertCoordinateSystemToolButton(QWidget* parent = nullptr);
~QConvertCoordinateSystemToolButton();
public slots:
virtual void excute() override;
};
extern "C" BASETOOLBOX_EXPORT void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox);

View File

@ -112,6 +112,7 @@
<ClCompile Include="BaseToolbox\GF3PSTNClass.cpp" />
<ClCompile Include="BaseToolbox\QClipRasterByRowCols.cpp" />
<ClCompile Include="BaseToolbox\QComplex2AmpPhase.cpp" />
<ClCompile Include="BaseToolbox\QConvertCoordinateSystemDialog.cpp" />
<ClCompile Include="BaseToolbox\QDEMResampleDialog.cpp" />
<ClCompile Include="BaseToolbox\QImportGF3StripL1ADataset.cpp" />
<ClCompile Include="BaseToolbox\QMergeRasterProcessDialog.cpp" />
@ -131,6 +132,7 @@
<QtMoc Include="BaseToolbox\QRDOrthProcessClass.h" />
<QtMoc Include="BaseToolbox\QMergeRasterProcessDialog.h" />
<QtMoc Include="BaseToolbox\QDEMResampleDialog.h" />
<QtMoc Include="BaseToolbox\QConvertCoordinateSystemDialog.h" />
<ClInclude Include="BaseToolbox\SatelliteGF3xmlParser.h" />
<ClInclude Include="BaseToolbox\SateOrbit.h" />
<ClInclude Include="BaseToolbox\simptsn.h" />
@ -143,6 +145,7 @@
<QtUic Include="BaseToolbox\DEMLLA2XYZTool.ui" />
<QtUic Include="BaseToolbox\QClipRasterByRowCols.ui" />
<QtUic Include="BaseToolbox\QComplex2AmpPhase.ui" />
<QtUic Include="BaseToolbox\QConvertCoordinateSystemDialog.ui" />
<QtUic Include="BaseToolbox\QDEMResampleDialog.ui" />
<QtUic Include="BaseToolbox\QImportGF3StripL1ADataset.ui" />
<QtUic Include="BaseToolbox\QMergeRasterProcessDialog.ui" />

View File

@ -94,6 +94,9 @@
<ClCompile Include="BaseToolbox\QDEMResampleDialog.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="BaseToolbox\QConvertCoordinateSystemDialog.cpp">
<Filter>BaseToolbox</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<QtMoc Include="BaseToolbox\DEMLLA2XYZTool.h">
@ -123,6 +126,9 @@
<QtMoc Include="BaseToolbox\QDEMResampleDialog.h">
<Filter>Header Files</Filter>
</QtMoc>
<QtMoc Include="BaseToolbox\QConvertCoordinateSystemDialog.h">
<Filter>BaseToolbox</Filter>
</QtMoc>
</ItemGroup>
<ItemGroup>
<QtUic Include="BaseToolbox\DEMLLA2XYZTool.ui">
@ -149,5 +155,8 @@
<QtUic Include="BaseToolbox\QDEMResampleDialog.ui">
<Filter>Form Files</Filter>
</QtUic>
<QtUic Include="BaseToolbox\QConvertCoordinateSystemDialog.ui">
<Filter>BaseToolbox</Filter>
</QtUic>
</ItemGroup>
</Project>

View File

@ -0,0 +1,83 @@
#include "QConvertCoordinateSystemDialog.h"
#include "ui_QConvertCoordinateSystemDialog.h"
#include <QFileDialog>
#include <QMessageBox>
#include "ImageOperatorBase.h"
QConvertCoordinateSystemDialog::QConvertCoordinateSystemDialog(QWidget *parent)
: QDialog(parent),ui(new Ui::QConvertCoordinateSystemDialogClass)
{
ui->setupUi(this);
connect(ui->dialogBtn, SIGNAL(accepted()), this, SLOT(onaccepted()));
connect(ui->dialogBtn, SIGNAL(rejected()), this, SLOT(onrejected()));
connect(ui->btnSelectInRaster, SIGNAL(clicked(bool)), this, SLOT(onbtnSelectInRasterClicked(bool)));
connect(ui->btnSelectOutRaster, SIGNAL(clicked(bool)), this, SLOT(onbtnSelectOutRasterClicked(bool)));
}
QConvertCoordinateSystemDialog::~QConvertCoordinateSystemDialog()
{}
void QConvertCoordinateSystemDialog::onaccepted()
{
QString espgcodestr = this->ui->lineEditEPSGCoder->text().trimmed();
bool espgcodeflag = false;
long espgcodeInt = -1;
espgcodeInt=espgcodestr.toInt(&espgcodeflag);
if (!espgcodeflag) {
QMessageBox::warning(this, u8"warning", u8"错误的ESPG代码");
return;
}
else {}
QString inrasterpath = this->ui->lineEditInRaster->text();
QString outrasterpath = this->ui->lineEditOutRaster->text();
ConvertCoordinateSystem(inrasterpath, outrasterpath, espgcodeInt);
QMessageBox::information(this, tr(u8"info"), tr(u8"completed!!!!"));
}
void QConvertCoordinateSystemDialog::onrejected()
{
this->close();
}
void QConvertCoordinateSystemDialog::onbtnSelectInRasterClicked(bool flag)
{
QString fileName = QFileDialog::getOpenFileName(
this, // 父窗口
tr(u8"选择影像文件"), // 标题
QString(), // 默认路径
tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // 文件过滤器
);
// 如果用户选择了文件
if (!fileName.isEmpty()) {
this->ui->lineEditInRaster->setText(fileName);
}
else {
QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
}
}
void QConvertCoordinateSystemDialog::onbtnSelectOutRasterClicked(bool flag)
{
QString fileName = QFileDialog::getSaveFileName(
this, // 父窗口
tr(u8"选择影像文件"), // 标题
QString(), // 默认路径
tr(u8"tif Files (*.tif);;data Files (*.data);;bin Files (*.bin);;All Files (*)") // 文件过滤器
);
// 如果用户选择了文件
if (!fileName.isEmpty()) {
this->ui->lineEditOutRaster->setText(fileName);
}
else {
QMessageBox::information(this, tr(u8"没有选择文件"), tr(u8"没有选择任何文件。"));
}
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <QDialog>
namespace Ui {
class QConvertCoordinateSystemDialogClass;
}
class QConvertCoordinateSystemDialog : public QDialog
{
Q_OBJECT
public:
QConvertCoordinateSystemDialog(QWidget *parent = nullptr);
~QConvertCoordinateSystemDialog();
private:
Ui::QConvertCoordinateSystemDialogClass* ui;
public slots:
void onaccepted();
void onrejected();
void onbtnSelectInRasterClicked(bool flag);
void onbtnSelectOutRasterClicked(bool flag);
};

View File

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QConvertCoordinateSystemDialogClass</class>
<widget class="QDialog" name="QConvertCoordinateSystemDialogClass">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>187</height>
</rect>
</property>
<property name="windowTitle">
<string>栅格坐标系转换</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QPushButton" name="btnSelectInRaster">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>选择</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="lineEditEPSGCoder">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>4326</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditOutRaster">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="btnSelectOutRaster">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>选择</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditInRaster">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>输入影像:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>输出:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="SloperLabel">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>EPSG Code:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>27</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="dialogBtn">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>