#include #include #include #include #include #include #include "DEM_GeneRas.h" #include "ThreadObject.h" #include "im2shp.h" using namespace std; WorkThreadObject::WorkThreadObject(QObject* parent) :QObject(parent) { qRegisterMetaType >("std::function"); } WorkThreadObject::~WorkThreadObject() { } void WorkThreadObject::runPredictWork(QString Moudle, QString DOM, QString DSM, QString PRE)//, std::functionfunc { QString str = QString("%1->%2,thread id:%3").arg(__FILE__).arg(__FUNCTION__).arg((int)QThread::currentThreadId()); QDir pluginsDir = QDir(qApp->applicationDirPath()); qDebug() << str << "----" << pluginsDir.currentPath(); if (!pluginsDir.cd("models\\envs")) { qDebug() << "no folder models\\envs"; return; } QString exeDirName = pluginsDir.absoluteFilePath("predict_4c_vegetation.exe"); qDebug() << "----" << exeDirName; QString model = " --model_path " + Moudle; QString dom_path = " --dom_path " + DOM + "/"; QString dsm_path = " --dsm_path " + DSM + "/"; QString pre_dir = " --pre_path " + PRE + "/"; QString ss = exeDirName + model + dom_path + dsm_path + pre_dir; qDebug() << ss; QProcess* pProces = new QProcess(this); connect(pProces, SIGNAL(readyReadStandardOutput()), this, SLOT(on_read())); pProces->start(ss); emit process(2); } void WorkThreadObject::on_read() { mProces = (QProcess*)sender(); QString output = QString::fromLocal8Bit(mProces->readAllStandardOutput()); if (output.toFloat() > 0) { qDebug() << "exe out:" << output.toFloat(); emit process(output.toFloat()); if (output.toFloat() == 100.0) emit addDataToMap(); } else qDebug() << "Unresolved exe out:" << output; } void WorkThreadObject::runFormatConvert(QString pre_path, QString DSM) { QDir dir(pre_path); QStringList nameFilters; nameFilters << "*.tif" << "*.tiff"; QStringList pre_tiff_files = dir.entryList(nameFilters, QDir::Files | QDir::Readable, QDir::Name); int list_len = pre_tiff_files.size(); for (int i = 0; i < list_len; i++) { emit process(float(i) / float(list_len) * 95); qDebug() << "TiffToShp progress:" << float(i) / float(list_len) * 100; QString file_path = pre_path + "\\" + pre_tiff_files[i]; QString dsm_path = DSM + "\\" + pre_tiff_files[i]; string path_preTiff = file_path.toStdString(); string pathPureName = path_preTiff.substr(0, path_preTiff.rfind(".")); string shp_path = pathPureName + ".shp"; //调起栅格转矢量 img2shp cc; QtGDALProcessBar* gb = new QtGDALProcessBar(); bool returnval = cc.ImagePolygonize(path_preTiff.c_str(), shp_path.c_str(), "ESRI Shapefile", 1, gb, gb); if (returnval == true) { QStringList list; list << dsm_path << QString::fromStdString(shp_path); emit addShpDataToMap(list); } else { //QMessageBox mess(QMessageBox::NoIcon, QString::fromLocal8Bit("错误"), QString::fromLocal8Bit("请检查输入数据")); //mess.setWindowFlags(Qt::Drawer); //int result = mess.exec(); //return; } } emit process(100); } void WorkThreadObject::on_cancel() { if (mProces == nullptr) { qDebug() << "--mProces null"; } else { //py打包exe文件名 QString KillStr = "taskkill /f /im predict_4c_vegetation.exe"; mProces->startDetached(KillStr); qDebug() << "--kill Proces"; } }