Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ca146c0c5 | |||
| b163a03dc9 | |||
| 3ba0a0d0ab |
@@ -1,23 +1,22 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 16
|
||||||
VisualStudioVersion = 16.0.31911.196
|
VisualStudioVersion = 16.0.32126.315
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DEM_GeneVec", "DEM_GeneVec\DEM_GeneVec.vcxproj", "{858826AD-BC7C-4B9D-8E48-626392904948}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DEM_Fill", "DEM_Fill\DEM_Fill.vcxproj", "{32F04C81-EC93-432F-9B60-0B92B5FCC5C5}"
|
||||||
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
|
||||||
{858826AD-BC7C-4B9D-8E48-626392904948}.Release|x64.ActiveCfg = Release|x64
|
{32F04C81-EC93-432F-9B60-0B92B5FCC5C5}.Release|x64.ActiveCfg = Release|x64
|
||||||
{858826AD-BC7C-4B9D-8E48-626392904948}.Release|x64.Build.0 = Release|x64
|
{32F04C81-EC93-432F-9B60-0B92B5FCC5C5}.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
|
||||||
Qt5Version = qt5.14.2
|
SolutionGuid = {D6C86E29-E4F8-449B-838C-C7B217220096}
|
||||||
SolutionGuid = {B8F00221-FFCF-43EE-B1EC-68EEC3E5BC58}
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
@@ -0,0 +1,364 @@
|
|||||||
|
#include "DEM_Fill.h"
|
||||||
|
|
||||||
|
#include <qgsrasterlayer.h>
|
||||||
|
#include <qgsvectorlayer.h>
|
||||||
|
#include <qgsmapcanvas.h>
|
||||||
|
|
||||||
|
void WorkThreadObject::runFillingWork(QString in_masked, QString out_filled, QString scale, QString size)
|
||||||
|
{
|
||||||
|
QDir pyDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (!pyDir.cd("models\\mask_fill"))
|
||||||
|
{
|
||||||
|
qDebug() << "no folder models\\mask_fill";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString pyFilePath = pyDir.absoluteFilePath("demFillHoles.py");
|
||||||
|
if (pyFilePath == "")
|
||||||
|
{
|
||||||
|
qDebug() << "not find demFillHoles.py";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QDir datDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (!datDir.cd("QGIS_3.22.8\\bin"))
|
||||||
|
{
|
||||||
|
qDebug() << "no folder QGIS_3.22.8\\bin";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QString datPath = datDir.absoluteFilePath("python-qgis-ltr.bat");
|
||||||
|
if (datPath == "")
|
||||||
|
{
|
||||||
|
qDebug() << "not find qgis env";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const char* cmd = (datPath + " " + pyFilePath + " --in_holedem " + in_masked + "/" + " --work_space " + out_filled + "/" +
|
||||||
|
" --scale " + scale + " --win_size " + size).toStdString().c_str();
|
||||||
|
cout << cmd << "\n";
|
||||||
|
run_cmd(cmd);
|
||||||
|
//QString cmd = datPath + " " + pyFilePath
|
||||||
|
// + " --in_holedem " + in_masked + "/" + " --work_space " + out_filled + "/"
|
||||||
|
// + " --scale " + scale + " --win_size " + size;
|
||||||
|
//QProcess* pProces = new QProcess(this);
|
||||||
|
//connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(readProcessStandardOutput()));
|
||||||
|
//pProces->start(cmd);
|
||||||
|
//emit process(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WorkThreadObject::readProcessStandardOutput()
|
||||||
|
{
|
||||||
|
mProcess = (QProcess*)sender();
|
||||||
|
QString output = QString::fromLocal8Bit(mProcess->readAllStandardOutput());
|
||||||
|
output.chop(2);
|
||||||
|
if (output.toFloat() != 0)
|
||||||
|
{
|
||||||
|
qDebug() << "process:" << output.toFloat();
|
||||||
|
emit process(output.toFloat());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "unsolved exe out:" << output;
|
||||||
|
}
|
||||||
|
|
||||||
|
int WorkThreadObject::run_cmd(const char* cmd)
|
||||||
|
{
|
||||||
|
char MsgBuff[1024];
|
||||||
|
int MsgLen = 1020;
|
||||||
|
FILE* fp;
|
||||||
|
if (cmd == NULL)
|
||||||
|
return -1;
|
||||||
|
if ((fp = _popen(cmd, "r")) == NULL)
|
||||||
|
return -2;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
memset(MsgBuff, 0, MsgLen);
|
||||||
|
//读取命令执行过程中的输出
|
||||||
|
while (fgets(MsgBuff, MsgLen, fp) != NULL)
|
||||||
|
{
|
||||||
|
printf("MsgBuff: %s\n", MsgBuff);
|
||||||
|
QString qStr = QString(MsgBuff);
|
||||||
|
if (qStr.toDouble() != 0.0)
|
||||||
|
emit process(qStr.toDouble());
|
||||||
|
}
|
||||||
|
//关闭执行的进程
|
||||||
|
if (_pclose(fp) == -1)
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
DataFilling::DataFilling()
|
||||||
|
{
|
||||||
|
//ui.setupUi(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DataFilling::PannelName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DataFilling::CategoryName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("DEM模块");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DataFilling::EnglishName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("DEM_Module");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DataFilling::ChineseName()
|
||||||
|
{
|
||||||
|
return QString::fromLocal8Bit("数据填补");
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DataFilling::Information()
|
||||||
|
{
|
||||||
|
return "数据填补";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DataFilling::IconPath()
|
||||||
|
{
|
||||||
|
return ":/DEM_Fill/resources/fill.svg";
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget* DataFilling::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(":/DEM_Fill/resources/fill.svg"));
|
||||||
|
myWidget->setAttribute(Qt::WA_QuitOnClose, false);
|
||||||
|
|
||||||
|
myWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
connect(myWidget, &QDialog::destroyed, this, [=] {
|
||||||
|
qDebug() << "----DEM Fill window close----";
|
||||||
|
|
||||||
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (pluginsDir.cd("srsplugins\\DemModel"))
|
||||||
|
{
|
||||||
|
QString strConfigPath = pluginsDir.absoluteFilePath("dem_config.ini");
|
||||||
|
QFile f(strConfigPath);
|
||||||
|
if (f.exists())
|
||||||
|
{
|
||||||
|
WriteConfigPaths(strConfigPath);
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
myWidget->close();
|
||||||
|
myWidget = nullptr;
|
||||||
|
if (mWorkThread != nullptr)
|
||||||
|
{
|
||||||
|
mWorkThread->quit();
|
||||||
|
mWorkThread->wait();//调用wait后先调用finished信号对应的槽函数,执行完成后再往下走
|
||||||
|
mWorkThread = nullptr;//mWorkThread, &QThread::finished, mWorkThread, &QObject::deleteLater,不需要delete
|
||||||
|
mWorker = nullptr;//mWorkThread, &QThread::finished, mWorker, &QObject::deleteLater
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(ui.pbtMasked, &QPushButton::pressed, this, &DataFilling::chooseMaskedSlope);
|
||||||
|
connect(ui.pbtOutFill, &QPushButton::pressed, this, &DataFilling::chooseOutFill);
|
||||||
|
|
||||||
|
connect(ui.pushButton_ok, &QPushButton::pressed, this, &DataFilling::readAndStart);
|
||||||
|
connect(ui.pushButton_cancel, &QPushButton::pressed, this, &DataFilling::pbCancel);
|
||||||
|
|
||||||
|
ui.progressBar->setTextVisible(true);
|
||||||
|
ui.progressBar->setRange(0, 100);
|
||||||
|
|
||||||
|
ui.pbtMasked->setFocus();
|
||||||
|
|
||||||
|
ui.lineRectangleScale->setValidator(new QRegExpValidator(QRegExp("^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$")));
|
||||||
|
ui.lineExpandSize->setValidator(new QIntValidator(0, 999, this));
|
||||||
|
ui.lineRectangleScale->setText("0.1");
|
||||||
|
ui.lineExpandSize->setText("3");
|
||||||
|
|
||||||
|
QFile qssFile(":/DEM_Fill/DEM_Fill.qss");
|
||||||
|
qssFile.open(QFile::ReadOnly); //以只读方式打开
|
||||||
|
if (qssFile.isOpen())
|
||||||
|
{
|
||||||
|
QString qss = QLatin1String(qssFile.readAll());
|
||||||
|
myWidget->setStyleSheet(qss);
|
||||||
|
qssFile.close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "无法打开文件";
|
||||||
|
|
||||||
|
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
||||||
|
if (pluginsDir.cd("srsplugins\\DemModel"))
|
||||||
|
{
|
||||||
|
QString strConfigPath = pluginsDir.absoluteFilePath("dem_config.ini");
|
||||||
|
QFile f(strConfigPath);
|
||||||
|
if (f.exists())
|
||||||
|
{
|
||||||
|
ReadConfigHistoryPaths(strConfigPath);
|
||||||
|
f.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showWin)
|
||||||
|
myWidget->show();
|
||||||
|
|
||||||
|
return myWidget;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilling::startWorkThread()
|
||||||
|
{
|
||||||
|
if (mWorker != nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mWorkThread = new QThread();
|
||||||
|
mWorker = new WorkThreadObject();
|
||||||
|
mWorker->moveToThread(mWorkThread);
|
||||||
|
connect(mWorkThread, &QThread::finished, mWorkThread, &QObject::deleteLater);
|
||||||
|
connect(mWorkThread, &QThread::finished, mWorker, &QObject::deleteLater);
|
||||||
|
connect(mWorker, &WorkThreadObject::sendMaskedTiff, this, &DataFilling::openResultData);
|
||||||
|
|
||||||
|
connect(mWorker, &WorkThreadObject::process, myWidget, [=](int value) {
|
||||||
|
ui.progressBar->setValue(value);
|
||||||
|
if (value == 100)
|
||||||
|
{
|
||||||
|
QMessageBox mess(QMessageBox::Information,
|
||||||
|
QString::fromLocal8Bit("填补结束"),
|
||||||
|
QString::fromLocal8Bit("填补结果文件夹:\n") + outPath);
|
||||||
|
mess.setWindowFlags(Qt::Drawer);
|
||||||
|
mess.setStandardButtons(QMessageBox::Yes);
|
||||||
|
mess.button(QMessageBox::StandardButton::Yes)->setText(QString::fromLocal8Bit("确认"));
|
||||||
|
//mess.setTextInteractionFlags(Qt::TextSelectableByMouse);
|
||||||
|
int result = mess.exec();
|
||||||
|
pbCancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
connect(this, &DataFilling::startDataFill, mWorker, &WorkThreadObject::runFillingWork);
|
||||||
|
|
||||||
|
mWorkThread->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilling::chooseMaskedSlope()
|
||||||
|
{
|
||||||
|
QString dirDom = QFileDialog::getExistingDirectory(ui.pbtMasked, QString::fromLocal8Bit("选择输入裁剪后的DEM文件夹"), "");
|
||||||
|
if (dirDom != "")
|
||||||
|
ui.lineMasked->setText(dirDom);
|
||||||
|
}
|
||||||
|
void DataFilling::chooseOutFill()
|
||||||
|
{
|
||||||
|
QString dirDom = QFileDialog::getExistingDirectory(ui.pbtOutFill, QString::fromLocal8Bit("选择输出数据填补结果文件夹"), "");
|
||||||
|
if (dirDom != "")
|
||||||
|
ui.lineOutFill->setText(dirDom);
|
||||||
|
}
|
||||||
|
void DataFilling::readAndStart()
|
||||||
|
{
|
||||||
|
QString in_masked = ui.lineMasked->text();
|
||||||
|
QString out_filled = ui.lineOutFill->text();
|
||||||
|
QString scale = ui.lineRectangleScale->text();
|
||||||
|
QString size = ui.lineExpandSize->text();
|
||||||
|
if (in_masked == "" || out_filled == "" || scale == "" || size == "")
|
||||||
|
{
|
||||||
|
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请检查输入输出路径"));
|
||||||
|
mess.setWindowFlags(Qt::Drawer);
|
||||||
|
int result = mess.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
outPath = out_filled;
|
||||||
|
|
||||||
|
ui.progressBar->setValue(0);
|
||||||
|
|
||||||
|
if (mWorkThread == nullptr)
|
||||||
|
{
|
||||||
|
qDebug() << "--startThread";
|
||||||
|
startWorkThread();
|
||||||
|
}
|
||||||
|
emit startDataFill(in_masked, out_filled, scale, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilling::ReadConfigHistoryPaths(QString strPath)
|
||||||
|
{
|
||||||
|
QSettings configIni(strPath, QSettings::IniFormat);
|
||||||
|
|
||||||
|
//打开标题为:[DemFill] 的组
|
||||||
|
configIni.beginGroup("DemFill");
|
||||||
|
|
||||||
|
ui.lineMasked->setText(configIni.value("MaskedFiles").toString());
|
||||||
|
ui.lineOutFill->setText(configIni.value("FilledFiles").toString());
|
||||||
|
|
||||||
|
configIni.endGroup();//关闭组
|
||||||
|
}
|
||||||
|
void DataFilling::WriteConfigPaths(QString strPath)
|
||||||
|
{
|
||||||
|
QSettings configIni(strPath, QSettings::IniFormat);
|
||||||
|
configIni.setIniCodec("utf-8");
|
||||||
|
//打开标题为:[DemFill] 的组
|
||||||
|
configIni.beginGroup("DemFill");
|
||||||
|
|
||||||
|
//更新输入模型路径
|
||||||
|
QString temp = ui.lineMasked->text();
|
||||||
|
if (temp != "")
|
||||||
|
configIni.setValue("MaskedFiles", temp);
|
||||||
|
//更新输入DOM路径
|
||||||
|
temp = ui.lineOutFill->text();
|
||||||
|
if (temp != "")
|
||||||
|
configIni.setValue("FilledFiles", temp);
|
||||||
|
|
||||||
|
configIni.endGroup();//关闭组
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilling::pbCancel()
|
||||||
|
{
|
||||||
|
delete myWidget;//调起&QDialog::destroyed
|
||||||
|
}
|
||||||
|
|
||||||
|
void DataFilling::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtWidgets/QDialog>
|
||||||
|
#include <QProcess>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QIntValidator>
|
||||||
|
#include <QRegExpValidator>
|
||||||
|
|
||||||
|
#include "SrsMainPluginInterFace.h"
|
||||||
|
|
||||||
|
#include "ui_DEM_Fill.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class WorkThreadObject :public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
int run_cmd(const char* cmd);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void process(int value);
|
||||||
|
void sendMaskedTiff(QStringList maskedData);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void runFillingWork(QString in_masked, QString out_filled, QString scale, QString size);
|
||||||
|
void readProcessStandardOutput();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QProcess* mProcess = nullptr;
|
||||||
|
|
||||||
|
QString outTiffPath, tifflinear, tiffcubic;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DataFilling : public SrsMainInterface
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(SrsMainInterface)
|
||||||
|
Q_PLUGIN_METADATA(IID MainInterface_iid)
|
||||||
|
|
||||||
|
public:
|
||||||
|
DataFilling();
|
||||||
|
|
||||||
|
virtual QString PannelName() override;
|
||||||
|
virtual QString CategoryName() override;
|
||||||
|
|
||||||
|
virtual QString EnglishName() override;
|
||||||
|
virtual QString ChineseName() override;
|
||||||
|
virtual QString Information() override;
|
||||||
|
virtual QString IconPath() override;
|
||||||
|
virtual QWidget* CenterWidget() override;
|
||||||
|
|
||||||
|
void startWorkThread();
|
||||||
|
|
||||||
|
//读json文件,获取历史存储的路径
|
||||||
|
void ReadConfigHistoryPaths(QString strPath);
|
||||||
|
//保存本次打开的路径到json文件
|
||||||
|
void WriteConfigPaths(QString strPath);
|
||||||
|
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
//pushbutton_OK
|
||||||
|
void readAndStart();
|
||||||
|
void pbCancel();
|
||||||
|
|
||||||
|
void chooseMaskedSlope();
|
||||||
|
void chooseOutFill();
|
||||||
|
|
||||||
|
void openResultData(QStringList string_list);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void startDataFill(QString in_masked, QString out_filled, QString scale, QString size);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::DEM_FillClass ui;
|
||||||
|
|
||||||
|
QDialog* myWidget = nullptr;
|
||||||
|
|
||||||
|
QThread* mWorkThread = nullptr;
|
||||||
|
WorkThreadObject* mWorker = nullptr;
|
||||||
|
|
||||||
|
QString outPath;
|
||||||
|
};
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/DEM_Fill">
|
||||||
|
<file>resources/fill.svg</file>
|
||||||
|
<file>DEM_Fill.qss</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
QProgressBar#progressBar {
|
||||||
|
border:0px solid white;
|
||||||
|
text-align:center;
|
||||||
|
color:black;
|
||||||
|
}
|
||||||
|
QProgressBar#progressBar:chunk {
|
||||||
|
background-color:#3FABBA;
|
||||||
|
width:20px;
|
||||||
|
}
|
||||||
|
QProgressBar#progressBar QLineEdit {
|
||||||
|
border:none;
|
||||||
|
color:black;
|
||||||
|
padding-left:5px;
|
||||||
|
font-size:16px;
|
||||||
|
background-color:transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QLabel{
|
||||||
|
color:black;
|
||||||
|
font-family:'Microsoft YaHei';
|
||||||
|
font-size:12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----QPushButtonÑùʽ±í*/
|
||||||
|
#pushButton_ok, #pushButton_cancel, #pbtMasked, #pbtOutFill{
|
||||||
|
font-family:'Microsoft YaHei';
|
||||||
|
font-size:12px;
|
||||||
|
background-color: #ffffff;
|
||||||
|
border: 1px solid #dcdfe6;
|
||||||
|
padding: 2px;
|
||||||
|
border-radius: 5px;
|
||||||
|
max-height:20px;
|
||||||
|
}
|
||||||
|
#pushButton_ok:hover, #pushButton_cancel:hover, #pbtMasked:hover, #pbtOutFill:hover{
|
||||||
|
background-color: #ecf5ff;
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
|
#pushButton_ok:pressed, #pushButton_cancel:pressed, #pbtMasked:pressed, #pbtOutFill:pressed{
|
||||||
|
border: 1px solid #3a8ee6;
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
|
#pushButton_ok:checked, #pushButton_cancel:checked, #pbtMasked:checked, #pbtOutFill:checked{
|
||||||
|
border: 1px solid #3a8ee6;
|
||||||
|
color: #409eff;
|
||||||
|
}
|
||||||
|
#pushButton_ok:focus, #pushButton_cancel:focus, #pbtMasked:focus, #pbtOutFill:focus{
|
||||||
|
border: 1px solid #3a8ee6;
|
||||||
|
color: #409eff;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
#pushButton_ok, #pushButton_cancel{
|
||||||
|
min-width:36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*----QLineEditÑùʽ*/
|
||||||
|
#lineMasked, #lineOutFill,#lineRectangleScale,#lineExpandSize{
|
||||||
|
border:0px;
|
||||||
|
border-bottom: 1px solid #B3B3B3;
|
||||||
|
font-family:'Microsoft YaHei';
|
||||||
|
background-color:transparent;
|
||||||
|
}
|
||||||
|
#lineMasked:hover, #lineOutFill:hover,#lineRectangleScale:hover,#lineExpandSize:hover{
|
||||||
|
border-bottom: 2px solid #66A3FF;
|
||||||
|
}
|
||||||
|
#lineMasked:focus, #lineOutFill:focus,#lineRectangleScale:focus,#lineExpandSize:focus{
|
||||||
|
border-bottom: 2px solid #7666FF;
|
||||||
|
}
|
||||||
@@ -0,0 +1,236 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>DEM_FillClass</class>
|
||||||
|
<widget class="QDialog" name="DEM_FillClass">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>250</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>400</width>
|
||||||
|
<height>250</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>400</width>
|
||||||
|
<height>250</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>DEM_Fill</string>
|
||||||
|
</property>
|
||||||
|
<property name="windowIcon">
|
||||||
|
<iconset resource="DEM_Fill.qrc">
|
||||||
|
<normaloff>:/DEM_Fill/resources/fill.svg</normaloff>:/DEM_Fill/resources/fill.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>输入裁剪后的DEM文件</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLineEdit" name="lineMasked"/>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QPushButton" name="pbtMasked">
|
||||||
|
<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">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>输出数据填补结果文件</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLineEdit" name="lineOutFill"/>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1">
|
||||||
|
<widget class="QPushButton" name="pbtOutFill">
|
||||||
|
<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" colspan="2">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>12</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>12</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>外接矩形外扩比例</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineRectangleScale"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>空洞外扩像素</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="lineExpandSize"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>81</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_ok">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>确定</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Fixed</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>13</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_cancel">
|
||||||
|
<property name="text">
|
||||||
|
<string>取消</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="value">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>lineMasked</tabstop>
|
||||||
|
<tabstop>pbtMasked</tabstop>
|
||||||
|
<tabstop>lineOutFill</tabstop>
|
||||||
|
<tabstop>pbtOutFill</tabstop>
|
||||||
|
<tabstop>lineRectangleScale</tabstop>
|
||||||
|
<tabstop>lineExpandSize</tabstop>
|
||||||
|
<tabstop>pushButton_ok</tabstop>
|
||||||
|
<tabstop>pushButton_cancel</tabstop>
|
||||||
|
</tabstops>
|
||||||
|
<resources>
|
||||||
|
<include location="DEM_Fill.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
||||||
@@ -7,11 +7,10 @@
|
|||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<ProjectGuid>{858826AD-BC7C-4B9D-8E48-626392904948}</ProjectGuid>
|
<ProjectGuid>{32F04C81-EC93-432F-9B60-0B92B5FCC5C5}</ProjectGuid>
|
||||||
<Keyword>QtVS_v304</Keyword>
|
<Keyword>QtVS_v304</Keyword>
|
||||||
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0.19041.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0.19041.0</WindowsTargetPlatformVersion>
|
||||||
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
|
||||||
<ProjectName>DEM_Train</ProjectName>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||||
@@ -23,7 +22,7 @@
|
|||||||
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
<Import Project="$(QtMsBuild)\qt_defaults.props" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
|
||||||
<QtInstall>QtQgis</QtInstall>
|
<QtInstall>qt5.11.2</QtInstall>
|
||||||
<QtModules>core;gui;widgets</QtModules>
|
<QtModules>core;gui;widgets</QtModules>
|
||||||
<QtBuildConfig>release</QtBuildConfig>
|
<QtBuildConfig>release</QtBuildConfig>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -38,13 +37,13 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<IncludePath>D:\qgis\osgeo4w\include;D:\qgis\osgeo4w\apps\Qt5\include;$(IncludePath)</IncludePath>
|
<TargetName>dem4-$(ProjectName)</TargetName>
|
||||||
<LibraryPath>D:\qgis\osgeo4w\lib;D:\qgis\osgeo4w\apps\Qt5\lib;$(LibraryPath)</LibraryPath>
|
<IncludePath>D:\qgis\osgeo4w\include;D:\qgis\osgeo4w\apps\Qt5\include;D:\qgis\osgeo4w\apps\qgis_build_sdk\include;D:\qgis\osgeo4w\apps\Qt5\include\QtXml;$(IncludePath)</IncludePath>
|
||||||
<TargetName>dem1-$(ProjectName)</TargetName>
|
<LibraryPath>D:\qgis\osgeo4w\lib;D:\qgis\osgeo4w\apps\Qt5\lib;D:\qgis\osgeo4w\apps\qgis_build_sdk\lib;$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<Link>
|
<Link>
|
||||||
<AdditionalDependencies>gdal_i.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>qgis_gui.lib;qgis_analysis.lib;qgis_core.lib;qgis_native.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
|
||||||
@@ -56,29 +55,25 @@
|
|||||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Windows</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="CProgressBar.cpp" />
|
<QtRcc Include="DEM_Fill.qrc" />
|
||||||
<ClCompile Include="ThreadObject.cpp" />
|
<QtUic Include="DEM_Fill.ui" />
|
||||||
<QtRcc Include="DEM_GeneVec.qrc" />
|
<QtMoc Include="DEM_Fill.h" />
|
||||||
<QtMoc Include="DEM_GeneVec.h" />
|
<ClCompile Include="DEM_Fill.cpp" />
|
||||||
<ClCompile Include="DEM_GeneVec.cpp" />
|
|
||||||
<ClCompile Include="main.cpp" />
|
<ClCompile Include="main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtUic Include="DEM_GeneVec.ui" />
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<QtMoc Include="ThreadObject.h" />
|
|
||||||
<QtMoc Include="SrsMainPluginInterFace.h" />
|
<QtMoc Include="SrsMainPluginInterFace.h" />
|
||||||
<QtMoc Include="CProgressBar.h" />
|
|
||||||
<ClInclude Include="x64\Release\uic\ui_DEM_GeneVec.h" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="DEM_GeneVec.qss" />
|
<ClInclude Include="x64\Release\uic\ui_DEM_Fill.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="DEM_Fill.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,18 +21,18 @@
|
|||||||
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
|
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
|
||||||
<Extensions>ts</Extensions>
|
<Extensions>ts</Extensions>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="process">
|
|
||||||
<UniqueIdentifier>{96222dac-cebd-43e4-bfdd-ebee13ab43e3}</UniqueIdentifier>
|
|
||||||
</Filter>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtRcc Include="DEM_GeneVec.qrc">
|
<QtRcc Include="DEM_Fill.qrc">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</QtRcc>
|
</QtRcc>
|
||||||
<QtMoc Include="DEM_GeneVec.h">
|
<QtUic Include="DEM_Fill.ui">
|
||||||
|
<Filter>Form Files</Filter>
|
||||||
|
</QtUic>
|
||||||
|
<QtMoc Include="DEM_Fill.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtMoc>
|
</QtMoc>
|
||||||
<ClCompile Include="DEM_GeneVec.cpp">
|
<ClCompile Include="DEM_Fill.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -40,36 +40,19 @@
|
|||||||
<ClCompile Include="main.cpp">
|
<ClCompile Include="main.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="ThreadObject.cpp">
|
|
||||||
<Filter>process</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="CProgressBar.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtUic Include="DEM_GeneVec.ui">
|
<QtMoc Include="SrsMainPluginInterFace.h">
|
||||||
<Filter>Form Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</QtUic>
|
</QtMoc>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="x64\Release\uic\ui_DEM_GeneVec.h">
|
<ClInclude Include="x64\Release\uic\ui_DEM_Fill.h">
|
||||||
<Filter>Form Files</Filter>
|
<Filter>Form Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<QtMoc Include="ThreadObject.h">
|
<None Include="DEM_Fill.qss">
|
||||||
<Filter>process</Filter>
|
|
||||||
</QtMoc>
|
|
||||||
<QtMoc Include="SrsMainPluginInterFace.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</QtMoc>
|
|
||||||
<QtMoc Include="CProgressBar.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</QtMoc>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<None Include="DEM_GeneVec.qss">
|
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include "DEM_Fill.h"
|
||||||
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
DataFilling w;
|
||||||
|
w.CenterWidget()->show();
|
||||||
|
return a.exec();
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?><svg width="26" height="26" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="6" y="6" width="36" height="36" rx="3" fill="none" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/><rect x="14" y="14" width="20" height="20" fill="none" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/><path d="M34 23L23 34" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/><path d="M25 14L14 25" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/><path d="M34 14L14 34" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/><path d="M14 22V34H26" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/><path d="M22 14H34V26" stroke="#2c2c2c" stroke-width="3" stroke-linecap="butt" stroke-linejoin="round"/></svg>
|
||||||
|
After Width: | Height: | Size: 936 B |
@@ -1,51 +0,0 @@
|
|||||||
#include "CProgressBar.h"
|
|
||||||
|
|
||||||
CProgressBar::CProgressBar(QWidget* parent) : QProgressBar(parent)
|
|
||||||
{
|
|
||||||
//this->setStyleSheet(
|
|
||||||
// "QProgressBar {color:black;font-size:12px;font-weight:normal;font-family:'Microsoft YaHei'; text-align:center; }"
|
|
||||||
// "QProgressBar::chunk {background-color: rgb(0, 160, 244);}");
|
|
||||||
}
|
|
||||||
|
|
||||||
void CProgressBar::ShowTips(const QString& strTips)
|
|
||||||
{
|
|
||||||
if (this->isHidden())
|
|
||||||
{
|
|
||||||
this->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->resetFormat();
|
|
||||||
this->setRange(0, 100);
|
|
||||||
this->setFormat(strTips);
|
|
||||||
this->setValue(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
double CProgressBar::GetDoubleFormatValue()
|
|
||||||
{
|
|
||||||
double dValue = 0.0;
|
|
||||||
|
|
||||||
QString strFormat = this->format();
|
|
||||||
if (!strFormat.isEmpty())
|
|
||||||
{
|
|
||||||
int nIndex = strFormat.indexOf(":");
|
|
||||||
if (nIndex != -1)
|
|
||||||
{
|
|
||||||
QString strFormatData = strFormat.mid(nIndex + 1, strFormat.length() - nIndex - 2);
|
|
||||||
dValue = strFormatData.toDouble();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CProgressBar::SetDoubleFormatValue(const QString& strFormat, double dValue)
|
|
||||||
{
|
|
||||||
if (this->isHidden())
|
|
||||||
{
|
|
||||||
this->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setFormat(strFormat + ":" + QString::number(dValue, 'f', 2) + "%");
|
|
||||||
this->setValue(dValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include<QProgressBar>
|
|
||||||
|
|
||||||
class CProgressBar : public QProgressBar
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
CProgressBar(QWidget* parent = 0);
|
|
||||||
~CProgressBar() {}
|
|
||||||
|
|
||||||
public:
|
|
||||||
void ShowTips(const QString& strTips);
|
|
||||||
|
|
||||||
void SetDoubleFormatValue(const QString& strFormat, double dValue);
|
|
||||||
|
|
||||||
double GetDoubleFormatValue();
|
|
||||||
};
|
|
||||||
@@ -1,425 +0,0 @@
|
|||||||
#include "DEM_GeneVec.h"
|
|
||||||
#include<windows.h>
|
|
||||||
#include<stdio.h>
|
|
||||||
#include<stdlib.h>
|
|
||||||
|
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
TrainMoudle::TrainMoudle()
|
|
||||||
{
|
|
||||||
//ui.setupUi(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
TrainMoudle::~TrainMoudle()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TrainMoudle::PannelName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TrainMoudle::CategoryName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("DEM模块");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TrainMoudle::EnglishName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("DEM_Module");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TrainMoudle::ChineseName()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("模型构建");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TrainMoudle::Information()
|
|
||||||
{
|
|
||||||
return QString::fromLocal8Bit("模型构建");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString TrainMoudle::IconPath()
|
|
||||||
{
|
|
||||||
return ":/DEM_GeneVec/resources/dem_vec.svg";
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget* TrainMoudle::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(":/DEM_GeneVec/resources/dem_vec.svg"));
|
|
||||||
myWidget->setAttribute(Qt::WA_QuitOnClose, false);
|
|
||||||
|
|
||||||
myWidget->setAttribute(Qt::WA_DeleteOnClose);
|
|
||||||
connect(myWidget, &QDialog::destroyed, this, [=] {
|
|
||||||
qDebug() << "----DEM train window close----";
|
|
||||||
|
|
||||||
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
||||||
if (pluginsDir.cd("srsplugins\\DemModel"))
|
|
||||||
{
|
|
||||||
QString strConfigPath = pluginsDir.absoluteFilePath("dem_config.ini");
|
|
||||||
QFile f(strConfigPath);
|
|
||||||
if (f.exists())
|
|
||||||
{
|
|
||||||
WriteConfigPaths(strConfigPath);
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mThread != nullptr)
|
|
||||||
{
|
|
||||||
mThread->requestInterruption();//请求线程中断
|
|
||||||
mThread->quit();
|
|
||||||
mThread->wait();//调用wait后先调用finished信号对应的槽函数,执行完成后再往下走
|
|
||||||
mWorkObject->on_cancel();
|
|
||||||
mThread = nullptr;//m_objThread, &QThread::finished, m_objThread, &QObject::deleteLater,不需要delete
|
|
||||||
mWorkObject = nullptr;//m_objThread, &QThread::finished, m_obj, &QObject::deleteLater
|
|
||||||
}
|
|
||||||
myWidget->close();
|
|
||||||
myWidget = nullptr;
|
|
||||||
});
|
|
||||||
connect(ui.pbtInModel, &QPushButton::pressed, this, &TrainMoudle::choseInModel);
|
|
||||||
connect(ui.pbtInDom, &QPushButton::pressed, this, &TrainMoudle::choseInDom);
|
|
||||||
connect(ui.pbtInDsm, &QPushButton::pressed, this, &TrainMoudle::choseInDsm);
|
|
||||||
connect(ui.pbtInLabel, &QPushButton::pressed, this, &TrainMoudle::choseInLabel);
|
|
||||||
connect(ui.pbtOutModel, &QPushButton::pressed, this, &TrainMoudle::choseOutModel);
|
|
||||||
|
|
||||||
connect(ui.pushButton_ok, &QPushButton::pressed, this, &TrainMoudle::readAndStart);
|
|
||||||
connect(ui.pushButton_cancel, &QPushButton::pressed, this, &TrainMoudle::pbCancel);
|
|
||||||
|
|
||||||
connect(ui.checkBoxMid, &QCheckBox::clicked, this, [=](bool checked) {
|
|
||||||
executeMid = checked;
|
|
||||||
if (!executeMid && !executeTrain)
|
|
||||||
ui.pushButton_ok->setEnabled(false);
|
|
||||||
else
|
|
||||||
ui.pushButton_ok->setEnabled(true);
|
|
||||||
});
|
|
||||||
connect(ui.checkBoxTrain, &QCheckBox::clicked, this, [=](bool checked) {
|
|
||||||
executeTrain = checked;
|
|
||||||
if (!executeMid && !executeTrain)
|
|
||||||
ui.pushButton_ok->setEnabled(false);
|
|
||||||
else
|
|
||||||
ui.pushButton_ok->setEnabled(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.progressBar->setTextVisible(true);
|
|
||||||
ui.progressBar->setRange(0, 100);
|
|
||||||
|
|
||||||
ui.lineEpoch1->setValidator(new QIntValidator(0, 999, this));
|
|
||||||
ui.lineEpoch2->setValidator(new QIntValidator(0, 999, this));
|
|
||||||
ui.lineEpoch1->setText("100");
|
|
||||||
ui.lineEpoch2->setText("100");
|
|
||||||
|
|
||||||
ui.pbtInModel->setFocus();
|
|
||||||
|
|
||||||
QFile qssFile(":/DEM_GeneVec/DEM_GeneVec.qss");
|
|
||||||
qssFile.open(QFile::ReadOnly); //以只读方式打开
|
|
||||||
if (qssFile.isOpen())
|
|
||||||
{
|
|
||||||
QString qss = QLatin1String(qssFile.readAll());
|
|
||||||
myWidget->setStyleSheet(qss);
|
|
||||||
qssFile.close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
qDebug() << "无法打开文件";
|
|
||||||
|
|
||||||
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
||||||
if (pluginsDir.cd("srsplugins\\DemModel"))
|
|
||||||
{
|
|
||||||
QString strConfigPath = pluginsDir.absoluteFilePath("dem_config.ini");
|
|
||||||
QFile f(strConfigPath);
|
|
||||||
if (f.exists())
|
|
||||||
{
|
|
||||||
ReadConfigHistoryPaths(strConfigPath);
|
|
||||||
f.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showWin)
|
|
||||||
myWidget->show();
|
|
||||||
|
|
||||||
return myWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrainMoudle::startWorkThread()
|
|
||||||
{
|
|
||||||
if (mWorkObject != nullptr)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mThread = new QThread();
|
|
||||||
mWorkObject = new WorkThreadObject();
|
|
||||||
mWorkObject->moveToThread(mThread);
|
|
||||||
connect(mThread, &QThread::finished, mThread, &QObject::deleteLater);
|
|
||||||
connect(mThread, &QThread::finished, mWorkObject, &QObject::deleteLater);
|
|
||||||
connect(mWorkObject, &WorkThreadObject::process, myWidget, [=](double val) {ui.progressBar->SetDoubleFormatValue(QString::fromLocal8Bit("进度"), val); });
|
|
||||||
connect(mWorkObject, &WorkThreadObject::addDataToMap, this, &TrainMoudle::addMap);
|
|
||||||
//connect(this, &TrainMoudle::killChildThread, mWorkObject, &WorkThreadObject::on_cancel);
|
|
||||||
|
|
||||||
connect(this, &TrainMoudle::start, mWorkObject, &WorkThreadObject::runTrainWork);
|
|
||||||
mThread->start();
|
|
||||||
}
|
|
||||||
//pbtDataset
|
|
||||||
//pbtValName
|
|
||||||
//pbtOutModel
|
|
||||||
void TrainMoudle::choseInModel()
|
|
||||||
{
|
|
||||||
QString inModel = QFileDialog::getOpenFileName(ui.pbtInModel, QString::fromLocal8Bit("选择输入模型文件路径"), "", "*.pth");
|
|
||||||
if (inModel != "")
|
|
||||||
ui.lineInModel->setText(inModel);
|
|
||||||
}
|
|
||||||
void TrainMoudle::choseInDom()
|
|
||||||
{
|
|
||||||
QString dataset = QFileDialog::getExistingDirectory(ui.pbtInDom, QString::fromLocal8Bit("选择输入DOM文件路径"), "");
|
|
||||||
if (dataset != "")
|
|
||||||
ui.lineInDom->setText(dataset);
|
|
||||||
}
|
|
||||||
void TrainMoudle::choseInDsm()
|
|
||||||
{
|
|
||||||
QString valName = QFileDialog::getExistingDirectory(ui.pbtInDsm, QString::fromLocal8Bit("选择输入Slope文件路径"), "");
|
|
||||||
if (valName != "")
|
|
||||||
ui.lineInDsm->setText(valName);
|
|
||||||
}
|
|
||||||
void TrainMoudle::choseInLabel()
|
|
||||||
{
|
|
||||||
QString valName = QFileDialog::getExistingDirectory(ui.pbtInLabel, QString::fromLocal8Bit("选择输入Label文件路径"), "");
|
|
||||||
if (valName != "")
|
|
||||||
ui.lineInLabel->setText(valName);
|
|
||||||
}
|
|
||||||
void TrainMoudle::choseOutModel()
|
|
||||||
{
|
|
||||||
QString outModel = QFileDialog::getExistingDirectory(ui.pbtOutModel, QString::fromLocal8Bit("选择输出模型文件路径"), "");
|
|
||||||
if (outModel != "")
|
|
||||||
ui.lineOutModel->setText(outModel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrainMoudle::ReadConfigHistoryPaths(QString strPath)
|
|
||||||
{
|
|
||||||
QSettings configIni(strPath, QSettings::IniFormat);
|
|
||||||
|
|
||||||
//打开标题为:[DemTrain] 的组,并读取出port字段的值
|
|
||||||
configIni.beginGroup("DemTrain");
|
|
||||||
|
|
||||||
ui.lineInModel->setText(configIni.value("RetrainModel").toString());
|
|
||||||
ui.lineInDom->setText(configIni.value("SrcDom").toString());
|
|
||||||
ui.lineInDsm->setText(configIni.value("SrcDsm").toString());
|
|
||||||
ui.lineInLabel->setText(configIni.value("SrcLabel").toString());
|
|
||||||
ui.lineOutModel->setText(configIni.value("TrainResult").toString());
|
|
||||||
|
|
||||||
configIni.endGroup();//关闭组
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrainMoudle::WriteConfigPaths(QString strPath)
|
|
||||||
{
|
|
||||||
QSettings configIni(strPath, QSettings::IniFormat);
|
|
||||||
configIni.setIniCodec("utf-8");
|
|
||||||
//打开标题为:[DemTrain] 的组
|
|
||||||
configIni.beginGroup("DemTrain");
|
|
||||||
|
|
||||||
//更新输入模型路径
|
|
||||||
QString temp = ui.lineInModel->text();
|
|
||||||
if (temp != "")
|
|
||||||
configIni.setValue("RetrainModel", temp);
|
|
||||||
//更新输入DOM路径
|
|
||||||
temp = ui.lineInDom->text();
|
|
||||||
if (temp != "")
|
|
||||||
configIni.setValue("SrcDom", temp);
|
|
||||||
//更新输入DSM路径
|
|
||||||
temp = ui.lineInDsm->text();
|
|
||||||
if (temp != "")
|
|
||||||
configIni.setValue("SrcDsm", temp);
|
|
||||||
//更新输入Label路径
|
|
||||||
temp = ui.lineInLabel->text();
|
|
||||||
if (temp != "")
|
|
||||||
configIni.setValue("SrcLabel", temp);
|
|
||||||
//更新输出结果路径
|
|
||||||
temp = ui.lineOutModel->text();
|
|
||||||
if (temp != "")
|
|
||||||
configIni.setValue("TrainResult", temp);
|
|
||||||
|
|
||||||
configIni.endGroup();//关闭组
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrainMoudle::addMap()
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon,
|
|
||||||
QString::fromLocal8Bit("运行结束"),
|
|
||||||
QString::fromLocal8Bit("结果文件生成路径\n") + ui.lineOutModel->text(),
|
|
||||||
QMessageBox::Ok, NULL);
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
mess.setButtonText(QMessageBox::Ok, QString::fromLocal8Bit("确认"));
|
|
||||||
int result = mess.exec();
|
|
||||||
//switch (result)
|
|
||||||
//{
|
|
||||||
//case QMessageBox::Ok:
|
|
||||||
// //string_list.append(ui.lineEdit_outras->text());
|
|
||||||
// //string_list.append(ui.lineEdit_outshp->text());
|
|
||||||
// //qDebug() << "----Yes:" << string_list;
|
|
||||||
// //openResultData(string_list);
|
|
||||||
// //emit addDataToCanvas(string_list);
|
|
||||||
// break;
|
|
||||||
//default:
|
|
||||||
// break;
|
|
||||||
//}
|
|
||||||
pbCancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrainMoudle::readAndStart()
|
|
||||||
{
|
|
||||||
QString inModel = ui.lineInModel->text();
|
|
||||||
QString inDOM = ui.lineInDom->text();
|
|
||||||
QString inDSM = ui.lineInDsm->text();
|
|
||||||
QString inLabel = ui.lineInLabel->text();
|
|
||||||
QString outModel = ui.lineOutModel->text();
|
|
||||||
|
|
||||||
ui.progressBar->SetDoubleFormatValue(QString::fromLocal8Bit("进度"), 0);
|
|
||||||
|
|
||||||
if (inModel == "" || inDOM == "" || inDSM == "" || inLabel == "" || outModel == "")
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请检查输入输出文件夹或数据"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QDir inDOMdir(inDOM);
|
|
||||||
if (!inDOMdir.exists())
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("DOM文件夹不存在"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QDir inDSMdir(inDSM);
|
|
||||||
if (!inDSMdir.exists())
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("Slope文件夹不存在"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QDir inLabeldir(inLabel);
|
|
||||||
if (!inLabeldir.exists())
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("Label文件夹不存在"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QDir outModeldir(outModel);
|
|
||||||
if (!outModeldir.exists())
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("模型输出文件夹不存在"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (executeMid && executeTrain)
|
|
||||||
qDebug() << "executeMid & executeTrain";
|
|
||||||
if (executeMid && (!executeTrain))
|
|
||||||
qDebug() << "executeMid, not executeTrain";
|
|
||||||
if ((!executeMid) && executeTrain)
|
|
||||||
{
|
|
||||||
//判断train文件夹下有无训练集文件夹
|
|
||||||
QDir dirImage(outModel + "/Images");
|
|
||||||
QDir dirLabel(outModel + "/Labels");
|
|
||||||
if (!dirImage.exists() || !dirLabel.exists())
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"),
|
|
||||||
QString::fromLocal8Bit("未找到训练集文件夹\n确保Images和Labels在以下路径中: \n") + outModel);
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//判断文件是否匹配
|
|
||||||
QStringList imgList = getAllFiles(outModel + "/Images", "tif");
|
|
||||||
QStringList labelList = getAllFiles(outModel + "/Labels", "tif");
|
|
||||||
if (imgList.size() == 0 || labelList.size() == 0)
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"),
|
|
||||||
QString::fromLocal8Bit("训练集文件夹内为空"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (imgList.size() != labelList.size())
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"),
|
|
||||||
QString::fromLocal8Bit("训练集Images、Labels文件夹内文件不匹配"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ui.lineEpoch1->text() == "" || ui.lineEpoch2->text() == "")
|
|
||||||
{
|
|
||||||
QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请输入正确的训练轮数"));
|
|
||||||
mess.setWindowFlags(Qt::Drawer);
|
|
||||||
int result = mess.exec();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString epoch1 = ui.lineEpoch1->text();
|
|
||||||
QString epoch2 = ui.lineEpoch2->text();
|
|
||||||
|
|
||||||
if (mThread == nullptr)
|
|
||||||
{
|
|
||||||
qDebug() << "--startThread";
|
|
||||||
startWorkThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit start(inModel, inDOM, inDSM, inLabel, outModel, executeMid, executeTrain, epoch1, epoch2);
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList TrainMoudle::getAllFiles(QString path, QString fileType)
|
|
||||||
{
|
|
||||||
QDir dir(path);
|
|
||||||
if (!dir.exists())
|
|
||||||
return QStringList();
|
|
||||||
dir.setFilter(QDir::Files | QDir::NoSymLinks);
|
|
||||||
QFileInfoList list = dir.entryInfoList();
|
|
||||||
|
|
||||||
int file_count = list.count();
|
|
||||||
if (file_count <= 0)
|
|
||||||
return QStringList();
|
|
||||||
QStringList files;
|
|
||||||
for (int i = 0; i < file_count; i++)
|
|
||||||
{
|
|
||||||
QFileInfo file_info = list.at(i);
|
|
||||||
QString suffix = file_info.suffix();
|
|
||||||
if (QString::compare(suffix, QString(fileType), Qt::CaseInsensitive) == 0)
|
|
||||||
{
|
|
||||||
QString absolute_file_path = file_info.absoluteFilePath();
|
|
||||||
files.append(absolute_file_path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return files;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TrainMoudle::pbCancel()
|
|
||||||
{
|
|
||||||
delete myWidget;//调起&QDialog::destroyed
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QtWidgets/QDialog>
|
|
||||||
#include <QFileDialog>
|
|
||||||
#include <QMetaType>
|
|
||||||
#include <QDialog>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QPushButton>
|
|
||||||
#include <QString>
|
|
||||||
#include <QThread>
|
|
||||||
#include <QVector>
|
|
||||||
#include <QIntValidator>
|
|
||||||
|
|
||||||
#include "ui_DEM_GeneVec.h"
|
|
||||||
#include "ThreadObject.h"
|
|
||||||
#include "SrsMainPluginInterFace.h"
|
|
||||||
|
|
||||||
#include "gdal_priv.h"
|
|
||||||
//#include "gdal_alg_priv.h"
|
|
||||||
|
|
||||||
class TrainMoudle : public SrsMainInterface
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_INTERFACES(SrsMainInterface)
|
|
||||||
Q_PLUGIN_METADATA(IID MainInterface_iid)
|
|
||||||
|
|
||||||
public:
|
|
||||||
TrainMoudle();
|
|
||||||
~TrainMoudle();
|
|
||||||
|
|
||||||
virtual QString PannelName() override;
|
|
||||||
virtual QString CategoryName() override;
|
|
||||||
|
|
||||||
virtual QString EnglishName() override;
|
|
||||||
virtual QString ChineseName() override;
|
|
||||||
virtual QString Information() override;
|
|
||||||
virtual QString IconPath() override;
|
|
||||||
virtual QWidget* CenterWidget() override;
|
|
||||||
|
|
||||||
void startWorkThread();
|
|
||||||
|
|
||||||
//读json文件,获取历史存储的路径
|
|
||||||
void ReadConfigHistoryPaths(QString strPath);
|
|
||||||
//保存本次打开的路径到json文件
|
|
||||||
void WriteConfigPaths(QString strPath);
|
|
||||||
|
|
||||||
QStringList getAllFiles(QString path, QString fileType);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void choseInModel();
|
|
||||||
void choseInDom();
|
|
||||||
void choseInDsm();
|
|
||||||
void choseInLabel();
|
|
||||||
void choseOutModel();
|
|
||||||
|
|
||||||
void addMap();
|
|
||||||
//pushbutton_OK
|
|
||||||
void readAndStart();
|
|
||||||
void pbCancel();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void start(QString inModel, QString dom, QString dsm, QString label, QString outModel, bool mid, bool train, QString epoch1, QString epoch2);
|
|
||||||
void killChildThread();
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ui::DEM_GeneVecClass ui;
|
|
||||||
|
|
||||||
QDialog* myWidget = nullptr;
|
|
||||||
|
|
||||||
WorkThreadObject* mWorkObject = nullptr;
|
|
||||||
|
|
||||||
QThread* mThread = nullptr;
|
|
||||||
|
|
||||||
bool executeMid = true;
|
|
||||||
bool executeTrain = true;
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<RCC>
|
|
||||||
<qresource prefix="/DEM_GeneVec">
|
|
||||||
<file>resources/dem_vec.svg</file>
|
|
||||||
<file>DEM_GeneVec.qss</file>
|
|
||||||
</qresource>
|
|
||||||
</RCC>
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
QProgressBar#progressBar {
|
|
||||||
border:0px solid white;
|
|
||||||
text-align:center;
|
|
||||||
color:black;
|
|
||||||
}
|
|
||||||
QProgressBar#progressBar:chunk {
|
|
||||||
background-color:#3FABBA;
|
|
||||||
width:20px;
|
|
||||||
}
|
|
||||||
QProgressBar#progressBar QLineEdit {
|
|
||||||
border:none;
|
|
||||||
color:black;
|
|
||||||
padding-left:5px;
|
|
||||||
font-size:16px;
|
|
||||||
background-color:transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
QLabel{
|
|
||||||
color:black;
|
|
||||||
font-family:'Microsoft YaHei';
|
|
||||||
font-size:12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*----QPushButtonÑùʽ±í*/
|
|
||||||
#pushButton_ok, #pushButton_cancel, #pbtInModel, #pbtInDom, #pbtInDsm, #pbtInLabel, #pbtOutModel{
|
|
||||||
font-family:'Microsoft YaHei';
|
|
||||||
font-size:12px;
|
|
||||||
background-color: #ffffff;
|
|
||||||
border: 1px solid #dcdfe6;
|
|
||||||
padding: 2px;
|
|
||||||
border-radius: 5px;
|
|
||||||
max-height:20px;
|
|
||||||
}
|
|
||||||
#pushButton_ok, #pushButton_cancel{
|
|
||||||
min-width:36px;
|
|
||||||
}
|
|
||||||
#pushButton_ok:hover, #pushButton_cancel:hover, #pbtInModel:hover, #pbtInDom:hover, #pbtInDsm:hover,#pbtInLabel:hover,#pbtOutModel:hover{
|
|
||||||
background-color: #ecf5ff;
|
|
||||||
color: #409eff;
|
|
||||||
}
|
|
||||||
#pushButton_ok:pressed, #pushButton_cancel:pressed, #pbtInModel:pressed, #pbtInDom:pressed, #pbtInDsm:pressed,#pbtInLabel:pressed,#pbtOutModel:pressed{
|
|
||||||
border: 1px solid #3a8ee6;
|
|
||||||
color: #409eff;
|
|
||||||
}
|
|
||||||
#pushButton_ok:checked, #pushButton_cancel:checked, #pbtInModel:checked, #pbtInDom:checked, #pbtInDsm:checked,#pbtInLabel:checked,#pbtOutModel:checked{
|
|
||||||
border: 1px solid #3a8ee6;
|
|
||||||
color: #409eff;
|
|
||||||
}
|
|
||||||
#pushButton_ok:focus, #pushButton_cancel:focus, #pbtInModel:focus, #pbtInDom:focus, #pbtInDsm:focus,#pbtInLabel:focus,#pbtOutModel:focus{
|
|
||||||
border: 1px solid #3a8ee6;
|
|
||||||
color: #409eff;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*----QLineEditÑùʽ*/
|
|
||||||
#lineInModel, #lineInDsm, #lineInDom, #lineOutModel, #lineInLabel, #lineEpoch1, #lineEpoch2{
|
|
||||||
border:0px;
|
|
||||||
border-bottom: 1px solid #B3B3B3;
|
|
||||||
font-family:'Microsoft YaHei';
|
|
||||||
font-size:12px;
|
|
||||||
background-color:transparent;
|
|
||||||
}
|
|
||||||
#lineInModel:hover, #lineInDsm:hover, #lineInDom:hover, #lineOutModel:hover, #lineInLabel:hover, #lineEpoch1:hover, #lineEpoch2:hover{
|
|
||||||
border-bottom: 2px solid #66A3FF;
|
|
||||||
}
|
|
||||||
#lineInModel:focus, #lineInDsm:focus, #lineInDom:focus, #lineOutModel:focus, #lineInLabel:focus, #lineEpoch1:focus, #lineEpoch2:focus{
|
|
||||||
border-bottom: 2px solid #7666FF;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*QCheckBox{
|
|
||||||
background:transparent;
|
|
||||||
border:0px;
|
|
||||||
color:black;
|
|
||||||
min-height: 20px;
|
|
||||||
min-width: 60px;
|
|
||||||
}
|
|
||||||
QCheckBox::disabled{
|
|
||||||
background:transparent;
|
|
||||||
border:0px;
|
|
||||||
color:#202020;
|
|
||||||
min-height: 20px;
|
|
||||||
min-width: 60px;
|
|
||||||
}
|
|
||||||
QCheckBox::indicator{
|
|
||||||
margin-right:-10px;
|
|
||||||
}
|
|
||||||
QCheckBox::indicator:checked{
|
|
||||||
image: url(:/RemoteSensingProcess/Resources/checkbox_checked.svg);
|
|
||||||
width:25px;
|
|
||||||
}
|
|
||||||
QCheckBox::indicator:unchecked{
|
|
||||||
image: url(:/RemoteSensingProcess/Resources/checkbox_unchecked.svg);
|
|
||||||
width:25px;
|
|
||||||
}
|
|
||||||
QCheckBox::indicator:disabled{
|
|
||||||
image: url(:/RemoteSensingProcess/Resources/checkbox_disabled.svg);
|
|
||||||
width:25px;
|
|
||||||
}*/
|
|
||||||
@@ -1,485 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0">
|
|
||||||
<class>DEM_GeneVecClass</class>
|
|
||||||
<widget class="QDialog" name="DEM_GeneVecClass">
|
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>550</width>
|
|
||||||
<height>320</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>550</width>
|
|
||||||
<height>320</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>550</width>
|
|
||||||
<height>320</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="windowTitle">
|
|
||||||
<string/>
|
|
||||||
</property>
|
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
|
||||||
<item row="0" column="0">
|
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInDom">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="1">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="lineEpoch1">
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>100</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>解冻训练次数</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QLineEdit" name="lineEpoch2">
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>100</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineOutModel">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtInModel">
|
|
||||||
<property name="text">
|
|
||||||
<string>选择文件</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInLabel">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="4" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtOutModel">
|
|
||||||
<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="0" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInModel"/>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<widget class="QLineEdit" name="lineInDsm">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</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="1" column="0">
|
|
||||||
<widget class="QLabel" name="label">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入DOM文件路径</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QLabel" name="label_2">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入DSM文件路径</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtInDom">
|
|
||||||
<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_mask">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入Label文件路径</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="2">
|
|
||||||
<widget class="QPushButton" name="pbtInDsm">
|
|
||||||
<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_mask_2">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输出模型文件路径</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="0" column="0">
|
|
||||||
<widget class="QLabel" name="label_3">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>输入初始模型文件路径</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="5" column="0">
|
|
||||||
<widget class="QLabel" name="label_4">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>110</width>
|
|
||||||
<height>16777215</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>冻结训练次数</string>
|
|
||||||
</property>
|
|
||||||
<property name="alignment">
|
|
||||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="sizeConstraint">
|
|
||||||
<enum>QLayout::SetDefaultConstraint</enum>
|
|
||||||
</property>
|
|
||||||
<property name="leftMargin">
|
|
||||||
<number>100</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="checkBoxMid">
|
|
||||||
<property name="text">
|
|
||||||
<string>生成训练集、验证集</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QCheckBox" name="checkBoxTrain">
|
|
||||||
<property name="text">
|
|
||||||
<string>模型训练</string>
|
|
||||||
</property>
|
|
||||||
<property name="checked">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pushButton_ok">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>确定</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer_2">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeType">
|
|
||||||
<enum>QSizePolicy::Fixed</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>10</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pushButton_cancel">
|
|
||||||
<property name="text">
|
|
||||||
<string>取消</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
|
||||||
<item>
|
|
||||||
<widget class="CProgressBar" name="progressBar">
|
|
||||||
<property name="value">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
|
||||||
<customwidgets>
|
|
||||||
<customwidget>
|
|
||||||
<class>CProgressBar</class>
|
|
||||||
<extends>QProgressBar</extends>
|
|
||||||
<header>CProgressBar.h</header>
|
|
||||||
</customwidget>
|
|
||||||
</customwidgets>
|
|
||||||
<tabstops>
|
|
||||||
<tabstop>lineInModel</tabstop>
|
|
||||||
<tabstop>pbtInModel</tabstop>
|
|
||||||
<tabstop>lineInDom</tabstop>
|
|
||||||
<tabstop>pbtInDom</tabstop>
|
|
||||||
<tabstop>lineInDsm</tabstop>
|
|
||||||
<tabstop>pbtInDsm</tabstop>
|
|
||||||
<tabstop>lineInLabel</tabstop>
|
|
||||||
<tabstop>pbtInLabel</tabstop>
|
|
||||||
<tabstop>lineOutModel</tabstop>
|
|
||||||
<tabstop>pbtOutModel</tabstop>
|
|
||||||
<tabstop>pushButton_ok</tabstop>
|
|
||||||
<tabstop>pushButton_cancel</tabstop>
|
|
||||||
</tabstops>
|
|
||||||
<resources>
|
|
||||||
<include location="DEM_GeneVec.qrc"/>
|
|
||||||
</resources>
|
|
||||||
<connections/>
|
|
||||||
</ui>
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
#include <QProcess>
|
|
||||||
#include <QDir>
|
|
||||||
#include <QApplication>
|
|
||||||
#include <QDebug>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
|
|
||||||
#include "DEM_GeneVec.h"
|
|
||||||
#include "ThreadObject.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
WorkThreadObject::WorkThreadObject(QObject* parent) :QObject(parent)
|
|
||||||
{
|
|
||||||
qRegisterMetaType<std::function<void(double)> >("std::function<void(double)>");
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkThreadObject::~WorkThreadObject()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkThreadObject::runTrainWork(QString inModel, QString dom, QString dsm, QString label, QString outModel, bool mid, bool train, QString epoch1, QString epoch2)
|
|
||||||
{
|
|
||||||
QString str = QString("%1->%2,thread id:%3").arg(__FILE__).arg(__FUNCTION__).arg((int)QThread::currentThreadId());
|
|
||||||
qDebug() << str;
|
|
||||||
|
|
||||||
QDir pluginsDir = QDir(qApp->applicationDirPath());
|
|
||||||
if (!pluginsDir.cd("models\\envs"))
|
|
||||||
{
|
|
||||||
qDebug() << "no folder models\\envs";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
QString exeDirName = pluginsDir.absoluteFilePath("train_4c_vegetaion.exe");
|
|
||||||
|
|
||||||
QString inDom = " --dom_path "+ dom + "/";
|
|
||||||
QString inDsm = " --dsm_path " + dsm + "/";
|
|
||||||
QString inLabel = " --label_path " + label + "/";
|
|
||||||
QString trainedModel = " --retrained_model " + inModel;
|
|
||||||
QString save_model = " --save_model " + outModel + "/";
|
|
||||||
QString strMid, strTrain;
|
|
||||||
if (mid)
|
|
||||||
strMid = " --exe_mid True ";
|
|
||||||
else
|
|
||||||
strMid = " --exe_mid False ";
|
|
||||||
if (train)
|
|
||||||
strTrain = " --exe_train True";
|
|
||||||
else
|
|
||||||
strTrain = " --exe_train False";
|
|
||||||
QString strEpoch1, strEpoch2;
|
|
||||||
strEpoch1 = " --epoch1 " + epoch1;
|
|
||||||
strEpoch2 = " --epoch2 " + epoch2;
|
|
||||||
|
|
||||||
//QString CUDA = " --CUDA False";
|
|
||||||
QString ss = exeDirName + inDom + inDsm + inLabel + trainedModel + save_model+ strMid + strTrain + strEpoch1 + strEpoch2;// + CUDA
|
|
||||||
qDebug() << ss;
|
|
||||||
QProcess* pProces = new QProcess(this);
|
|
||||||
connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(on_read()));
|
|
||||||
|
|
||||||
pProces->start(ss);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkThreadObject::on_read()
|
|
||||||
{
|
|
||||||
mProces = (QProcess*)sender();
|
|
||||||
QString output = QString::fromLocal8Bit(mProces->readAllStandardOutput());
|
|
||||||
//qDebug() << "out:" << output;
|
|
||||||
if (output.toDouble() > 0)
|
|
||||||
{
|
|
||||||
qDebug() << "exe out:" << output.toDouble();
|
|
||||||
emit process(output.toDouble());
|
|
||||||
if (output.toDouble() == 100.0)
|
|
||||||
{
|
|
||||||
emit addDataToMap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
qDebug() << "Unresolved exe out:" << output;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WorkThreadObject::on_cancel()
|
|
||||||
{
|
|
||||||
QString str = QString("--1.%1->%2,thread id:%3").arg(__FILE__).arg(__FUNCTION__).arg((int)QThread::currentThreadId());
|
|
||||||
qDebug() << str;
|
|
||||||
|
|
||||||
if (mProces == nullptr)
|
|
||||||
{
|
|
||||||
qDebug() << "--mProces null";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QString KillStr = "taskkill /f /im train_4c_vegetaion.exe";
|
|
||||||
mProces->startDetached(KillStr);
|
|
||||||
qDebug() << "--kill Proces";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
#ifndef THREADOBJECT_H
|
|
||||||
#define THREADOBJECT_H
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
#include <QMessageBox>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QThread>
|
|
||||||
#include <QVector>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
//#include "MultiQProcess.h"
|
|
||||||
|
|
||||||
//#include "qtclasslibrary1_global.h"
|
|
||||||
#include "SrsMainPluginInterFace.h"
|
|
||||||
#include "ui_DEM_GeneVec.h"
|
|
||||||
//#include "Extract.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class TrainMoudle;
|
|
||||||
|
|
||||||
class WorkThreadObject :public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
WorkThreadObject(QObject* parent = NULL);
|
|
||||||
~WorkThreadObject();
|
|
||||||
|
|
||||||
void on_cancel();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void process(double value);
|
|
||||||
void addDataToMap();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
//void RunWork(QString landsat_file, QString gf_file, QString tvdi_file);
|
|
||||||
//void RunWork(QString file1, QString file2, QString file_out, std::function<void(int)>progressCallback);
|
|
||||||
//void RunWork(QString file1, QString file2, QString file_out);
|
|
||||||
void runTrainWork(QString inModel, QString dom, QString dsm, QString label, QString outModel, bool mid, bool train, QString epoch1, QString epoch2);
|
|
||||||
void on_read();
|
|
||||||
|
|
||||||
private:
|
|
||||||
QProcess* mProces = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#include "DEM_GeneVec.h"
|
|
||||||
#include <QtWidgets/QApplication>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
QApplication a(argc, argv);
|
|
||||||
|
|
||||||
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());
|
|
||||||
|
|
||||||
TrainMoudle w;
|
|
||||||
w.CenterWidget()->show();
|
|
||||||
return a.exec();
|
|
||||||
}
|
|
||||||
@@ -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="1650520802998" class="icon" viewBox="0 0 1132 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5053" width="28.7421875" height="26" 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="M1131.403629 583.018705c1.939725-47.361608-39.010016-64.495842-39.010017-64.495842l-226.408963-105.391702s0.538812-182.926804 0-232.120374a73.440128 73.440128 0 0 0-40.949741-66.651092S645.82591 35.80085 592.645128 6.974387c-27.694956-15.086747-56.5753 0-56.5753 0S367.529315 89.035513 315.480039 112.312208c-47.577133 21.229208-46.876677 66.651092-46.876677 66.651092V411.891892S120.160551 482.476314 57.873839 509.524696C-1.71881 535.333809 0.005389 589.592216 0.005389 589.592216s0.538812 185.890272 0 234.275623c-0.538812 52.264801 42.350653 68.806341 42.350654 68.806342s143.862906 80.06752 212.669247 114.713156c50.91777 25.539707 83.946969 0.646575 83.946969 0.646575l226.085675-122.525936s178.777948 92.67573 220.859195 121.879361c48.816402 33.729655 82.007245 5.65753 82.007245 5.65753s199.198938-111.156994 230.288412-126.836435c33.298605-16.703184 33.298605-58.030094 33.298605-58.030094s-2.047487-197.905788-0.107762-245.159633zM299.85448 675.371147l-206.903955-99.895816 206.903955-99.949696 210.783404 98.925953-210.783404 100.919559z m232.282018 148.335049l-199.091175 109.594438v-195.696657l199.091175-94.561573v180.663792z m32.705911-537.357589L340.911983 181.010787l223.930426-108.840101 232.766949 108.840101-232.766949 105.391702z m35.66938 64.38808l197.043688-94.561573v159.057415L600.511789 512.110995V350.790568z m235.137723 324.63446l-205.82633-99.895816 197.151451-99.949696 214.662853 99.949696-205.987974 99.895816z m227.378825 154.800797l-195.211725 103.12869v-195.696657l195.211725-94.561573v187.12954z" p-id="5054" fill="#2c2c2c"></path></svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,548 @@
|
|||||||
|
import os
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
import tifIO
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
import math
|
||||||
|
from math import floor
|
||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
import qgis
|
||||||
|
from qgis.core import * # attach main QGIS library
|
||||||
|
from qgis.utils import * # attach main python library
|
||||||
|
from qgis.analysis import *
|
||||||
|
from osgeo import gdal
|
||||||
|
|
||||||
|
#相对路径
|
||||||
|
qgis_path = sys.executable
|
||||||
|
process_path = qgis_path.split('bin')[0]+'apps\\qgis-ltr\\python\\plugins'
|
||||||
|
# process_path = 'D:/code/RsSurvey/RsSurvey_Build/x64/Release/QGIS_3.22.8/apps/qgis-ltr/python/plugins/'
|
||||||
|
if os.path.exists(process_path):
|
||||||
|
print("exists path:"+process_path)
|
||||||
|
sys.stdout.flush()
|
||||||
|
else:
|
||||||
|
print("fine no path:"+process_path)
|
||||||
|
sys.stdout.flush()
|
||||||
|
sys.path.append(process_path)
|
||||||
|
|
||||||
|
qgs = QgsApplication([], False)
|
||||||
|
qgs.initQgis()
|
||||||
|
|
||||||
|
import processing
|
||||||
|
from processing.core.Processing import Processing
|
||||||
|
Processing.initialize()
|
||||||
|
|
||||||
|
|
||||||
|
#添加参数
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--in_holedem', type=str,
|
||||||
|
default='D:/A_testdata/dianli_test/00yanshou/data_train_dem/05veg_maskedTiff/',
|
||||||
|
help='输入数据,经过裁剪的dem')
|
||||||
|
parser.add_argument('--work_space', type=str,
|
||||||
|
default='D:/A_testdata/dianli_test/00yanshou/data_train_dem/06veg_dataFill_workspace/',
|
||||||
|
help='用于填补时存放中间路径及结果文件')
|
||||||
|
parser.add_argument('--scale', type=float,
|
||||||
|
default=0.1,
|
||||||
|
help='外接矩形放大的比例')
|
||||||
|
parser.add_argument('--win_size', type=int,
|
||||||
|
default=3,
|
||||||
|
help='空洞外扩像素')
|
||||||
|
opt = parser.parse_args()
|
||||||
|
in_holedem = opt.in_holedem
|
||||||
|
work_space = opt.work_space
|
||||||
|
scale = opt.scale
|
||||||
|
win_size = opt.win_size
|
||||||
|
'''
|
||||||
|
txt文件名以in_holedem中dem数据文件名命名
|
||||||
|
内容以singlehole文件开始,包含位置信息
|
||||||
|
subname, lt_x,lt_y,rb_x,rb_y
|
||||||
|
tktk130_mask_id_1_hw_83_106.tif,1364,1950,1470,2033
|
||||||
|
'''
|
||||||
|
out_txt_folder = 'txt_singlehole/'
|
||||||
|
singlehole_folder = 'dem_singlehole/'# 保存单个空洞
|
||||||
|
|
||||||
|
ras2pot_folder = 'raster2points/'
|
||||||
|
ras2potpro_folder = 'raster2points_pro/'
|
||||||
|
tinmesh_folder = 'TINMesh/'
|
||||||
|
potfrommesh_folder = 'pointfrommesh/'
|
||||||
|
potfrommeshfloat_folder = 'pointfrommeshfloat/'
|
||||||
|
filltif_folder = 'tif/'
|
||||||
|
filltifpro_folder = 'tif_pro/'
|
||||||
|
|
||||||
|
out_fulltif_folder = 'out_result/'# 填补并放回的整图结果
|
||||||
|
|
||||||
|
print("win_size:%d,scale:%.4f" % (win_size, scale))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def findHoles(in_demfolder, out_singlehole, txt_folder):
|
||||||
|
count = 0
|
||||||
|
ev = floor(win_size / 2)
|
||||||
|
|
||||||
|
if os.path.exists(txt_folder):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(txt_folder)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print("error {}".format(str(e)))
|
||||||
|
sys.stdout.flush()
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(txt_folder)
|
||||||
|
|
||||||
|
if os.path.exists(out_singlehole):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_singlehole)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print("error {}".format(str(e)))
|
||||||
|
sys.stdout.flush()
|
||||||
|
print(-1)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_singlehole)
|
||||||
|
|
||||||
|
dem_list = []
|
||||||
|
src_list = os.listdir(in_demfolder)
|
||||||
|
for f in src_list:
|
||||||
|
if os.path.splitext(f)[1] == '.tif' or os.path.splitext(f)[1] == '.TIF':
|
||||||
|
dem_list.append(f)
|
||||||
|
|
||||||
|
for imgfile in dem_list:
|
||||||
|
filename = os.path.splitext(imgfile)[0]
|
||||||
|
txtname = filename + '.txt'
|
||||||
|
txt_route = os.path.join(txt_folder, txtname)
|
||||||
|
|
||||||
|
file_handle = open(txt_route, mode='w')
|
||||||
|
# file_handle.writelines(['文件名,左上角列号,左上角行号,右下角列号,右下角行号\n'])
|
||||||
|
|
||||||
|
dem_route = os.path.join(in_demfolder, imgfile)
|
||||||
|
proj, geotrans, dem_img, width, height = tifIO.ReadTif(dem_route) # c,h,w
|
||||||
|
origin = cv2.imread(dem_route, cv2.IMREAD_UNCHANGED)
|
||||||
|
|
||||||
|
img = origin.copy()
|
||||||
|
# 二值化,转换类型
|
||||||
|
ret2, binary = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY_INV)
|
||||||
|
thresh_image = binary.astype(np.uint8)
|
||||||
|
|
||||||
|
# 连通域分析
|
||||||
|
contours, hierarchy = cv2.findContours(thresh_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) # 检索最外轮廓
|
||||||
|
# contours, hierarchy = cv2.findContours(thresh_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) # 检索所有轮廓
|
||||||
|
|
||||||
|
for i in range(0, len(contours)):
|
||||||
|
thisgeo = geotrans.copy()
|
||||||
|
lt_x, lt_y, w, h = cv2.boundingRect(contours[i]) # 最小包络矩形的四至
|
||||||
|
# 矩形外扩,最小外扩2像元,保证空洞再小也能外扩
|
||||||
|
w_ex = floor(w * scale / 2) if floor(w * scale / 2) > 2 else 2
|
||||||
|
h_ex = floor(h * scale / 2) if floor(h * scale / 2) > 2 else 2
|
||||||
|
if lt_x - w_ex >= 0:
|
||||||
|
new_lt_x = lt_x - w_ex
|
||||||
|
else:
|
||||||
|
new_lt_x = 0
|
||||||
|
|
||||||
|
if lt_y - h_ex >= 0:
|
||||||
|
new_lt_y = lt_y - h_ex
|
||||||
|
else:
|
||||||
|
new_lt_y = 0
|
||||||
|
|
||||||
|
if lt_x + w + w_ex <= width:
|
||||||
|
new_rb_x = lt_x + w + w_ex
|
||||||
|
else:
|
||||||
|
new_rb_x = width
|
||||||
|
|
||||||
|
if lt_y + h + h_ex <= height:
|
||||||
|
new_rb_y = lt_y + h + h_ex
|
||||||
|
else:
|
||||||
|
new_rb_y = height
|
||||||
|
|
||||||
|
this_hole = img[new_lt_y: new_rb_y, new_lt_x: new_rb_x]
|
||||||
|
flag = np.zeros(this_hole.shape, dtype=int)
|
||||||
|
flag[this_hole > -9999] = 1 # 如果低于-9999,arcgis中nodata是极小的负数
|
||||||
|
|
||||||
|
# 洞不扩大
|
||||||
|
# this_hole[this_hole <=0] = np.nan
|
||||||
|
|
||||||
|
# 洞外扩
|
||||||
|
new_w = new_rb_x - new_lt_x
|
||||||
|
new_h = new_rb_y - new_lt_y
|
||||||
|
for c in range(0, new_w):
|
||||||
|
for r in range(0, new_h):
|
||||||
|
if flag[r, c] == 0:
|
||||||
|
for win_c in range(win_size):
|
||||||
|
for win_r in range(win_size):
|
||||||
|
tempr = r + win_r - ev
|
||||||
|
tempc = c + win_c - ev
|
||||||
|
if tempr >= 0 and tempr < new_h and tempc >= 0 and tempc < new_w:
|
||||||
|
this_hole[tempr, tempc] = np.nan
|
||||||
|
|
||||||
|
lon = thisgeo[0] + thisgeo[1] * new_lt_x
|
||||||
|
lat = thisgeo[3] + thisgeo[5] * new_lt_y
|
||||||
|
|
||||||
|
thisgeo[0] = lon
|
||||||
|
thisgeo[3] = lat
|
||||||
|
|
||||||
|
# fileroutesub =filename+ '_%d.tif' % count
|
||||||
|
fileroutesub = filename + '_id_%d_hw_%d_%d' % (i + 1, new_h, new_w) + '.tif'
|
||||||
|
fileroute = os.path.join(out_singlehole, fileroutesub)
|
||||||
|
this_hole[np.where(this_hole == 0.0)] = np.nan
|
||||||
|
tifIO.writeTif(fileroute, proj, thisgeo, this_hole) # 投影信息不对
|
||||||
|
|
||||||
|
# 坐标从【0,0】开始计,左上坐标【x,y】,右下坐标[x+w-1,y+h-1]
|
||||||
|
file_handle.writelines([fileroutesub, ',', str(new_lt_x), ',',
|
||||||
|
str(new_lt_y), ',', str(new_rb_x), ',', str(new_rb_y), '\n'])
|
||||||
|
count = count + 1
|
||||||
|
file_handle.close()
|
||||||
|
|
||||||
|
|
||||||
|
def confirmWorkspaceClear(rootPath):
|
||||||
|
out_path_raster2points = os.path.join(rootPath, ras2pot_folder)
|
||||||
|
if os.path.exists(out_path_raster2points):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_raster2points)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_raster2points)
|
||||||
|
print(4)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
out_path_raster2points_pro = os.path.join(rootPath, ras2potpro_folder)
|
||||||
|
if os.path.exists(out_path_raster2points_pro):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_raster2points_pro)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_raster2points_pro)
|
||||||
|
print(5)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
out_path_TINMesh = os.path.join(rootPath, tinmesh_folder)
|
||||||
|
if os.path.exists(out_path_TINMesh):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_TINMesh)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_TINMesh)
|
||||||
|
print(6)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
out_path_pointfrommesh = os.path.join(rootPath, potfrommesh_folder)
|
||||||
|
if os.path.exists(out_path_pointfrommesh):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_pointfrommesh)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_pointfrommesh)
|
||||||
|
print(7)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
out_path_pointfrommeshfloat = os.path.join(rootPath, potfrommeshfloat_folder)
|
||||||
|
if os.path.exists(out_path_pointfrommeshfloat):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_pointfrommeshfloat)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_pointfrommeshfloat)
|
||||||
|
print(8)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
out_path_tif = os.path.join(rootPath, filltif_folder)
|
||||||
|
if os.path.exists(out_path_tif):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_tif)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_tif)
|
||||||
|
print(9)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
out_path_tif_pro = os.path.join(rootPath, filltifpro_folder)
|
||||||
|
if os.path.exists(out_path_tif_pro):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path_tif_pro)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path_tif_pro)
|
||||||
|
print(10)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def raster2points(fileName):
|
||||||
|
inFile=work_space+singlehole_folder+fileName
|
||||||
|
# 获取文件信息
|
||||||
|
rlayer = QgsRasterLayer(inFile, "SRTM layer name")
|
||||||
|
tif_crs =rlayer.crs().toWkt()
|
||||||
|
if not rlayer.isValid():
|
||||||
|
print("图层加载失败!")
|
||||||
|
dataset = gdal.Open(inFile)
|
||||||
|
gt = dataset.GetGeoTransform()
|
||||||
|
Xmin = gt[0]
|
||||||
|
Ymin = gt[3]
|
||||||
|
width = dataset.RasterXSize
|
||||||
|
height = dataset.RasterYSize
|
||||||
|
Xmax = gt[0] + width*gt[1] + height*gt[2]
|
||||||
|
Ymax = gt[3] + width*gt[4] + height*gt[5]
|
||||||
|
extent = [Xmin,Xmax,min(Ymin,Ymax),max(Ymin,Ymax)]
|
||||||
|
cellHeight = math.fabs(gt[1])
|
||||||
|
cellWidth = math.fabs(gt[5])
|
||||||
|
|
||||||
|
# #准备进行处理
|
||||||
|
# aid='saga:rastervaluestopoints'
|
||||||
|
out_path = os.path.join(work_space,ras2pot_folder)
|
||||||
|
outFile=out_path+fileName[0:fileName.index('.')]+'.geojson'
|
||||||
|
# p = {
|
||||||
|
# 'GRIDS': [inFile],
|
||||||
|
# 'NODATA': True,
|
||||||
|
# 'POLYGONS': None,
|
||||||
|
# 'SHAPES': outFile,
|
||||||
|
# 'TYPE': 0}
|
||||||
|
# processing.run(aid, p)
|
||||||
|
print(qgis_path)
|
||||||
|
exe_path= qgis_path.split('python.exe')[0]+"saga_cmd.exe"
|
||||||
|
print(exe_path)
|
||||||
|
cammand_line=exe_path+" shapes_grid 3 -GRIDS {} -POLYGONS None -NODATA 1 -SHAPES {} -TYPE 0".format(inFile,outFile)# --flags[qr]
|
||||||
|
process_status=subprocess.call(cammand_line)
|
||||||
|
if 0!=process_status:
|
||||||
|
print("error ")
|
||||||
|
|
||||||
|
pro_aid = 'native:assignprojection'
|
||||||
|
proFile = work_space+ras2potpro_folder+fileName[0:fileName.index('.')]+'.geojson'
|
||||||
|
pro_p = {
|
||||||
|
'CRS': QgsCoordinateReferenceSystem('EPSG:4546'),
|
||||||
|
'INPUT': outFile,
|
||||||
|
'OUTPUT': proFile,
|
||||||
|
}
|
||||||
|
processing.run(pro_aid, pro_p)
|
||||||
|
return fileName[0:fileName.index('.')]+'.geojson', cellHeight, cellWidth, tif_crs, extent
|
||||||
|
|
||||||
|
|
||||||
|
def points2mesh(fileName,tif_crs):
|
||||||
|
aid='native:tinmeshcreation'
|
||||||
|
inFile=work_space+ras2potpro_folder+fileName
|
||||||
|
optFile=work_space+tinmesh_folder+fileName[0:fileName.index('.')]+'.file'
|
||||||
|
p={ 'CRS_OUTPUT' : QgsCoordinateReferenceSystem('EPSG:4546'), 'MESH_FORMAT' : 2, 'OUTPUT_MESH' : optFile,
|
||||||
|
'SOURCE_DATA' : [{'source': inFile,'type': 0,'attributeIndex': 3}] }
|
||||||
|
|
||||||
|
processing.run(aid,p)
|
||||||
|
return fileName[0:fileName.index('.')]+'.file'
|
||||||
|
|
||||||
|
|
||||||
|
def getpointFromMesh(fileName, tif_crs,extent):
|
||||||
|
inFile = work_space + tinmesh_folder + fileName
|
||||||
|
if not os.path.exists(inFile):
|
||||||
|
inFile = work_space + tinmesh_folder + fileName + '.ply'
|
||||||
|
optFile = 'TEMPORARY_OUTPUT'
|
||||||
|
aid = 'native:exportmeshongrid'
|
||||||
|
# tif_crs
|
||||||
|
p = {'CRS_OUTPUT' : QgsCoordinateReferenceSystem('EPSG:4546'), 'DATASET_GROUPS': [0],
|
||||||
|
'DATASET_TIME': {'type': 'static'},
|
||||||
|
'EXTENT':None,
|
||||||
|
'GRID_SPACING': 0.05,
|
||||||
|
'INPUT' : inFile, 'OUTPUT': optFile, 'VECTOR_OPTION': 0}
|
||||||
|
# 'EXTENT': '%.8f,%.8f,%.8f,%.8f [EPSG:4546]' % (extent[0],extent[1],extent[2],extent[3]),
|
||||||
|
res = processing.run(aid, p)
|
||||||
|
# Save as a shapefile
|
||||||
|
Fl_ou = fileName[0:fileName.index('.')] + '.geojson'
|
||||||
|
Fl_ou = work_space + potfrommesh_folder + Fl_ou
|
||||||
|
|
||||||
|
options = QgsVectorFileWriter.SaveVectorOptions()
|
||||||
|
options.driverName = "geojson"
|
||||||
|
QgsVectorFileWriter.writeAsVectorFormatV2(res['OUTPUT'], Fl_ou, QgsCoordinateTransformContext(), options)
|
||||||
|
# TODO turn string to realNumber
|
||||||
|
return fileName[0:fileName.index('.')] + '.geojson'
|
||||||
|
|
||||||
|
|
||||||
|
def transString2float(fileName):
|
||||||
|
inFile = work_space + potfrommesh_folder + fileName
|
||||||
|
|
||||||
|
opt = work_space + potfrommeshfloat_folder + fileName
|
||||||
|
optFile = open(opt, 'w')
|
||||||
|
# minx=9999999
|
||||||
|
# maxx=0
|
||||||
|
# miny=99999999
|
||||||
|
# maxy=0
|
||||||
|
with open(inFile) as jsonFile:
|
||||||
|
points = json.load(jsonFile)
|
||||||
|
features = points['features']
|
||||||
|
for feature in features:
|
||||||
|
properties = feature['properties']
|
||||||
|
Bed_Elevation = float(properties['Bed Elevation'])
|
||||||
|
properties['Bed Elevation'] = Bed_Elevation
|
||||||
|
#
|
||||||
|
# geometry=feature['geometry']
|
||||||
|
'''
|
||||||
|
coordinates = geometry['coordinates']
|
||||||
|
|
||||||
|
x = coordinates[0]
|
||||||
|
if minx>x:
|
||||||
|
minx =x
|
||||||
|
if maxx<x:
|
||||||
|
maxx=x
|
||||||
|
y= coordinates[1]
|
||||||
|
if miny > y:
|
||||||
|
miny=y
|
||||||
|
if maxy <y:
|
||||||
|
maxy=y
|
||||||
|
'''
|
||||||
|
json.dump(points, optFile)
|
||||||
|
optFile.close()
|
||||||
|
return fileName
|
||||||
|
|
||||||
|
|
||||||
|
def point2tif(fileName,cellHeight,cellWidth,tif_crs,extent):
|
||||||
|
inFile=work_space+potfrommeshfloat_folder+fileName
|
||||||
|
# print(inFile)
|
||||||
|
optFile=work_space+filltif_folder+fileName[0:fileName.index('.')]+'.tif'
|
||||||
|
# print(extent)
|
||||||
|
aid='gdal:rasterize'
|
||||||
|
p = {'BURN':0, 'DATA_TYPE':5,
|
||||||
|
'EXTENT':None,
|
||||||
|
'EXTRA': '', 'FIELD' : 'Bed Elevation', 'HEIGHT' : cellHeight,'INIT' : None,
|
||||||
|
'INPUT': inFile, 'INVERT' : False, 'NODATA' : 0, 'OPTIONS' : '', 'OUTPUT' : optFile,
|
||||||
|
'UNITS': 1, 'USE_Z' : False, 'WIDTH' : cellWidth}
|
||||||
|
# p= { 'BURN':0, 'DATA_TYPE':5,
|
||||||
|
# 'EXTENT':'544158.5540865903, 544161.2540865903, 4450451.895210848, 4450455.295210849 [EPSG:4546]',
|
||||||
|
# 'EXTRA' : '', 'FIELD' : 'Bed Elevation', 'HEIGHT' : cellHeight,
|
||||||
|
# 'INIT' : None, 'INPUT' : inFile, 'INVERT' : False, 'NODATA' : 0,
|
||||||
|
# 'OPTIONS' : '',
|
||||||
|
# 'OUTPUT' : optFile, 'UNITS' : 1, 'USE_Z' : False, 'WIDTH' : cellWidth}
|
||||||
|
processing.run(aid,p)
|
||||||
|
dataset=gdal.Open(optFile)
|
||||||
|
width = dataset.RasterXSize
|
||||||
|
height = dataset.RasterYSize
|
||||||
|
# print('out wid,hei:',width,height)
|
||||||
|
|
||||||
|
optFile2=work_space+'tif2/'+fileName[0:fileName.index('.')]+'.tif'
|
||||||
|
# print(optFile2)
|
||||||
|
pro_aid='gdal:warpreproject'
|
||||||
|
# proFile=optFile
|
||||||
|
# proFile=rootPath+'raster2points_pro/'+fileName[0:fileName.index('.')]+'.shp'
|
||||||
|
# pro_p={ 'CRS' : QgsCoordinateReferenceSystem('EPSG:4546'), 'INPUT' : outFile, 'OUTPUT' :proFile}
|
||||||
|
pro_p={'SOURCE_CRS' : QgsCoordinateReferenceSystem('EPSG:4546'),
|
||||||
|
'TARGET_CRS' : QgsCoordinateReferenceSystem(tif_crs),
|
||||||
|
'EXTENT': '%.8f,%.8f,%.8f,%.8f [EPSG:4546]' % (extent[0], extent[1], extent[2], extent[3]),
|
||||||
|
'RESAMPLING':2,'INPUT' : optFile, 'OUTPUT' :optFile2}
|
||||||
|
processing.run(pro_aid,pro_p)
|
||||||
|
|
||||||
|
return fileName
|
||||||
|
|
||||||
|
|
||||||
|
def processOneTif(fileName):
|
||||||
|
# 转矢量点,赋投影
|
||||||
|
processedFile, cellHeight, cellWidth, tif_crs, extent = raster2points(fileName)
|
||||||
|
meshFile = points2mesh(processedFile, tif_crs)
|
||||||
|
pointsFile = getpointFromMesh(meshFile, tif_crs, extent)
|
||||||
|
pointsFilefloat = transString2float(pointsFile)
|
||||||
|
point2tif(pointsFilefloat, cellHeight, cellWidth, tif_crs, extent)
|
||||||
|
|
||||||
|
|
||||||
|
def demFill():
|
||||||
|
# print("demFill")
|
||||||
|
# sys.stdout.flush()
|
||||||
|
single_files_list=os.listdir(work_space+singlehole_folder)
|
||||||
|
temp_file_lists = []
|
||||||
|
for file in single_files_list:
|
||||||
|
if os.path.splitext(file)[1] == '.tif' or os.path.splitext(file)[1] == '.TIF':
|
||||||
|
temp_file_lists.append(file)
|
||||||
|
total = len(temp_file_lists)
|
||||||
|
for index, file in enumerate(temp_file_lists):
|
||||||
|
sys.stdout.flush()
|
||||||
|
processOneTif(file)
|
||||||
|
print(10+float((index+1) / total * 79))
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
def back2Whole():
|
||||||
|
txtList=[]
|
||||||
|
txt_dir=work_space+out_txt_folder
|
||||||
|
sub_list = os.listdir(txt_dir)
|
||||||
|
#先找txt,保存文件名到list中
|
||||||
|
for f in sub_list:
|
||||||
|
if os.path.splitext(f)[1] == '.txt' or os.path.splitext(f)[1] == '.TXT':
|
||||||
|
txtList.append(f)
|
||||||
|
|
||||||
|
txtNum=len(txtList)
|
||||||
|
if txtNum<=0:
|
||||||
|
# print("There is no holes to join")
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
currentIndicator=0
|
||||||
|
for txtfile in txtList:
|
||||||
|
#根据文件名找原来的图像文件,拷贝
|
||||||
|
imgname=os.path.splitext(txtfile)[0]
|
||||||
|
demfile=imgname+'.tif'# txt文件名与dem文件名对应
|
||||||
|
txt_route= os.path.join(txt_dir, txtfile)# txt文件
|
||||||
|
dem_route = os.path.join(in_holedem, demfile)# 空缺的整图
|
||||||
|
proj, geotrans, dem_img, width, height = tifIO.ReadTif(dem_route) # c,h,w
|
||||||
|
img = dem_img.copy()
|
||||||
|
#读txt,找到对应的小矩形文件
|
||||||
|
file_handle=open(txt_route,mode="r")
|
||||||
|
lines=file_handle.readlines()
|
||||||
|
for i in lines:
|
||||||
|
s=i.split(',')
|
||||||
|
#['文件名,左上角列号,左上角行号,右下角列号,右下角行号\n']
|
||||||
|
subname=s[0]
|
||||||
|
lt_x=int(s[1])
|
||||||
|
lt_y=int(s[2])
|
||||||
|
rb_x=int(s[3])
|
||||||
|
rb_y=int(s[4])
|
||||||
|
# print(subname+" img's lt_x:%d,lt_y:%d,rb_x:%d,rb_y:%d" % (lt_x,lt_y,rb_x,rb_y))
|
||||||
|
# 读相应的文件,根据行列号替换
|
||||||
|
sub_route = os.path.join(work_space+filltif_folder, subname)
|
||||||
|
proj_sub, geotrans_sub, sub_img, w_sub, h_sub = tifIO.ReadTif(sub_route)
|
||||||
|
sp = sub_img.shape
|
||||||
|
img_w = sp[1]
|
||||||
|
img_h = sp[0]
|
||||||
|
# print(subname + " img's w:%d,h:%d" % (img_w,img_h))
|
||||||
|
# img[lt_y:rb_y,lt_x:rb_x]=sub_img
|
||||||
|
img[lt_y:lt_y+img_h,lt_x:lt_x+img_w]=sub_img
|
||||||
|
file_handle.close()
|
||||||
|
out_path = os.path.join(work_space,out_fulltif_folder)
|
||||||
|
if os.path.exists(out_path):
|
||||||
|
try:
|
||||||
|
shutil.rmtree(out_path)
|
||||||
|
time.sleep(2) # 防止删除操作未结束就运行mkdir()
|
||||||
|
except Exception as e:
|
||||||
|
print(-1.0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.mkdir(out_path)
|
||||||
|
|
||||||
|
out_wholefile=imgname+'_whole.tif'
|
||||||
|
tifIO.writeTif(out_path+out_wholefile, proj, geotrans, img)
|
||||||
|
currentIndicator=currentIndicator+1
|
||||||
|
print(90.0+float(currentIndicator/txtNum)*10)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(0)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
in_demfolder = in_holedem
|
||||||
|
out_singlehole = os.path.join(work_space, singlehole_folder)
|
||||||
|
txt_folder = os.path.join(work_space, out_txt_folder)
|
||||||
|
# 执行寻找并保存单个空洞
|
||||||
|
findHoles(in_demfolder,out_singlehole,txt_folder)
|
||||||
|
print(2)
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
confirmWorkspaceClear(work_space)
|
||||||
|
|
||||||
|
demFill()
|
||||||
|
|
||||||
|
back2Whole()
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
from osgeo import gdal
|
||||||
|
# from tqdm import tqdm
|
||||||
|
|
||||||
|
def ReadTif(tif_path):
|
||||||
|
dataset = gdal.Open(tif_path)
|
||||||
|
width = dataset.RasterXSize
|
||||||
|
height = dataset.RasterYSize
|
||||||
|
|
||||||
|
geotrans = list(dataset.GetGeoTransform()) # 仿射矩阵
|
||||||
|
proj = dataset.GetProjection() # 地图投影信息
|
||||||
|
data = dataset.ReadAsArray(0, 0, width, height) # 将数据写成数组,对应栅格矩阵
|
||||||
|
|
||||||
|
del dataset # 关闭对象,文件dataset
|
||||||
|
return proj, geotrans, data, width, height
|
||||||
|
|
||||||
|
def writeTif(fileroute, im_proj, im_geotrans, im_data):
|
||||||
|
# 判断栅格数据的数据类型
|
||||||
|
"""
|
||||||
|
GDAL中的GDALDataType是一个枚举型,其中的值为:
|
||||||
|
GDT_Unknown : 未知数据类型
|
||||||
|
GDT_Byte : 8bit正整型 (C++中对应unsigned char)
|
||||||
|
GDT_UInt16 : 16bit正整型 (C++中对应 unsigned short)
|
||||||
|
GDT_Int16 : 16bit整型 (C++中对应 short 或 short int)
|
||||||
|
GDT_UInt32 : 32bit 正整型 (C++中对应unsigned long)
|
||||||
|
GDT_Int32 : 32bit整型 (C++中对应int 或 long 或 long int)
|
||||||
|
GDT_Float32 : 32bit 浮点型 (C++中对应float)
|
||||||
|
GDT_Float64 : 64bit 浮点型 (C++中对应double)
|
||||||
|
GDT_CInt16 : 16bit复整型 (?)
|
||||||
|
GDT_CInt32 : 32bit复整型 (?)
|
||||||
|
GDT_CFloat32 : 32bit复浮点型 (?)
|
||||||
|
GDT_CFloat64 : 64bit复浮点型 (?)
|
||||||
|
"""
|
||||||
|
if 'int8' in im_data.dtype.name:
|
||||||
|
datatype = gdal.GDT_Byte
|
||||||
|
elif 'int16' in im_data.dtype.name:
|
||||||
|
datatype = gdal.GDT_UInt16
|
||||||
|
else:
|
||||||
|
datatype = gdal.GDT_Float32
|
||||||
|
|
||||||
|
# 判读数组维数
|
||||||
|
if len(im_data.shape) == 3:
|
||||||
|
im_bands, im_height, im_width = im_data.shape
|
||||||
|
else:
|
||||||
|
im_bands, (im_height, im_width) = 1, im_data.shape
|
||||||
|
im_data = im_data.reshape(im_bands,im_height, im_width)
|
||||||
|
# 创建文件
|
||||||
|
driver = gdal.GetDriverByName("GTiff") # 数据类型必须有,因为要计算需要多大内存空间
|
||||||
|
dataset = driver.Create(fileroute, im_width,im_height, im_bands, datatype)
|
||||||
|
|
||||||
|
dataset.SetGeoTransform(im_geotrans) # 写入仿射变换参数
|
||||||
|
dataset.SetProjection(im_proj) # 写入投影
|
||||||
|
|
||||||
|
if im_bands == 1:
|
||||||
|
dataset.GetRasterBand(1).WriteArray(im_data[0]) # 写入数组数据
|
||||||
|
else:
|
||||||
|
#for i in range(im_bands):
|
||||||
|
for i in tqdm(range(im_bands)):
|
||||||
|
dataset.GetRasterBand(i + 1).WriteArray(im_data[i])
|
||||||
|
|
||||||
|
del dataset
|
||||||
|
|
||||||
|
def np2gdal(hwc): # hwc2chw
|
||||||
|
chw = hwc.swapaxes(2, 0).swapaxes(1, 2) # h,w,c to c,h,w
|
||||||
|
return chw
|
||||||
|
|
||||||
|
def gdal2np(chw): #chw2hwc
|
||||||
|
hwc = chw.swapaxes(1, 0).swapaxes(1, 2) # h,w,c
|
||||||
|
return hwc
|
||||||
Reference in New Issue
Block a user