修改进度条提示

main
陈增辉 2024-11-15 18:15:47 +08:00
parent 26fd7c20ae
commit 490433aea7
2 changed files with 61 additions and 6 deletions

View File

@ -913,6 +913,42 @@ void gdalImage::setNoDataValue(double nodatavalue = -9999, int band_ids = 1)
GDALClose((GDALDatasetH)poDstDS); GDALClose((GDALDatasetH)poDstDS);
} }
void gdalImage::setNoDataValuei(int nodatavalue, int band_ids)
{
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7
// GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update));
poDstDS->GetRasterBand(band_ids)->SetNoDataValue(nodatavalue);
GDALFlushCache((GDALDatasetH)poDstDS);
GDALClose((GDALDatasetH)poDstDS);
}
double gdalImage::getNoDataValue(int band_ids)
{
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7
// GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update));
double v= poDstDS->GetRasterBand(band_ids)->GetNoDataValue( );
GDALFlushCache((GDALDatasetH)poDstDS);
GDALClose((GDALDatasetH)poDstDS);
return v;
}
int gdalImage::getNoDataValuei(int band_ids)
{
GDALAllRegister();
CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7
// GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff");
GDALDataset* poDstDS = (GDALDataset*)(GDALOpen(img_path.toUtf8().constData(), GA_Update));
int v= poDstDS->GetRasterBand(band_ids)->GetNoDataValue( );
GDALFlushCache((GDALDatasetH)poDstDS);
GDALClose((GDALDatasetH)poDstDS);
return v;
}
int gdalImage::InitInv_gt() int gdalImage::InitInv_gt()
{ {
// 1 lon lat = x // 1 lon lat = x
@ -1639,7 +1675,7 @@ ErrorCode MergeRasterProcess(QVector<QString> filepaths, QString outfileptah, QS
// 初始化 // 初始化
long resultline = Memory1MB * 500 / 8 / resultImage.width; long resultline = Memory1MB * 500 / 8 / resultImage.width;
resultline = resultline < 3000 ? resultline : 3000; // 最多100行 resultline = resultline < 10000 ? resultline : 10000; // 最多100行
resultline = resultline > 0 ? resultline : 2; resultline = resultline > 0 ? resultline : 2;
long bandnum = resultImage.band_num + 1; long bandnum = resultImage.band_num + 1;
long starti = 0; long starti = 0;
@ -1700,8 +1736,8 @@ ErrorCode MergeRasterInGeoCoding(QVector<gdalImage> imgdslist, gdalImage resulti
} }
// 分块计算 // 分块计算
long resultline = Memory1MB * 100 / 8 / resultimg.width; long resultline = Memory1MB * 300 / 8 / resultimg.width;
resultline = resultline < 100 ? resultline : 100; // 最多100行 resultline = resultline < 1000 ? resultline : 1000; // 最多100行
long bandnum = resultimg.band_num+1; long bandnum = resultimg.band_num+1;
long starti = 0; long starti = 0;
@ -1724,7 +1760,7 @@ ErrorCode MergeRasterInGeoCoding(QVector<gdalImage> imgdslist, gdalImage resulti
omp_lock_t lock; omp_lock_t lock;
omp_init_lock(&lock); omp_init_lock(&lock);
//#pragma omp parallel for #pragma omp parallel for
for (starti = 0; starti < resultimg.height; starti = starti + resultline) { for (starti = 0; starti < resultimg.height; starti = starti + resultline) {
long blocklines = resultline; long blocklines = resultline;
blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti;
@ -1788,6 +1824,18 @@ ErrorCode MergeRasterInGeoCoding(QVector<gdalImage> imgdslist, gdalImage resulti
Eigen::MatrixXd resultdata = resultimg.getData(starti, 0, blocklines, resultimg.width, b); Eigen::MatrixXd resultdata = resultimg.getData(starti, 0, blocklines, resultimg.width, b);
Eigen::MatrixXi resultmask = maskimg.getDatai(starti, 0, blocklines, resultimg.width, b); Eigen::MatrixXi resultmask = maskimg.getDatai(starti, 0, blocklines, resultimg.width, b);
Eigen::MatrixXd data = imgdslist[ir].getData(minRid, 0, rowlen, imgdslist[ir].width, b); Eigen::MatrixXd data = imgdslist[ir].getData(minRid, 0, rowlen, imgdslist[ir].width, b);
double nodata = imgdslist[ir].getNoDataValue(b);
for (long ii = 0; ii < data.rows(); ii++) {
for (long jj = 0; jj < data.cols(); jj++) {
if (std::abs(data(ii, jj) - nodata) < 1e-6) {
data(ii, jj) = 0;
}
}
}
rowcount = data.rows(); rowcount = data.rows();
colcount = data.cols(); colcount = data.cols();
for (long i = 0; i < rowcount; i++) { for (long i = 0; i < rowcount; i++) {
@ -1825,13 +1873,14 @@ ErrorCode MergeRasterInGeoCoding(QVector<gdalImage> imgdslist, gdalImage resulti
maskimg.saveImage(resultmask, starti, 0, b); maskimg.saveImage(resultmask, starti, 0, b);
} }
} }
omp_set_lock(&lock); omp_set_lock(&lock);
processNumber = processNumber + blocklines; processNumber = processNumber + blocklines;
std::cout << "\rprocess bar:\t" << processNumber * 100.0 / resultimg.height << " % " << "\t\t\t"; std::cout << "\rprocess bar:\t" << processNumber * 100.0 / resultimg.height << " % " << "\t\t\t";
if (nullptr != dia) { if (nullptr != dia) {
dia->showProcess(processNumber * 1.0 / resultimg.height, u8"合并图像"); dia->showProcess(processNumber * 1.0 / resultimg.height, u8"合并图像");
} }
if (progressDialog.maximum() >= processNumber) { if (progressDialog.maximum() <= processNumber) {
processNumber = progressDialog.maximum() - 1; processNumber = progressDialog.maximum() - 1;
} }
progressDialog.setValue(processNumber); progressDialog.setValue(processNumber);
@ -1840,7 +1889,7 @@ ErrorCode MergeRasterInGeoCoding(QVector<gdalImage> imgdslist, gdalImage resulti
omp_destroy_lock(&lock); omp_destroy_lock(&lock);
std::cout << std::endl; std::cout << std::endl;
progressDialog.setWindowTitle(u8"影像掩膜"); progressDialog.setWindowTitle(u8"影像掩膜");
progressDialog.setLabelText(u8"影像掩膜");
for (starti = 0; starti < resultimg.height; starti = starti + resultline) { for (starti = 0; starti < resultimg.height; starti = starti + resultline) {
long blocklines = resultline; long blocklines = resultline;
blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti;
@ -1861,6 +1910,9 @@ ErrorCode MergeRasterInGeoCoding(QVector<gdalImage> imgdslist, gdalImage resulti
resultimg.saveImage(data, starti, 0, b); resultimg.saveImage(data, starti, 0, b);
maskimg.saveImage(maskdata, starti, 0, b); maskimg.saveImage(maskdata, starti, 0, b);
} }
if (nullptr != dia) {
dia->showProcess((starti + blocklines) * 1.0 / resultimg.height, u8"影像掩膜");
}
progressDialog.setValue(starti + blocklines); progressDialog.setValue(starti + blocklines);
} }
resultimg.setNoDataValue(-9999); resultimg.setNoDataValue(-9999);

View File

@ -171,6 +171,9 @@ public: // 方法
virtual void saveImage(Eigen::MatrixXi, int start_row, int start_col, int band_ids); virtual void saveImage(Eigen::MatrixXi, int start_row, int start_col, int band_ids);
virtual void saveImage(); virtual void saveImage();
virtual void setNoDataValue(double nodatavalue, int band_ids); virtual void setNoDataValue(double nodatavalue, int band_ids);
virtual void setNoDataValuei(int nodatavalue, int band_ids);
virtual double getNoDataValue(int band_ids);
virtual int getNoDataValuei(int band_ids);
virtual int InitInv_gt(); virtual int InitInv_gt();
virtual Landpoint getRow_Col(double lon, double lat); virtual Landpoint getRow_Col(double lon, double lat);
virtual Landpoint getLandPoint(double i, double j, double ati); virtual Landpoint getLandPoint(double i, double j, double ati);