Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef3f64410d | |||
| 57d01cc7fb |
@@ -1,378 +0,0 @@
|
|||||||
#include "LandslideAssess.h"
|
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
LandslideAssess::LandslideAssess()
|
|
||||||
{
|
|
||||||
//ui.setupUi(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LandslideAssess::PannelName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("地质模块");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LandslideAssess::CategoryName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("地质模块");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LandslideAssess::EnglishName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("LandslideAssess");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LandslideAssess::ChineseName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("结果评估");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LandslideAssess::Information()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("结果评估");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString LandslideAssess::IconPath()
|
|
||||||
{
|
|
||||||
return QString(":/LandslideAssess/resources/assessment.svg");
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget* LandslideAssess::CenterWidget()
|
|
||||||
{
|
|
||||||
QString gdal_path = qApp->applicationDirPath().toLocal8Bit() + "/share/gdal";
|
|
||||||
QString pro_lib_path = qApp->applicationDirPath().toLocal8Bit() + "/share/proj";
|
|
||||||
qputenv("GDAL_DATA", gdal_path.toLocal8Bit());
|
|
||||||
qputenv("PROJ_LIB", pro_lib_path.toLocal8Bit());
|
|
||||||
|
|
||||||
bool showWin = false;
|
|
||||||
if (myWidget == nullptr)
|
|
||||||
{
|
|
||||||
myWidget = new QDialog();
|
|
||||||
showWin = true;
|
|
||||||
qDebug() << "new QDialog()";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug() << "already have myWidget";
|
|
||||||
//激活窗口并提升至顶层
|
|
||||||
myWidget->activateWindow();
|
|
||||||
myWidget->raise();
|
|
||||||
return myWidget;
|
|
||||||
}
|
|
||||||
ui.setupUi(myWidget);
|
|
||||||
|
|
||||||
myWidget->setWindowTitle(QString::fromLocal8Bit("结果评估"));
|
|
||||||
myWidget->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
|
|
||||||
myWidget->setWindowIcon(QIcon(":/LandslideAssess/resources/assessment.svg"));
|
|
||||||
myWidget->setAttribute(Qt::WA_QuitOnClose, false);
|
|
||||||
|
|
||||||
myWidget->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
connect(myWidget, &QDialog::destroyed, this, [=] {
|
|
||||||
qDebug() << "----Landslide assess window close----";
|
|
||||||
|
|
||||||
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
||||||
if (pluginsDir.cd("srsplugins\\SldModel"))
|
|
||||||
{
|
|
||||||
QString strConfigPath = pluginsDir.absoluteFilePath("sld_config.ini");
|
|
||||||
QFile f(strConfigPath);
|
|
||||||
if (f.exists())
|
|
||||||
{
|
|
||||||
WriteConfigPaths(strConfigPath);
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mWorkThread != nullptr)
|
|
||||||
{
|
|
||||||
mWorkThread->requestInterruption();//请求线程中断
|
|
||||||
mWorkThread->quit();
|
|
||||||
mWorkThread->wait();//调用wait后先调用finished信号对应的槽函数,执行完成后再往下走
|
|
||||||
mWorker->on_cancel();
|
|
||||||
mWorkThread = nullptr;//mWorkThread, &QThread::finished, mWorkThread, &QObject::deleteLater,不需要delete
|
|
||||||
mWorker = nullptr;//mWorkThread, &QThread::finished, mWorker, &QObject::deleteLater
|
|
||||||
}
|
|
||||||
//qDebug() << "--destroyed";
|
|
||||||
myWidget->close();
|
|
||||||
myWidget = nullptr;
|
|
||||||
});
|
|
||||||
connect(ui.pbtInDataset, &QPushButton::clicked, this, &LandslideAssess::choosePredictPath);
|
|
||||||
connect(ui.pbtInLabel, &QPushButton::clicked, this, &LandslideAssess::chooseLabelPath);
|
|
||||||
connect(ui.pbtIndex, &QPushButton::clicked, this, &LandslideAssess::chooseAssessFile);
|
|
||||||
connect(ui.pbtInModel, &QPushButton::clicked, this, &LandslideAssess::chooseModelFile);
|
|
||||||
connect(ui.pbtResult, &QPushButton::clicked, this, &LandslideAssess::chooseResultPath);
|
|
||||||
|
|
||||||
connect(ui.pushButton_ok, &QPushButton::clicked, this, &LandslideAssess::readAndStart);
|
|
||||||
connect(ui.pushButton_cancel, &QPushButton::clicked, this, &LandslideAssess::pbCancel);
|
|
||||||
|
|
||||||
ui.progressBar->setTextVisible(true);
|
|
||||||
ui.progressBar->setRange(0, 100);
|
|
||||||
|
|
||||||
ui.pbtInModel->setFocus();
|
|
||||||
|
|
||||||
QFile qssFile(":/LandslideAssess/LandslideAssess.qss");
|
|
||||||
qssFile.open(QFile::ReadOnly); //以只读方式打开
|
|
||||||
if (qssFile.isOpen())
|
|
||||||
{
|
|
||||||
QString qss = QLatin1String(qssFile.readAll());
|
|
||||||
myWidget->setStyleSheet(qss);
|
|
||||||
qssFile.close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
qDebug() << "no qssFile";
|
|
||||||
|
|
||||||
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
||||||
if (pluginsDir.cd("srsplugins\\SldModel"))
|
|
||||||
{
|
|
||||||
QString strConfigPath = pluginsDir.absoluteFilePath("sld_config.ini");
|
|
||||||
QFile f(strConfigPath);
|
|
||||||
if (f.exists())
|
|
||||||
{
|
|
||||||
ReadConfigHistoryPaths(strConfigPath);
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showWin)
|
|
||||||
myWidget->show();
|
|
||||||
|
|
||||||
return myWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::startWorkThread()
|
|
||||||
{
|
|
||||||
if (mWorker != nullptr)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mWorkThread = new QThread();
|
|
||||||
mWorker = new WorkObject();
|
|
||||||
mWorker->moveToThread(mWorkThread);
|
|
||||||
connect(mWorkThread, &QThread::finished, mWorkThread, &QObject::deleteLater);
|
|
||||||
connect(mWorkThread, &QThread::finished, mWorker, &QObject::deleteLater);
|
|
||||||
connect(mWorker, &WorkObject::progress, myWidget, [=](int value) {
|
|
||||||
ui.progressBar->setValue(value);
|
|
||||||
if (value == 100)
|
|
||||||
{
|
|
||||||
QString txtDir = ui.lineResult->text() + "/assessment.txt";
|
|
||||||
QFile file(txtDir);
|
|
||||||
QString outLines = "";
|
|
||||||
if (file.open(QIODevice::ReadOnly))
|
|
||||||
{
|
|
||||||
QTextStream stream(&file);
|
|
||||||
// recall 召回率
|
|
||||||
// precision 精确率
|
|
||||||
// mIoU 平均交并比
|
|
||||||
// mAP 平均精度均值
|
|
||||||
// f1_score
|
|
||||||
while (!stream.atEnd())
|
|
||||||
{
|
|
||||||
QString line = stream.readLine();
|
|
||||||
//strs.push_back(line);
|
|
||||||
if (line.contains("===>mIoU"))
|
|
||||||
{
|
|
||||||
//===>mIoU:68.45; mAP: 74.92
|
|
||||||
line.remove("===>");
|
|
||||||
line.replace(QStringLiteral("mAP"), QStringLiteral("平均精度均值mAP"));
|
|
||||||
line.replace(QStringLiteral("mIoU"), QStringLiteral("平均交并比mIoU"));
|
|
||||||
outLines = outLines + line + "\n";
|
|
||||||
}
|
|
||||||
else if (line.contains("===>recall"))
|
|
||||||
{
|
|
||||||
//===>recall:66.62; precision: 51.2
|
|
||||||
line.remove("===>");
|
|
||||||
line.replace(QStringLiteral("recall"), QStringLiteral("召回率recall"));
|
|
||||||
line.replace(QStringLiteral("precision"), QStringLiteral("精确率precision"));
|
|
||||||
outLines = outLines + line + "\n";
|
|
||||||
}
|
|
||||||
else if (line.contains("===>f1_score"))
|
|
||||||
{
|
|
||||||
//===>f1_score:57.9
|
|
||||||
line.remove("===>");
|
|
||||||
line.replace(QStringLiteral("f1_score"), QStringLiteral("F1分数f1_score"));
|
|
||||||
outLines = outLines + line;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
QMessageBox mess(QMessageBox::Information,
|
|
||||||
QString::fromLocal8Bit("评估结束"),
|
|
||||||
QString::fromLocal8Bit("评价结果:\n") + txtDir + "\n"
|
|
||||||
+ outLines);
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
mess.setStandardButtons(QMessageBox::Yes);
|
|
||||||
mess.button(QMessageBox::StandardButton::Yes)->setText(QString::fromLocal8Bit("确认"));
|
|
||||||
int result = mess.exec();
|
|
||||||
pbCancel();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connect(this, &LandslideAssess::startPreAssessment, mWorker, &WorkObject::runAssessWork);
|
|
||||||
|
|
||||||
mWorkThread->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::ReadConfigHistoryPaths(QString strPath)
|
|
||||||
{
|
|
||||||
QSettings configIni(strPath, QSettings::IniFormat);
|
|
||||||
|
|
||||||
//打开标题为:[DemTrain] 的组,读取DemTrain输出结果TrainResult字段
|
|
||||||
configIni.beginGroup("SldTrain");
|
|
||||||
|
|
||||||
QString strDemTrainResult = configIni.value("TrainResult").toString();
|
|
||||||
QDir srcDir = QDir(strDemTrainResult);
|
|
||||||
//更新评价文件列表
|
|
||||||
if (srcDir.absoluteFilePath("val_list.txt") != "")
|
|
||||||
ui.lineIndex->setText(srcDir.absoluteFilePath("val_list.txt"));
|
|
||||||
//更新输入Images
|
|
||||||
srcDir = QDir(strDemTrainResult);
|
|
||||||
if (srcDir.cd("Images"))
|
|
||||||
ui.lineInDataset->setText(srcDir.absolutePath());
|
|
||||||
//更新输入Labels
|
|
||||||
srcDir = QDir(strDemTrainResult);
|
|
||||||
if (srcDir.cd("Labels"))
|
|
||||||
ui.lineInLabel->setText(srcDir.absolutePath());
|
|
||||||
|
|
||||||
configIni.endGroup();//关闭组
|
|
||||||
|
|
||||||
//打开标题为:[DemAssess] 的组,读取AssessResult字段
|
|
||||||
configIni.beginGroup("SldAssess");
|
|
||||||
//更新评价结果输出
|
|
||||||
ui.lineResult->setText(configIni.value("AssessResult").toString());
|
|
||||||
|
|
||||||
configIni.endGroup();//关闭组
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::WriteConfigPaths(QString strPath)
|
|
||||||
{
|
|
||||||
QSettings configIni(strPath, QSettings::IniFormat);
|
|
||||||
configIni.setIniCodec("utf-8");
|
|
||||||
//打开标题为:[DemAssess] 的组
|
|
||||||
configIni.beginGroup("SldAssess");
|
|
||||||
|
|
||||||
//更新输入模型路径
|
|
||||||
QString temp = ui.lineResult->text();
|
|
||||||
if (temp != "")
|
|
||||||
configIni.setValue("AssessResult", temp);
|
|
||||||
|
|
||||||
configIni.endGroup();//关闭组
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::readAndStart()
|
|
||||||
{
|
|
||||||
QString dirModel = ui.lineInModel->text();
|
|
||||||
QString dirIndex = ui.lineIndex->text();
|
|
||||||
QString dirLabel = ui.lineInLabel->text();
|
|
||||||
QString dirPredict = ui.lineInDataset->text();
|
|
||||||
QString dirResult = ui.lineResult->text();
|
|
||||||
|
|
||||||
ui.progressBar->setValue(0);
|
|
||||||
|
|
||||||
if (dirLabel == "" || dirPredict == "" || dirIndex == "" || dirModel == "" || dirResult == "")
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请检查输入路径"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mWorkThread == nullptr)
|
|
||||||
{
|
|
||||||
qDebug() << "--startThread";
|
|
||||||
startWorkThread();
|
|
||||||
}
|
|
||||||
emit startPreAssessment(dirModel, dirPredict, dirLabel, dirIndex, dirResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::pbCancel()
|
|
||||||
{
|
|
||||||
qDebug() << "--pbtCancel";
|
|
||||||
delete myWidget;//调起&QDialog::destroyed
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::choosePredictPath()
|
|
||||||
{
|
|
||||||
QString dirInDataset = QFileDialog::getExistingDirectory(ui.pbtInDataset, QString::fromLocal8Bit("选择输入评价文件路径"), "");
|
|
||||||
if (dirInDataset != "")
|
|
||||||
ui.lineInDataset->setText(dirInDataset);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::chooseLabelPath()
|
|
||||||
{
|
|
||||||
QString dirDom = QFileDialog::getExistingDirectory(ui.pbtInLabel, QString::fromLocal8Bit("选择输入标签文件路径"), "");
|
|
||||||
if (dirDom != "")
|
|
||||||
ui.lineInLabel->setText(dirDom);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::chooseAssessFile()
|
|
||||||
{
|
|
||||||
QString dirDom = QFileDialog::getOpenFileName(ui.pbtIndex, QString::fromLocal8Bit("选择输入评估文件索引"), "", "*.txt");
|
|
||||||
if (dirDom != "")
|
|
||||||
ui.lineIndex->setText(dirDom);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::chooseModelFile()
|
|
||||||
{
|
|
||||||
QString fileModel = QFileDialog::getOpenFileName(ui.pbtInModel, QString::fromLocal8Bit("选择输入模型文件"), "", "*.pth");
|
|
||||||
if (fileModel != "")
|
|
||||||
ui.lineInModel->setText(fileModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void LandslideAssess::chooseResultPath()
|
|
||||||
{
|
|
||||||
QString dirResult = QFileDialog::getExistingDirectory(ui.pbtResult, QString::fromLocal8Bit("选择评估结果输出路径"), "");
|
|
||||||
if (dirResult != "")
|
|
||||||
ui.lineResult->setText(dirResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkObject::runAssessWork(QString model, QString PRE, QString label, QString index, QString result)
|
|
||||||
{
|
|
||||||
qDebug() << "start work:" << "\npredict: " << PRE << "\nLabel:" << label;
|
|
||||||
QFileInfo file(index);
|
|
||||||
file.absolutePath();
|
|
||||||
assess_txt_path = file.absolutePath() + "/assessment.txt";
|
|
||||||
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
||||||
qDebug() << "----" << pluginsDir.currentPath();
|
|
||||||
if (!pluginsDir.cd("models\\envs"))
|
|
||||||
{
|
|
||||||
qDebug() << "no folder models\\envs";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString exeDirName = pluginsDir.absoluteFilePath("miou_landslide.exe");
|
|
||||||
QString model_dir = " --model_dir " + model;
|
|
||||||
QString img_data_dir = " --img_data_dir " + PRE + "/";
|
|
||||||
QString label_dir = " --label_dir " + label + "/";
|
|
||||||
QString val_list = " --val_list " + index;
|
|
||||||
QString out_result = " --result_file " + result + "/";
|
|
||||||
QString ss = exeDirName + model_dir + img_data_dir + label_dir + val_list + out_result;
|
|
||||||
qDebug() << ss;
|
|
||||||
QProcess* pProces = new QProcess(this);
|
|
||||||
connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(writeAssessTxt()));
|
|
||||||
pProces->start(ss);
|
|
||||||
|
|
||||||
emit progress(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkObject::writeAssessTxt()
|
|
||||||
{
|
|
||||||
mProcess = (QProcess*)sender();
|
|
||||||
QString output = QString::fromLocal8Bit(mProcess->readAllStandardOutput());
|
|
||||||
output.chop(2);
|
|
||||||
if (output.toFloat() != 0)
|
|
||||||
{
|
|
||||||
qDebug() << "process:" << output.toFloat();
|
|
||||||
emit progress(output.toFloat());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
qDebug() << "unsolved exe out:" << output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkObject::on_cancel()
|
|
||||||
{
|
|
||||||
if (mProcess == nullptr)
|
|
||||||
qDebug() << "--mProces null";
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QString KillStr = "taskkill /f /im miou_landslide.exe";
|
|
||||||
mProcess->startDetached(KillStr);
|
|
||||||
qDebug() << "--kill Proces";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<RCC>
|
|
||||||
<qresource prefix="/LandslideAssess">
|
|
||||||
<file>resources/assessment.svg</file>
|
|
||||||
<file>LandslideAssess.qss</file>
|
|
||||||
</qresource>
|
|
||||||
</RCC>
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1652932649746" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2186" width="32" height="32" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style type="text/css">@font-face { font-family: feedback-iconfont; src: url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff2?t=1630033759944") format("woff2"), url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.woff?t=1630033759944") format("woff"), url("//at.alicdn.com/t/font_1031158_u69w8yhxdu.ttf?t=1630033759944") format("truetype"); }
|
|
||||||
</style></defs><path d="M802.3 649c-13.3 0-24 10.7-24 24v163.9c0 17.7-14.4 32.1-32.1 32.1H222.6c-17.7 0-32.1-14.4-32.1-32.1v-656c0-17.7 14.4-32.1 32.1-32.1h523.7c17.7 0 32 14.4 32 32V235c0 13.3 10.7 24 24 24s24-10.7 24-24v-54.2c0-44.1-35.9-80-80-80H222.6c-44.2 0-80.1 35.9-80.1 80.1v656c0 44.2 35.9 80.1 80.1 80.1h523.6c44.2 0 80.1-35.9 80.1-80.1V673c0-13.3-10.7-24-24-24z" fill="#2c2c2c" p-id="2187"></path><path d="M856.6 332.2L827 315.1c-15.2-9.3-31.5-11.1-47-5.2-12.7 4.8-24.3 14.8-33.8 29l-16.4 25.2c-0.8 0.8-1.5 1.7-2.1 2.6-0.7 1-1.2 2.1-1.7 3.2L563 620.5c-8.8 13.2-13.2 29.2-12.6 45.1l-2.2 90.4c-0.1 5.7 5.4 9.7 10.8 7.9l100.8-35.2c15.6-4.6 28.6-14.8 36.8-28.9L866 411.2l0.1-0.1c5.3-9.1 11.7-23.2 12.1-38 0.5-17.5-7.2-32-21.6-40.9z m-50.3 17.1l29.6 17.1c1.4 0.9 2.4 1.7 2.3 5.4-0.1 5-2.6 12-6.7 19.1l-8.5 14.5-50.6-33.3 7.3-11.2c13.1-19.8 22.6-14 26.6-11.6zM662.1 679.5l-0.1 0.1c-3 5.2-8 9-13.8 10.7l-0.5 0.1-51.7 18c-3.2 1.1-6.6-1.3-6.5-4.7l1-38.7v-0.8c-0.4-7.6 1.7-15.4 5.9-21.7l154.2-236.9 52.2 34.3-140.7 239.6zM702.6 256.9c-7.8-7.8-20.5-7.9-28.3-0.1L467.8 462.4l-93.9-98.6c-7-7.4-18.5-8.3-26.6-2.1l-113.1 86.6c-8.8 6.7-10.4 19.3-3.7 28 6.7 8.8 19.3 10.4 28 3.7l98.8-75.7 95.6 100.4c3.7 3.9 8.8 6.1 14.2 6.2h0.3c5.3 0 10.4-2.1 14.1-5.8l221.1-220c7.8-7.7 7.8-20.4 0-28.2zM266.3 647h186.2c11 0 20-9 20-20s-9-20-20-20H266.3c-11 0-20 9-20 20s9 20 20 20zM266.3 775h232.2c11 0 20-9 20-20s-9-20-20-20H266.3c-11 0-20 9-20 20s9 20 20 20z" fill="#2c2c2c" p-id="2188"></path></svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -3,20 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.32630.194
|
VisualStudioVersion = 16.0.32630.194
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LandslideAssess", "LandslideAssess\LandslideAssess.vcxproj", "{AEAE6E5B-D14B-46CB-BF18-3375936B7CD2}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LandslidePredict", "LandslidePredict\LandslidePredict.vcxproj", "{ABE55CAB-C9A0-4D11-AF67-DEFEF07F3DA5}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Release|x64 = Release|x64
|
Release|x64 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{AEAE6E5B-D14B-46CB-BF18-3375936B7CD2}.Release|x64.ActiveCfg = Release|x64
|
{ABE55CAB-C9A0-4D11-AF67-DEFEF07F3DA5}.Release|x64.ActiveCfg = Release|x64
|
||||||
{AEAE6E5B-D14B-46CB-BF18-3375936B7CD2}.Release|x64.Build.0 = Release|x64
|
{ABE55CAB-C9A0-4D11-AF67-DEFEF07F3DA5}.Release|x64.Build.0 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {B31E7462-C1A4-4BA3-97F3-704180A5CDB6}
|
SolutionGuid = {A9D5438D-7ABE-4CBF-BEAE-6F3FE0CBEB3F}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 进度条基类
|
||||||
|
*
|
||||||
|
* 提供进度条基类接口,来反映当前算法的进度值
|
||||||
|
*/
|
||||||
|
//源码:class IMGALG_API CProcessBase
|
||||||
|
class CProcessBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief 构造函数
|
||||||
|
*/
|
||||||
|
CProcessBase()
|
||||||
|
{
|
||||||
|
m_dPosition = 0.0;
|
||||||
|
m_iStepCount = 100;
|
||||||
|
m_iCurStep = 0;
|
||||||
|
m_bIsContinue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 析构函数
|
||||||
|
*/
|
||||||
|
virtual ~CProcessBase() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度信息
|
||||||
|
* @param pszMsg 进度信息
|
||||||
|
*/
|
||||||
|
virtual void SetMessage(const char* pszMsg) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度值
|
||||||
|
* @param dPosition 进度值
|
||||||
|
* @return 返回是否取消的状态,true为不取消,false为取消
|
||||||
|
*/
|
||||||
|
virtual bool SetPosition(double dPosition) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 进度条前进一步,返回true表示继续,false表示取消
|
||||||
|
* @return 返回是否取消的状态,true为不取消,false为取消
|
||||||
|
*/
|
||||||
|
virtual bool StepIt() = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度个数
|
||||||
|
* @param iStepCount 进度个数
|
||||||
|
*/
|
||||||
|
virtual void SetStepCount(int iStepCount)
|
||||||
|
{
|
||||||
|
ReSetProcess();
|
||||||
|
m_iStepCount = iStepCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取进度信息
|
||||||
|
* @return 返回当前进度信息
|
||||||
|
*/
|
||||||
|
string GetMessage()
|
||||||
|
{
|
||||||
|
return m_strMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 获取进度值
|
||||||
|
* @return 返回当前进度值
|
||||||
|
*/
|
||||||
|
double GetPosition()
|
||||||
|
{
|
||||||
|
return m_dPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 重置进度条
|
||||||
|
*/
|
||||||
|
void ReSetProcess()
|
||||||
|
{
|
||||||
|
m_dPosition = 0.0;
|
||||||
|
m_iStepCount = 100;
|
||||||
|
m_iCurStep = 0;
|
||||||
|
m_bIsContinue = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! 进度信息 */
|
||||||
|
string m_strMessage;
|
||||||
|
/*! 进度值 */
|
||||||
|
double m_dPosition;
|
||||||
|
/*! 进度个数 */
|
||||||
|
int m_iStepCount;
|
||||||
|
/*! 进度当前个数 */
|
||||||
|
int m_iCurStep;
|
||||||
|
/*! 是否取消,值为false时表示计算取消 */
|
||||||
|
bool m_bIsContinue;
|
||||||
|
};
|
||||||
@@ -0,0 +1,383 @@
|
|||||||
|
#include "LandslidePredict.h"
|
||||||
|
|
||||||
|
#include <qgsrasterlayer.h>
|
||||||
|
#include <qgsvectorlayer.h>
|
||||||
|
#include <qgsmapcanvas.h>
|
||||||
|
|
||||||
|
LandslidePredict::LandslidePredict()
|
||||||
|
{
|
||||||
|
//ui.setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LandslidePredict::PannelName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("地质模块");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LandslidePredict::CategoryName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("地质模块");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LandslidePredict::EnglishName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("LandslidePredict");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LandslidePredict::ChineseName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("滑坡识别");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LandslidePredict::Information()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("滑坡识别");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString LandslidePredict::IconPath()
|
||||||
|
{
|
||||||
|
return QString(":/LandslidePredict/resources/landslide.svg");
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* LandslidePredict::CenterWidget()
|
||||||
|
{
|
||||||
|
QString gdal_path = qApp->applicationDirPath().toLocal8Bit() + "/share/gdal";
|
||||||
|
QString pro_lib_path = qApp->applicationDirPath().toLocal8Bit() + "/share/proj";
|
||||||
|
qputenv("GDAL_DATA", gdal_path.toLocal8Bit());
|
||||||
|
qputenv("PROJ_LIB", pro_lib_path.toLocal8Bit());
|
||||||
|
|
||||||
|
bool showWin = false;
|
||||||
|
if (myWidget == nullptr)
|
||||||
|
{
|
||||||
|
myWidget = new QDialog();
|
||||||
|
showWin = true;
|
||||||
|
qDebug() << "new QDialog()";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qDebug() << "already have myWidget";
|
||||||
|
//激活窗口并提升至顶层
|
||||||
|
myWidget->activateWindow();
|
||||||
|
myWidget->raise();
|
||||||
|
return myWidget;
|
||||||
|
}
|
||||||
|
ui.setupUi(myWidget);
|
||||||
|
|
||||||
|
myWidget->setWindowTitle(QString::fromLocal8Bit("滑坡识别"));
|
||||||
|
myWidget->setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
|
||||||
|
myWidget->setWindowIcon(QIcon(":/LandslidePredict/resources/landslide.svg"));
|
||||||
|
myWidget->setAttribute(Qt::WA_QuitOnClose, false);
|
||||||
|
|
||||||
|
myWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
|
||||||
|
connect(myWidget, &QDialog::destroyed, this, [=]() {
|
||||||
|
qDebug() << "----Landslide Predict window close----";
|
||||||
|
|
||||||
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (pluginsDir.cd("srsplugins\\SldModel"))
|
||||||
|
{
|
||||||
|
QString strConfigPath = pluginsDir.absoluteFilePath("sld_config.ini");
|
||||||
|
QFile f(strConfigPath);
|
||||||
|
if (f.exists())
|
||||||
|
{
|
||||||
|
WriteConfigPaths(strConfigPath);
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mWorkThread != nullptr)
|
||||||
|
{
|
||||||
|
mWorkThread->requestInterruption();//请求线程中断
|
||||||
|
mWorkThread->quit();
|
||||||
|
mWorkThread->wait();//调用wait后先调用finished信号对应的槽函数,执行完成后再往下走
|
||||||
|
mWorkObject->on_cancel();
|
||||||
|
mWorkThread = nullptr;//mWorkThread, &QThread::finished, mWorkThread, &QObject::deleteLater,不需要delete
|
||||||
|
mWorkObject = nullptr;//mWorkThread, &QThread::finished, mWorker, &QObject::deleteLater
|
||||||
|
}
|
||||||
|
myWidget->close();
|
||||||
|
myWidget = nullptr;
|
||||||
|
qDebug() << "--destroyed";
|
||||||
|
});
|
||||||
|
connect(ui.pbtInModel, &QPushButton::clicked, this, &LandslidePredict::chooseInModel);
|
||||||
|
connect(ui.pbtInDataset, &QPushButton::clicked, this, &LandslidePredict::chooseInDataset);
|
||||||
|
connect(ui.pbtPreResult, &QPushButton::clicked, this, &LandslidePredict::chooseResultPath);
|
||||||
|
|
||||||
|
connect(ui.pushButton_ok, &QPushButton::clicked, this, &LandslidePredict::readAndStart);
|
||||||
|
connect(ui.pushButton_cancel, &QPushButton::clicked, this, &LandslidePredict::pbCancel);
|
||||||
|
|
||||||
|
ui.pbtInModel->setFocus();
|
||||||
|
|
||||||
|
ui.progressBar->setTextVisible(true);
|
||||||
|
ui.progressBar->setRange(0, 100);
|
||||||
|
|
||||||
|
QFile qssFile(":/LandslidePredict/LandslidePredict.qss");
|
||||||
|
qssFile.open(QFile::ReadOnly); //以只读方式打开
|
||||||
|
if (qssFile.isOpen())
|
||||||
|
{
|
||||||
|
QString qss = QLatin1String(qssFile.readAll());
|
||||||
|
myWidget->setStyleSheet(qss);
|
||||||
|
qssFile.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "no qssFile";
|
||||||
|
|
||||||
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (pluginsDir.cd("srsplugins\\SldModel"))
|
||||||
|
{
|
||||||
|
QString strConfigPath = pluginsDir.absoluteFilePath("sld_config.ini");
|
||||||
|
QFile f(strConfigPath);
|
||||||
|
if (f.exists())
|
||||||
|
{
|
||||||
|
ReadConfigHistoryPaths(strConfigPath);
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showWin)
|
||||||
|
myWidget->show();
|
||||||
|
|
||||||
|
return myWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::startWorkThread()
|
||||||
|
{
|
||||||
|
if (mWorkObject != nullptr)
|
||||||
|
return;
|
||||||
|
mWorkThread = new QThread();
|
||||||
|
mWorkObject = new WorkObject();
|
||||||
|
mWorkObject->moveToThread(mWorkThread);
|
||||||
|
connect(mWorkThread, &QThread::finished, mWorkThread, &QObject::deleteLater);
|
||||||
|
connect(mWorkThread, &QThread::finished, mWorkObject, &QObject::deleteLater);
|
||||||
|
connect(mWorkObject, &WorkObject::progress, myWidget, [=](int value) {ui.progressBar->setValue(value); });
|
||||||
|
connect(mWorkObject, &WorkObject::preFinished, this, &LandslidePredict::finished);
|
||||||
|
connect(mWorkObject, &WorkObject::addShpDataToMap, this, &LandslidePredict::openResultData);
|
||||||
|
connect(this, &LandslidePredict::startTiffToShp, mWorkObject, &WorkObject::runFormatConvert);
|
||||||
|
|
||||||
|
connect(this, &LandslidePredict::start, mWorkObject, &WorkObject::runPredictWork);
|
||||||
|
mWorkThread->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::ReadConfigHistoryPaths(QString strPath)
|
||||||
|
{
|
||||||
|
QSettings configIni(strPath, QSettings::IniFormat);
|
||||||
|
|
||||||
|
//打开标题为:[SldPredict] 的组
|
||||||
|
configIni.beginGroup("SldPredict");
|
||||||
|
|
||||||
|
ui.lineInDataset->setText(configIni.value("SrcDom").toString());
|
||||||
|
ui.linePreResult->setText(configIni.value("PredictResult").toString());
|
||||||
|
|
||||||
|
configIni.endGroup();//关闭组
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::WriteConfigPaths(QString strPath)
|
||||||
|
{
|
||||||
|
QSettings configIni(strPath, QSettings::IniFormat);
|
||||||
|
configIni.setIniCodec("utf-8");
|
||||||
|
//打开标题为:[SldPredict] 的组
|
||||||
|
configIni.beginGroup("SldPredict");
|
||||||
|
|
||||||
|
//更新输入DOM路径
|
||||||
|
QString temp = ui.lineInDataset->text();
|
||||||
|
if (temp != "")
|
||||||
|
configIni.setValue("SrcDom", temp);
|
||||||
|
//更新输出结果路径
|
||||||
|
temp = ui.linePreResult->text();
|
||||||
|
if (temp != "")
|
||||||
|
configIni.setValue("PredictResult", temp);
|
||||||
|
|
||||||
|
configIni.endGroup();//关闭组
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::openResultData(QStringList string_list)
|
||||||
|
{
|
||||||
|
if (string_list.isEmpty())
|
||||||
|
return;
|
||||||
|
QgsRasterLayer* rastLayer;
|
||||||
|
QgsVectorLayer* vecLayer;
|
||||||
|
for each (QString layerPath in string_list)
|
||||||
|
{
|
||||||
|
QFileInfo fileInfo(layerPath);
|
||||||
|
QString layerBaseName = fileInfo.baseName(); // 图层名称
|
||||||
|
if ("tif" == fileInfo.suffix() || "tiff" == fileInfo.suffix())
|
||||||
|
{
|
||||||
|
rastLayer = new QgsRasterLayer(fileInfo.filePath(), layerPath, "gdal");
|
||||||
|
if (!rastLayer)
|
||||||
|
return;
|
||||||
|
QgsMapLayer* mapLayer = rastLayer;
|
||||||
|
QgsRectangle myRectangle;
|
||||||
|
rastLayer->setContrastEnhancement(QgsContrastEnhancement::StretchToMinimumMaximum
|
||||||
|
, QgsRasterMinMaxOrigin::StdDev, myRectangle);
|
||||||
|
QList<QgsMapLayer*> mapLayers;
|
||||||
|
mapLayers << mapLayer;
|
||||||
|
QgsProject::instance()->addMapLayers(mapLayers);
|
||||||
|
//zoomToSelectedLayer(mapLayer);
|
||||||
|
}
|
||||||
|
else if ("shp" == fileInfo.suffix())
|
||||||
|
{
|
||||||
|
vecLayer = new QgsVectorLayer(fileInfo.filePath(), layerPath);
|
||||||
|
if (!vecLayer)
|
||||||
|
return;
|
||||||
|
QgsMapLayer* mapLayer = vecLayer;
|
||||||
|
QList<QgsMapLayer*> mapLayers;
|
||||||
|
mapLayers << mapLayer;
|
||||||
|
QgsProject::instance()->addMapLayers(mapLayers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::readAndStart()
|
||||||
|
{
|
||||||
|
QString dirModel = ui.lineInModel->text();
|
||||||
|
QString dirDataset = ui.lineInDataset->text();
|
||||||
|
QString dirPRE = ui.linePreResult->text();
|
||||||
|
|
||||||
|
ui.progressBar->setValue(0);
|
||||||
|
if (dirModel == "" || dirDataset == "" || dirPRE == "")
|
||||||
|
{
|
||||||
|
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请检查输入输出文件或路径"));
|
||||||
|
mess.setWindowFlags(Qt::Drawer);
|
||||||
|
int result = mess.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (mWorkThread == nullptr)
|
||||||
|
{
|
||||||
|
qDebug() << "--startThread";
|
||||||
|
startWorkThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.label_progress->setText(QString::fromLocal8Bit("预测进度:"));
|
||||||
|
emit start(dirModel, dirDataset, dirPRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::pbCancel()
|
||||||
|
{
|
||||||
|
qDebug() << "--pbtCancel";
|
||||||
|
delete myWidget;//调起&QDialog::destroyed
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::chooseInModel()
|
||||||
|
{
|
||||||
|
QString dirModel = QFileDialog::getOpenFileName(ui.pbtInModel, QString::fromLocal8Bit("选择模型文件"), "", "*.pth");
|
||||||
|
if (dirModel != "")
|
||||||
|
ui.lineInModel->setText(dirModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::chooseInDataset()
|
||||||
|
{
|
||||||
|
QString dirInDataset = QFileDialog::getExistingDirectory(ui.pbtInDataset, QString::fromLocal8Bit("选择输入预测数据路径"), "");
|
||||||
|
if (dirInDataset != "")
|
||||||
|
ui.lineInDataset->setText(dirInDataset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LandslidePredict::chooseResultPath()
|
||||||
|
{
|
||||||
|
QString dirPre = QFileDialog::getExistingDirectory(ui.pbtPreResult, QString::fromLocal8Bit("选择预测结果输出文件路径"), "");
|
||||||
|
if (dirPre != "")
|
||||||
|
ui.linePreResult->setText(dirPre);
|
||||||
|
}
|
||||||
|
|
||||||
|
//预测结束,转矢量
|
||||||
|
void LandslidePredict::finished()
|
||||||
|
{
|
||||||
|
QMessageBox mess(QMessageBox::NoIcon,
|
||||||
|
QString::fromLocal8Bit("滑坡识别结束"),
|
||||||
|
QString::fromLocal8Bit("将对如下路径中结果进行转矢量处理:\n") + ui.linePreResult->text(),
|
||||||
|
QMessageBox::Ok, NULL);
|
||||||
|
mess.setWindowFlags(Qt::Drawer);
|
||||||
|
mess.setButtonText(QMessageBox::Ok, QString::fromLocal8Bit("确认"));
|
||||||
|
int result = mess.exec();
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case QMessageBox::Ok:
|
||||||
|
emit startTiffToShp(ui.linePreResult->text(), ui.lineInDataset->text());
|
||||||
|
ui.label_progress->setText(QString::fromLocal8Bit("转矢量进度:"));
|
||||||
|
ui.progressBar->setValue(0);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkObject::runPredictWork(QString inModel, QString inDataset, QString outPre)
|
||||||
|
{
|
||||||
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (!pluginsDir.cd("models\\envs"))
|
||||||
|
{
|
||||||
|
qDebug() << "no folder models\\envs";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString exeDirName = pluginsDir.absoluteFilePath("predict_3c_landslide.exe");
|
||||||
|
|
||||||
|
QString strModel = " --model_path " + inModel;
|
||||||
|
QString strData = " --dom_path " + inDataset + "/";
|
||||||
|
QString strPre = " --pre_path " + outPre + "/";
|
||||||
|
|
||||||
|
QString ss = exeDirName + strModel + strData + strPre;
|
||||||
|
qDebug() << ss;
|
||||||
|
QProcess* pProces = new QProcess(this);
|
||||||
|
connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(on_read()));
|
||||||
|
|
||||||
|
pProces->start(ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkObject::on_read()
|
||||||
|
{
|
||||||
|
mProcess = (QProcess*)sender();
|
||||||
|
QString output = QString::fromLocal8Bit(mProcess->readAllStandardOutput());
|
||||||
|
if (output.toFloat() > 0)
|
||||||
|
{
|
||||||
|
qDebug() << "exe out:" << output.toFloat();
|
||||||
|
emit progress(output.toFloat());
|
||||||
|
if (output.toFloat() == 100)
|
||||||
|
emit preFinished();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "Unresolved exe out:" << output;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkObject::on_cancel()
|
||||||
|
{
|
||||||
|
if (mProcess == nullptr)
|
||||||
|
{
|
||||||
|
qDebug() << "--mProces null";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QString KillStr = "taskkill /f /im predict_3c_landslide.exe";
|
||||||
|
mProcess->startDetached(KillStr);
|
||||||
|
qDebug() << "--kill Proces";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkObject::runFormatConvert(QString pre, QString dataset)
|
||||||
|
{
|
||||||
|
QDir dir(pre);
|
||||||
|
QStringList nameFilters;
|
||||||
|
nameFilters << "*.tif" << "*.tiff";
|
||||||
|
QStringList pre_tiff_files = dir.entryList(nameFilters, QDir::Files | QDir::Readable, QDir::Name);
|
||||||
|
int list_len = pre_tiff_files.size();
|
||||||
|
for (int i = 0; i < list_len; i++)
|
||||||
|
{
|
||||||
|
emit progress(float(i) / float(list_len) * 95);
|
||||||
|
qDebug() << "TiffToShp progress:" << float(i) / float(list_len) * 100;
|
||||||
|
QString file_path = pre + "\\" + pre_tiff_files[i];
|
||||||
|
QString dsm_path = dataset + "\\" + pre_tiff_files[i];
|
||||||
|
string path_preTiff = file_path.toStdString();
|
||||||
|
string pathPureName = path_preTiff.substr(0, path_preTiff.rfind("."));
|
||||||
|
string shp_path = pathPureName + ".shp";
|
||||||
|
//调起栅格转矢量
|
||||||
|
img2shp cc;
|
||||||
|
QtGDALProcessBar* gb = new QtGDALProcessBar();
|
||||||
|
bool returnval = cc.ImagePolygonize(path_preTiff.c_str(), shp_path.c_str(), "ESRI Shapefile", 1, gb, gb);
|
||||||
|
if (returnval == true)
|
||||||
|
{
|
||||||
|
QStringList list;
|
||||||
|
list << dsm_path << QString::fromStdString(shp_path);
|
||||||
|
emit addShpDataToMap(list);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "ImagePolygonize fail";
|
||||||
|
}
|
||||||
|
emit progress(100);
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QtWidgets/QDialog>
|
#include <QtWidgets/QDialog>
|
||||||
#include "ui_LandslideAssess.h"
|
#include "ui_LandslidePredict.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -11,37 +11,45 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QIntValidator>
|
||||||
|
|
||||||
#include "SrsMainPluginInterFace.h"
|
#include "SrsMainPluginInterFace.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "im2shp.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class WorkObject :public QObject
|
class WorkObject :public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public slots:
|
||||||
|
void runPredictWork(QString inModel, QString inDataset, QString outPre);
|
||||||
|
void on_read();
|
||||||
void on_cancel();
|
void on_cancel();
|
||||||
|
void runFormatConvert(QString pre, QString dataset);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void progress(int value);
|
void progress(int value);
|
||||||
|
void preFinished();
|
||||||
public slots:
|
void addShpDataToMap(QStringList list);
|
||||||
void runAssessWork(QString model, QString PRE, QString label, QString index, QString result);
|
|
||||||
void writeAssessTxt();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QProcess* mProcess = nullptr;
|
QProcess* mProcess = nullptr;
|
||||||
QString assess_txt_path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class LandslideAssess : public SrsMainInterface
|
class LandslidePredict : public SrsMainInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_INTERFACES(SrsMainInterface)
|
Q_INTERFACES(SrsMainInterface)
|
||||||
Q_PLUGIN_METADATA(IID MainInterface_iid)
|
Q_PLUGIN_METADATA(IID MainInterface_iid)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LandslideAssess();
|
LandslidePredict();
|
||||||
|
|
||||||
virtual QString PannelName() override;
|
virtual QString PannelName() override;
|
||||||
virtual QString CategoryName() override;
|
virtual QString CategoryName() override;
|
||||||
@@ -59,26 +67,28 @@ public:
|
|||||||
//保存本次打开的路径到json文件
|
//保存本次打开的路径到json文件
|
||||||
void WriteConfigPaths(QString strPath);
|
void WriteConfigPaths(QString strPath);
|
||||||
|
|
||||||
|
void openResultData(QStringList string_list);
|
||||||
signals:
|
|
||||||
void startPreAssessment(QString model, QString prefile, QString label, QString index, QString result);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void readAndStart();
|
void readAndStart();
|
||||||
void pbCancel();
|
void pbCancel();
|
||||||
|
|
||||||
void choosePredictPath();
|
void chooseInModel();
|
||||||
void chooseLabelPath();
|
void chooseInDataset();
|
||||||
void chooseAssessFile();
|
void chooseResultPath();
|
||||||
void chooseModelFile();
|
|
||||||
void chooseResultPath();
|
void finished();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void start(QString inModel, QString inDataset, QString outPre);
|
||||||
|
void startTiffToShp(QString pre, QString dataset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::LandslideAssessClass ui;
|
Ui::LandslidePredictClass ui;
|
||||||
|
|
||||||
QDialog* myWidget = nullptr;
|
QDialog* myWidget = nullptr;
|
||||||
|
|
||||||
WorkObject* mWorker = nullptr;
|
|
||||||
QThread* mWorkThread = nullptr;
|
QThread* mWorkThread = nullptr;
|
||||||
|
WorkObject* mWorkObject = nullptr;
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/LandslidePredict">
|
||||||
|
<file>resources/landslide.svg</file>
|
||||||
|
<file>LandslidePredict.qss</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
@@ -22,7 +22,7 @@ QLabel{
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*----QPushButtonÑùʽ±í*/
|
/*----QPushButtonÑùʽ±í*/
|
||||||
#pushButton_ok, #pushButton_cancel, #pbtInDataset, #pbtInLabel, #pbtInModel, #pbtIndex,#pbtResult{
|
#pushButton_ok, #pushButton_cancel, #pbtInModel, #pbtInDataset , #pbtPreResult{
|
||||||
font-family:'Microsoft YaHei';
|
font-family:'Microsoft YaHei';
|
||||||
font-size:12px;
|
font-size:12px;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
@@ -34,35 +34,35 @@ QLabel{
|
|||||||
#pushButton_ok, #pushButton_cancel{
|
#pushButton_ok, #pushButton_cancel{
|
||||||
min-width:36px;
|
min-width:36px;
|
||||||
}
|
}
|
||||||
#pushButton_ok:hover, #pushButton_cancel:hover, #pbtInDataset:hover, #pbtInLabel:hover, #pbtInModel:hover, #pbtIndex:hover,#pbtResult:hover{
|
#pushButton_ok:hover, #pushButton_cancel:hover, #pbtInModel:hover, #pbtInDataset:hover,#pbtPreResult:hover{
|
||||||
background-color: #ecf5ff;
|
background-color: #ecf5ff;
|
||||||
color: #409eff;
|
color: #409eff;
|
||||||
}
|
}
|
||||||
#pushButton_ok:pressed, #pushButton_cancel:pressed, #pbtInDataset:pressed, #pbtInLabel:pressed, #pbtInModel:pressed, #pbtIndex:pressed,#pbtResult:pressed{
|
#pushButton_ok:pressed, #pushButton_cancel:pressed, #pbtInModel:pressed, #pbtInDataset:pressed,#pbtPreResult:pressed{
|
||||||
border: 1px solid #3a8ee6;
|
border: 1px solid #3a8ee6;
|
||||||
color: #409eff;
|
color: #409eff;
|
||||||
}
|
}
|
||||||
#pushButton_ok:checked, #pushButton_cancel:checked, #pbtInDataset:checked, #pbtInLabel:checked, #pbtInModel:checked, #pbtIndex:checked,#pbtResult:checked{
|
#pushButton_ok:checked, #pushButton_cancel:checked, #pbtInModel:checked, #pbtInDataset:checked,#pbtPreResult:checked{
|
||||||
border: 1px solid #3a8ee6;
|
border: 1px solid #3a8ee6;
|
||||||
color: #409eff;
|
color: #409eff;
|
||||||
}
|
}
|
||||||
#pushButton_ok:focus, #pushButton_cancel:focus, #pbtInDataset:focus, #pbtInLabel:focus, #pbtInModel:focus, #pbtIndex:focus,#pbtResult:focus{
|
#pushButton_ok:focus, #pushButton_cancel:focus, #pbtInModel:focus, #pbtInDataset:focus,#pbtPreResult:focus{
|
||||||
border: 1px solid #3a8ee6;
|
border: 1px solid #3a8ee6;
|
||||||
color: #409eff;
|
color: #409eff;
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----QLineEditÑùʽ*/
|
/*----QLineEditÑùʽ*/
|
||||||
#lineInDataset, #lineInLabel, #lineInModel, #lineIndex, #lineResult{
|
#lineInModel, #lineInDataset, #linePreResult{
|
||||||
border:0px;
|
border:0px;
|
||||||
border-bottom: 1px solid #B3B3B3;
|
border-bottom: 1px solid #B3B3B3;
|
||||||
font-family:'Microsoft YaHei';
|
font-family:'Microsoft YaHei';
|
||||||
font-size:12px;
|
font-size:12px;
|
||||||
background-color:transparent;
|
background-color:transparent;
|
||||||
}
|
}
|
||||||
#lineInDataset:hover, #lineInLabel:hover, #lineInModel:hover, #lineIndex:hover, #lineResult:hover{
|
#lineInModel:hover, #lineInDataset:hover, #linePreResult:hover{
|
||||||
border-bottom: 2px solid #66A3FF;
|
border-bottom: 2px solid #66A3FF;
|
||||||
}
|
}
|
||||||
#lineInDataset:focus, #lineInLabel:focus, #lineInModel:focus, #lineIndex:focus, #lineResult:focus{
|
#lineInModel:focus, #lineInDataset:focus, #linePreResult:focus{
|
||||||
border-bottom: 2px solid #7666FF;
|
border-bottom: 2px solid #7666FF;
|
||||||
}
|
}
|
||||||
@@ -1,199 +1,46 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>LandslideAssessClass</class>
|
<class>LandslidePredictClass</class>
|
||||||
<widget class="QDialog" name="LandslideAssessClass">
|
<widget class="QDialog" name="LandslidePredictClass">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>500</width>
|
<width>460</width>
|
||||||
<height>300</height>
|
<height>270</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>460</width>
|
||||||
|
<height>270</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>460</width>
|
||||||
|
<height>270</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>LandslideAssess</string>
|
<string>LandslidePredict</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="2" column="1">
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<widget class="QProgressBar" name="progressBar">
|
||||||
<item row="0" column="0">
|
<property name="value">
|
||||||
<widget class="QLabel" name="label">
|
<number>0</number>
|
||||||
<property name="sizePolicy">
|
</property>
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
</widget>
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入模型文件路径</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInModel"/>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtInModel">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>选择文件</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入验证文件索引</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineIndex"/>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtIndex">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>选择文件</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入验证文件路径</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInDataset"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtInDataset">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>选择文件夹</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入标签文件路径</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInLabel"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtInLabel">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>选择文件夹</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="0">
|
|
||||||
<widget class="QLabel" name="label_4">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>评估结果输出路径</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineResult"/>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtResult">
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>75</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>选择文件夹</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_progress">
|
||||||
|
<property name="text">
|
||||||
|
<string>进度:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_2">
|
<spacer name="horizontalSpacer_2">
|
||||||
@@ -202,7 +49,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
<width>133</width>
|
<width>40</width>
|
||||||
<height>20</height>
|
<height>20</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
@@ -240,12 +87,114 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="0" column="0" colspan="2">
|
||||||
<widget class="QProgressBar" name="progressBar">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<property name="value">
|
<item row="0" column="0">
|
||||||
<number>0</number>
|
<widget class="QLabel" name="label">
|
||||||
</property>
|
<property name="sizePolicy">
|
||||||
</widget>
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>输入模型文件路径</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QLineEdit" name="lineInModel"/>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="2">
|
||||||
|
<widget class="QPushButton" name="pbtInModel">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>打开文件</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>输入预测数据路径</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="lineInDataset"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<widget class="QPushButton" name="pbtInDataset">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>打开文件夹</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>预测结果文件路径</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="linePreResult"/>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="2">
|
||||||
|
<widget class="QPushButton" name="pbtPreResult">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>75</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>打开文件夹</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@@ -253,19 +202,15 @@
|
|||||||
<tabstops>
|
<tabstops>
|
||||||
<tabstop>lineInModel</tabstop>
|
<tabstop>lineInModel</tabstop>
|
||||||
<tabstop>pbtInModel</tabstop>
|
<tabstop>pbtInModel</tabstop>
|
||||||
<tabstop>lineIndex</tabstop>
|
|
||||||
<tabstop>pbtIndex</tabstop>
|
|
||||||
<tabstop>lineInDataset</tabstop>
|
<tabstop>lineInDataset</tabstop>
|
||||||
<tabstop>pbtInDataset</tabstop>
|
<tabstop>pbtInDataset</tabstop>
|
||||||
<tabstop>lineInLabel</tabstop>
|
<tabstop>linePreResult</tabstop>
|
||||||
<tabstop>pbtInLabel</tabstop>
|
<tabstop>pbtPreResult</tabstop>
|
||||||
<tabstop>lineResult</tabstop>
|
|
||||||
<tabstop>pbtResult</tabstop>
|
|
||||||
<tabstop>pushButton_ok</tabstop>
|
<tabstop>pushButton_ok</tabstop>
|
||||||
<tabstop>pushButton_cancel</tabstop>
|
<tabstop>pushButton_cancel</tabstop>
|
||||||
</tabstops>
|
</tabstops>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="LandslideAssess.qrc"/>
|
<include location="LandslidePredict.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
+20
-10
@@ -7,7 +7,7 @@
|
|||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{AEAE6E5B-D14B-46CB-BF18-3375936B7CD2}</ProjectGuid>
|
<ProjectGuid>{ABE55CAB-C9A0-4D11-AF67-DEFEF07F3DA5}</ProjectGuid>
|
||||||
<Keyword>QtVS_v304</Keyword>
|
<Keyword>QtVS_v304</Keyword>
|
||||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0</WindowsTargetPlatformVersion>
|
||||||
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
||||||
@@ -37,10 +37,15 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<TargetName>landslide2_assess</TargetName>
|
<IncludePath>D:\qgis\osgeo4w\include;D:\qgis\osgeo4w\apps\qgis_build_sdk\include;D:\qgis\osgeo4w\apps\Qt5\include;D:\qgis\osgeo4w\apps\Qt5\include\QtXml;$(IncludePath)</IncludePath>
|
||||||
<IncludePath>D:\qgis\osgeo4w\include;D:\qgis\osgeo4w\apps\Qt5\include;$(IncludePath)</IncludePath>
|
<LibraryPath>D:\qgis\osgeo4w\lib;D:\qgis\osgeo4w\apps\qgis_build_sdk\lib;D:\qgis\osgeo4w\apps\Qt5\lib;$(LibraryPath)</LibraryPath>
|
||||||
<LibraryPath>D:\qgis\osgeo4w\lib;D:\qgis\osgeo4w\apps\Qt5\lib;$(LibraryPath)</LibraryPath>
|
<TargetName>landslide3_pre</TargetName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Link>
|
||||||
|
<AdditionalDependencies>gdal_i.lib;qgis_gui.lib;qgis_analysis.lib;qgis_core.lib;qgis_native.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
|
||||||
@@ -55,20 +60,25 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtRcc Include="LandslideAssess.qrc" />
|
<ClCompile Include="QtGDALProcessBar.cpp" />
|
||||||
<QtUic Include="LandslideAssess.ui" />
|
<QtRcc Include="LandslidePredict.qrc" />
|
||||||
<QtMoc Include="LandslideAssess.h" />
|
<QtUic Include="LandslidePredict.ui" />
|
||||||
<ClCompile Include="LandslideAssess.cpp" />
|
<QtMoc Include="LandslidePredict.h" />
|
||||||
|
<ClCompile Include="im2shp.cpp" />
|
||||||
|
<ClCompile Include="LandslidePredict.cpp" />
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="SrsMainPluginInterFace.h" />
|
<QtMoc Include="SrsMainPluginInterFace.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="x64\Release\uic\ui_LandslideAssess.h" />
|
<ClInclude Include="CProcessBase.h" />
|
||||||
|
<ClInclude Include="im2shp.h" />
|
||||||
|
<QtMoc Include="QtGDALProcessBar.h" />
|
||||||
|
<ClInclude Include="x64\Release\uic\ui_LandslidePredict.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="LandslideAssess.qss" />
|
<None Include="LandslidePredict.qss" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
|
||||||
+21
-6
@@ -23,16 +23,16 @@
|
|||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtRcc Include="LandslideAssess.qrc">
|
<QtRcc Include="LandslidePredict.qrc">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</QtRcc>
|
</QtRcc>
|
||||||
<QtUic Include="LandslideAssess.ui">
|
<QtUic Include="LandslidePredict.ui">
|
||||||
<Filter>Form Files</Filter>
|
<Filter>Form Files</Filter>
|
||||||
</QtUic>
|
</QtUic>
|
||||||
<QtMoc Include="LandslideAssess.h">
|
<QtMoc Include="LandslidePredict.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
<ClCompile Include="LandslideAssess.cpp">
|
<ClCompile Include="LandslidePredict.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -40,19 +40,34 @@
|
|||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="im2shp.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="QtGDALProcessBar.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="SrsMainPluginInterFace.h">
|
<QtMoc Include="SrsMainPluginInterFace.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
|
<QtMoc Include="QtGDALProcessBar.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="x64\Release\uic\ui_LandslideAssess.h">
|
<ClInclude Include="x64\Release\uic\ui_LandslidePredict.h">
|
||||||
<Filter>Form Files</Filter>
|
<Filter>Form Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="CProcessBase.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="im2shp.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="LandslideAssess.qss">
|
<None Include="LandslidePredict.qss">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
#include "QtGDALProcessBar.h"
|
||||||
|
#include <QCoreApplication>
|
||||||
|
|
||||||
|
|
||||||
|
QtGDALProcessBar::QtGDALProcessBar(QWidget *parent)
|
||||||
|
: QProgressBar(parent)
|
||||||
|
{
|
||||||
|
//ui.setupUi(this);
|
||||||
|
this->setTextVisible(true);
|
||||||
|
m_dPosition = 0.0;
|
||||||
|
m_iStepCount = 100;
|
||||||
|
m_iCurStep = 0;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QtGDALProcessBar::~QtGDALProcessBar()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度信息
|
||||||
|
* @param pszMsg 进度信息
|
||||||
|
*/
|
||||||
|
void QtGDALProcessBar::SetMessage(const char* pszMsg)
|
||||||
|
{
|
||||||
|
if (pszMsg != NULL)
|
||||||
|
{
|
||||||
|
m_strMessage = pszMsg;
|
||||||
|
//setLabelText(QString(pszMsg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度值
|
||||||
|
* @param dPosition 进度值
|
||||||
|
*/
|
||||||
|
bool QtGDALProcessBar::SetPosition(double dPosition)
|
||||||
|
{
|
||||||
|
m_dPosition = dPosition;
|
||||||
|
//cout << "m_dPosition " << m_dPosition << endl;
|
||||||
|
//current_value = value();
|
||||||
|
int temp_value = int(m_start_value +std::min(100u, (uint)(m_dPosition * 100.0 )) * m_scale);
|
||||||
|
|
||||||
|
setValue(temp_value);
|
||||||
|
//setFormat(tr("%1%").arg(temp_value));
|
||||||
|
//cout << "StepIt " << temp_value << "\t" << "current_value" << int(m_start_value + temp_value * m_scale) << endl;
|
||||||
|
//QCoreApplication::instance()->processEvents();
|
||||||
|
//this->update();
|
||||||
|
//if (this->wasCanceled())
|
||||||
|
// return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QtGDALProcessBar::SetStartEndValue(int i_start_value, int i_end_value)
|
||||||
|
{
|
||||||
|
if (i_end_value< i_start_value )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_start_value = i_start_value;
|
||||||
|
m_end_value = i_end_value;
|
||||||
|
m_scale = (m_end_value - m_start_value) / 100.0;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 进度条前进一步,返回false表示终止操作
|
||||||
|
*/
|
||||||
|
bool QtGDALProcessBar::StepIt()
|
||||||
|
{
|
||||||
|
m_iCurStep++;
|
||||||
|
m_dPosition = m_iCurStep * 1.0 / m_iStepCount;
|
||||||
|
//current_value = value();
|
||||||
|
int temp_value = std::min(100u, (uint)(m_dPosition * 100.0));
|
||||||
|
setValue(int(m_start_value + temp_value * m_scale));
|
||||||
|
//setFormat(QString("当前进度为:%1%").arg(temp_value));
|
||||||
|
//cout << "StepIt " << temp_value <<"\t"<<"current_value"<< current_value << endl;
|
||||||
|
|
||||||
|
//QCoreApplication::instance()->processEvents();
|
||||||
|
|
||||||
|
//if (this->wasCanceled())
|
||||||
|
// return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QtGDALProcessBar::updateProgress(int step)
|
||||||
|
{
|
||||||
|
this->setValue(step);
|
||||||
|
//this->update();
|
||||||
|
//cout << "updateProgress " << step << endl;
|
||||||
|
//QCoreApplication::instance()->processEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QProgressBar>
|
||||||
|
#include "CProcessBase.h"
|
||||||
|
|
||||||
|
class QtGDALProcessBar : public QProgressBar,public CProcessBase
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
QtGDALProcessBar(QWidget *parent = Q_NULLPTR);
|
||||||
|
~QtGDALProcessBar();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度信息
|
||||||
|
* @param pszMsg 进度信息
|
||||||
|
*/
|
||||||
|
void SetMessage(const char* pszMsg);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 设置进度值
|
||||||
|
* @param dPosition 进度值
|
||||||
|
*/
|
||||||
|
bool SetPosition(double dPosition);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置进度条开始结束值
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="i_start_value"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
bool SetStartEndValue(int i_start_value,int i_end_value);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 进度条前进一步
|
||||||
|
*/
|
||||||
|
bool StepIt();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前进度值
|
||||||
|
/// </summary>
|
||||||
|
int current_value;
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void updateProgress(int);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
/// <summary>
|
||||||
|
/// 进度条开始值
|
||||||
|
/// </summary>
|
||||||
|
int m_start_value;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 进度条结束值
|
||||||
|
/// </summary>
|
||||||
|
int m_end_value;
|
||||||
|
|
||||||
|
float m_scale;
|
||||||
|
|
||||||
|
};
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
#include "im2shp.h"
|
||||||
|
#include <ogrsf_frmts.h>
|
||||||
|
#include "CProcessBase.h"
|
||||||
|
/**
|
||||||
|
* \brief 调用GDAL进度条接口
|
||||||
|
*
|
||||||
|
* 该函数用于将GDAL算法中的进度信息导出到CProcessBase基类中,供给界面显示
|
||||||
|
*
|
||||||
|
* @param dfComplete 完成进度值,其取值为 0.0 到 1.0 之间
|
||||||
|
* @param pszMessage 进度信息
|
||||||
|
* @param pProgressArg CProcessBase的指针
|
||||||
|
*
|
||||||
|
* @return 返回TRUE表示继续计算,否则为取消
|
||||||
|
*/
|
||||||
|
int STD_API ALGTermProgress(double dfComplete, const char* pszMessage, void* pProgressArg)
|
||||||
|
{
|
||||||
|
if (pProgressArg != NULL)
|
||||||
|
{
|
||||||
|
QtGDALProcessBar* pProcess = (QtGDALProcessBar*)pProgressArg;
|
||||||
|
pProcess->m_bIsContinue = pProcess->SetPosition(dfComplete);
|
||||||
|
|
||||||
|
if (pProcess->m_bIsContinue)
|
||||||
|
return TRUE;
|
||||||
|
else
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int img2shp::ImagePolygonize(const char* pszSrcFile, const char* pszDstFile, const char* pszFormat, int BandNum,
|
||||||
|
QtGDALProcessBar* probar, QProgressBar* progressBar)
|
||||||
|
{
|
||||||
|
if (NULL == pszSrcFile || NULL == pszDstFile)
|
||||||
|
{
|
||||||
|
printf("待处理的栅格数据及输出矢量数据数据无效!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GDALGetDriverCount() == 0)
|
||||||
|
GDALAllRegister();
|
||||||
|
OGRRegisterAll();
|
||||||
|
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
|
||||||
|
CPLSetConfigOption("SHAPE_ENCODING", "gb2312");
|
||||||
|
|
||||||
|
//打开输入图像,并判断是否正常
|
||||||
|
GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(pszSrcFile, GA_ReadOnly);
|
||||||
|
if (NULL == poSrcDS)
|
||||||
|
{
|
||||||
|
printf("输入文件不能打开,请检查文件是否存在!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//构造矢量文件驱动并创建矢量图层
|
||||||
|
GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
|
||||||
|
if (NULL == poDriver)
|
||||||
|
{
|
||||||
|
printf("不能创建指定类型的矢量文件驱动!");
|
||||||
|
GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*Create方法主要用于创建栅格文件的新数据集,其中nXSize,nYSize,nBands,都是对栅格文件的描述,**都置零后台会默认创建矢量数据集**
|
||||||
|
*/
|
||||||
|
//根据文件名创建输出矢量数据集
|
||||||
|
|
||||||
|
GDALDataset* poDstDs = poDriver->Create(pszDstFile, 0, 0, 0, GDT_Unknown, NULL);
|
||||||
|
if (NULL == poDstDs)
|
||||||
|
{
|
||||||
|
printf("不能创建矢量文件!");
|
||||||
|
GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
OGRSpatialReference* poSpatialRef = new OGRSpatialReference(poSrcDS->GetProjectionRef());
|
||||||
|
|
||||||
|
OGRLayer* poLayer = poDstDs->CreateLayer("Target", poSpatialRef, wkbPolygon, NULL);
|
||||||
|
if (NULL == poLayer)
|
||||||
|
{
|
||||||
|
printf("创建矢量图层失败!");
|
||||||
|
GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
GDALClose(poDstDs);
|
||||||
|
poSpatialRef = NULL;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
OGRFieldDefn ofieldDef("value", OFTInteger);
|
||||||
|
if (OGRERR_NONE != poLayer->CreateField(&ofieldDef))
|
||||||
|
{
|
||||||
|
printf("创建矢量图层属性表失败!");
|
||||||
|
GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
GDALClose(poDstDs);
|
||||||
|
poSpatialRef = NULL;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取图像的对应波段
|
||||||
|
GDALRasterBandH hSrcBand = (GDALRasterBandH)poSrcDS->GetRasterBand(1);
|
||||||
|
|
||||||
|
GDALRasterBand* rasterband = poSrcDS->GetRasterBand(1);
|
||||||
|
|
||||||
|
GDALProgressFunc pfnProgress = ALGTermProgress;
|
||||||
|
|
||||||
|
if (!probar->SetStartEndValue(0, 100))
|
||||||
|
{
|
||||||
|
cout << "初始进度值设置失败!!!" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//if (GDALPolygonize(hSrcBand, NULL, (OGRLayerH)poLayer, 0, NULL, pfnProgress, probar) != CE_None)
|
||||||
|
//if (GDALPolygonize(hSrcBand, NULL, (OGRLayerH)poLayer, 0, NULL, GDALTermProgress, NULL) != CE_None)
|
||||||
|
//qDebug() << rasterband->GetNoDataValue() << endl;
|
||||||
|
//if (0.0 == poSrcDS->GetRasterBand(1)->GetNoDataValue())
|
||||||
|
//{
|
||||||
|
// if (CE_None != GDALPolygonize(hSrcBand, hSrcBand, (OGRLayerH)poLayer, 0, NULL, pfnProgress, probar))
|
||||||
|
// {
|
||||||
|
// GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
// GDALClose(poDstDs);
|
||||||
|
// delete poSpatialRef;
|
||||||
|
// poSpatialRef = NULL;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// if (CE_None != GDALPolygonize(hSrcBand, NULL, (OGRLayerH)poLayer, 0, NULL, pfnProgress, probar))
|
||||||
|
// {
|
||||||
|
// GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
// GDALClose(poDstDs);
|
||||||
|
// delete poSpatialRef;
|
||||||
|
// poSpatialRef = NULL;
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
if (CE_None != GDALPolygonize(hSrcBand, hSrcBand, (OGRLayerH)poLayer, 0, NULL, pfnProgress, probar))
|
||||||
|
{
|
||||||
|
GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
GDALClose(poDstDs);
|
||||||
|
delete poSpatialRef;
|
||||||
|
poSpatialRef = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
GDALClose((GDALDatasetH)poSrcDS);
|
||||||
|
GDALClose(poDstDs);
|
||||||
|
poSpatialRef = NULL;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "gdal_priv.h"
|
||||||
|
#include "ogrsf_frmts.h" //for ogr
|
||||||
|
#include "gdal_alg.h" //for GDALPolygonize
|
||||||
|
#include "cpl_conv.h" //for CPLMalloc()
|
||||||
|
#include "QtGDALProcessBar.h"
|
||||||
|
#include <QDebug>
|
||||||
|
/**
|
||||||
|
* @brief 导出符号定义
|
||||||
|
*/
|
||||||
|
#ifndef STD_API
|
||||||
|
#define STD_API __stdcall
|
||||||
|
#endif
|
||||||
|
/**
|
||||||
|
* \brief 调用GDAL进度条接口
|
||||||
|
*
|
||||||
|
* 该函数用于将GDAL算法中的进度信息导出到CProcessBase基类中,供给界面显示
|
||||||
|
*
|
||||||
|
* @param dfComplete 完成进度值,其取值为 0.0 到 1.0 之间
|
||||||
|
* @param pszMessage 进度信息
|
||||||
|
* @param pProgressArg CProcessBase的指针
|
||||||
|
*
|
||||||
|
* @return 返回TRUE表示继续计算,否则为取消
|
||||||
|
*/
|
||||||
|
int STD_API ALGTermProgress(double dfComplete, const char* pszMessage, void* pProgressArg);
|
||||||
|
|
||||||
|
class img2shp
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
int ImagePolygonize(const char* pszSrcFile, const char* pszDstFile, const char* pszFormat, int BandNum, QtGDALProcessBar* probar, QProgressBar* progressBar);
|
||||||
|
bool createChineseStringProperty(OGRLayer* poLayer, const char* filterFieldName, const char* createFieldName, vector<string> nameVal, float min, QProgressBar* progressBar);
|
||||||
|
protected:
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#include "LandslideAssess.h"
|
#include "LandslidePredict.h"
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
LandslideAssess w;
|
LandslidePredict w;
|
||||||
w.CenterWidget()->show();
|
w.CenterWidget()->show();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="32" height="32" viewBox="0 0 32 32" fill="none"><g opacity="1" transform="translate(0 0) rotate(0 16 16)"><path id="路径 1 (轮廓)" fill-rule="evenodd" style="fill:#2C2C2C" transform="translate(0 1.5374328853267798) rotate(0 15.99999999999979 14.46256711467357)" opacity="1" d="M17.11 8.78L19.6 20.62L29.27 24.69L32 28.93L0 28.93L0 14.53L6.07 1.45L6.29 0.99L14.08 0L17.11 8.78ZM7.53 2.69L1.84 14.94L1.84 27.08L28.62 27.08L28.03 26.16L17.99 21.94L15.33 9.27L12.82 2.02L7.53 2.69Z" /><path id="路径 2" fill-rule="evenodd" style="fill:#2C2C2C" transform="translate(18.9798339264529 9.916436213707748) rotate(0 5.021363830056714 7.462944407974411)" opacity="1" d="M1.75,11.42L10.04,14.93L7.09,6.73L0.18,0L0,0.28L1.75,11.42Z " /><path id="路径 3" fill-rule="evenodd" style="fill:#2C2C2C" transform="translate(26.07423786983578 13.693975975768783) rotate(0 1.4741618583652738 1.3820267422174524)" opacity="1" d="M0.53,0.2C0.46,0.17 0.37,0.19 0.32,0.26C0.27,0.32 0.27,0.41 0.31,0.47L1.66,2.53C1.7,2.59 1.75,2.62 1.82,2.62C1.88,2.62 1.93,2.59 1.97,2.54L2.82,1.3C2.85,1.25 2.86,1.19 2.84,1.14C2.82,1.09 2.78,1.04 2.73,1.02L0.53,0.2Z " /><path id="路径 4" fill-rule="evenodd" style="fill:#2C2C2C" transform="translate(21.28321183014864 9.640030865264256) rotate(0 1.8427023229565922 1.5662969745131128)" opacity="1" d="M3.66,0.65C3.67,0.6 3.65,0.55 3.62,0.51C3.59,0.47 3.55,0.45 3.5,0.44L0.56,0.07C0.48,0.06 0.41,0.1 0.37,0.18C0.34,0.25 0.36,0.34 0.41,0.39L3.08,2.89C3.13,2.93 3.2,2.95 3.27,2.93C3.33,2.9 3.38,2.84 3.39,2.78L3.66,0.65Z " /></g></svg>
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user