diff --git a/ImageOperatorBase.cpp b/ImageOperatorBase.cpp index c8b2ed2..a3381ef 100644 --- a/ImageOperatorBase.cpp +++ b/ImageOperatorBase.cpp @@ -913,6 +913,42 @@ void gdalImage::setNoDataValue(double nodatavalue = -9999, int band_ids = 1) 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() { // 1 lon lat = x @@ -1639,7 +1675,7 @@ ErrorCode MergeRasterProcess(QVector filepaths, QString outfileptah, QS // 初始化 long resultline = Memory1MB * 500 / 8 / resultImage.width; - resultline = resultline < 3000 ? resultline : 3000; // 最多100行 + resultline = resultline < 10000 ? resultline : 10000; // 最多100行 resultline = resultline > 0 ? resultline : 2; long bandnum = resultImage.band_num + 1; long starti = 0; @@ -1700,8 +1736,8 @@ ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resulti } // 分块计算 - long resultline = Memory1MB * 100 / 8 / resultimg.width; - resultline = resultline < 100 ? resultline : 100; // 最多100行 + long resultline = Memory1MB * 300 / 8 / resultimg.width; + resultline = resultline < 1000 ? resultline : 1000; // 最多100行 long bandnum = resultimg.band_num+1; long starti = 0; @@ -1724,7 +1760,7 @@ ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resulti omp_lock_t lock; omp_init_lock(&lock); -//#pragma omp parallel for +#pragma omp parallel for for (starti = 0; starti < resultimg.height; starti = starti + resultline) { long blocklines = resultline; blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; @@ -1788,6 +1824,18 @@ ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resulti Eigen::MatrixXd resultdata = resultimg.getData(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); + + 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(); colcount = data.cols(); for (long i = 0; i < rowcount; i++) { @@ -1825,13 +1873,14 @@ ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resulti maskimg.saveImage(resultmask, starti, 0, b); } } + omp_set_lock(&lock); processNumber = processNumber + blocklines; std::cout << "\rprocess bar:\t" << processNumber * 100.0 / resultimg.height << " % " << "\t\t\t"; if (nullptr != dia) { dia->showProcess(processNumber * 1.0 / resultimg.height, u8"合并图像"); } - if (progressDialog.maximum() >= processNumber) { + if (progressDialog.maximum() <= processNumber) { processNumber = progressDialog.maximum() - 1; } progressDialog.setValue(processNumber); @@ -1840,7 +1889,7 @@ ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resulti omp_destroy_lock(&lock); std::cout << std::endl; progressDialog.setWindowTitle(u8"影像掩膜"); - + progressDialog.setLabelText(u8"影像掩膜"); for (starti = 0; starti < resultimg.height; starti = starti + resultline) { long blocklines = resultline; blocklines = starti + blocklines < resultimg.height ? blocklines : resultimg.height - starti; @@ -1861,6 +1910,9 @@ ErrorCode MergeRasterInGeoCoding(QVector imgdslist, gdalImage resulti resultimg.saveImage(data, 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); } resultimg.setNoDataValue(-9999); diff --git a/ImageOperatorBase.h b/ImageOperatorBase.h index 0e95baf..0e37d47 100644 --- a/ImageOperatorBase.h +++ b/ImageOperatorBase.h @@ -171,6 +171,9 @@ public: // 方法 virtual void saveImage(Eigen::MatrixXi, int start_row, int start_col, int band_ids); virtual void saveImage(); 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 Landpoint getRow_Col(double lon, double lat); virtual Landpoint getLandPoint(double i, double j, double ati);