From a074003d6f4a74c886c7251ca3d5d7eaae4e1934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A2=9E=E8=BE=89?= <3045316072@qq.com> Date: Thu, 10 Apr 2025 18:32:25 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E4=BA=86L1B=E7=BA=A7?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E7=94=9F=E4=BA=A7=E5=8A=9F=E8=83=BD=202.?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9F=BA=E4=BA=8E=E7=BB=8F=E7=BA=AC=E5=BA=A6?= =?UTF-8?q?=E9=87=87=E6=A0=B7=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaseTool/ImageOperatorBase.h | 15 + BaseCommonLibrary/BaseTool/RasterToolBase.cpp | 7 +- BaseCommonLibrary/BaseTool/RasterToolBase.h | 42 +- .../BaseTool/SARSimulationImageL1.h | 6 + BaseCommonLibrary/ImageOperatorFuntion.cpp | 616 +++++++++++++----- Toolbox/BaseToolbox/BaseToolbox.vcxproj | 4 +- .../GF3CalibrationAndGeocodingClass.cpp | 88 --- .../GF3CalibrationAndGeocodingClass.h | 10 - .../BaseToolbox/QComplex2AmpPhase.cpp | 1 + .../SARImage/ImageNetOperator.cpp | 123 +++- .../SARImage/ImageNetOperator.h | 6 + .../SARImage/QL1ASARProcessDialog.cpp | 114 ++++ .../SARImage/QL1ASARProcessDialog.h | 30 + .../SARImage/QL1ASARProcessDialog.ui | 232 +++++++ .../SARImage/QLonLatInterpAtiFromDEM.cpp | 124 ++++ .../SARImage/QLonLatInterpAtiFromDEM.h | 29 + .../SARImage/QLonLatInterpAtiFromDEM.ui | 191 ++++++ .../SimulationSARTool/SimulationSARTool.cpp | 37 ++ Toolbox/SimulationSARTool/SimulationSARTool.h | 28 + .../SimulationSARTool.vcxproj | 6 + .../SimulationSARTool.vcxproj.filters | 18 + 21 files changed, 1433 insertions(+), 294 deletions(-) create mode 100644 Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui create mode 100644 Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp create mode 100644 Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h create mode 100644 Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui diff --git a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h index d47ad7c..2f52328 100644 --- a/BaseCommonLibrary/BaseTool/ImageOperatorBase.h +++ b/BaseCommonLibrary/BaseTool/ImageOperatorBase.h @@ -316,6 +316,21 @@ void BASECONSTVARIABLEAPI testOutDataArr(QString filename, long* data, long row void BASECONSTVARIABLEAPI CreateSARIntensityByLookTable(QString IntensityRasterPath, QString LookTableRasterPath, QString SARIntensityPath, long min_rid, long max_rid, long min_cid, long max_cid, std::function processBarShow = {}); +bool BASECONSTVARIABLEAPI ConvertVrtToEnvi(QString vrtPath, QString outPath); + + + + +void BASECONSTVARIABLEAPI MultiLookRaster(QString inRasterPath, QString outRasterPath, long looklineNumrow, long looklineNumCol); +ErrorCode BASECONSTVARIABLEAPI Complex2PhaseRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI Complex2dBRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI Complex2AmpRaster(QString inComplexPath, QString outRasterPath); +ErrorCode BASECONSTVARIABLEAPI ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy); + + + + + //--------------------- 图像文件读写 ------------------------------ diff --git a/BaseCommonLibrary/BaseTool/RasterToolBase.cpp b/BaseCommonLibrary/BaseTool/RasterToolBase.cpp index 32711fb..5debe6f 100644 --- a/BaseCommonLibrary/BaseTool/RasterToolBase.cpp +++ b/BaseCommonLibrary/BaseTool/RasterToolBase.cpp @@ -15,6 +15,8 @@ #include #include #include +#include "SARSimulationImageL1.h" +#include namespace RasterToolBase { long getProjectEPSGCodeByLon_Lat(double lon, double lat, ProjectStripDelta stripState) @@ -268,4 +270,7 @@ namespace RasterToolBase { return CoordinateSystemType::UNKNOW; } } -} // namespace RasterToolBase \ No newline at end of file +}; // namespace RasterToolBase + + + diff --git a/BaseCommonLibrary/BaseTool/RasterToolBase.h b/BaseCommonLibrary/BaseTool/RasterToolBase.h index bc6842f..254d4bb 100644 --- a/BaseCommonLibrary/BaseTool/RasterToolBase.h +++ b/BaseCommonLibrary/BaseTool/RasterToolBase.h @@ -12,40 +12,42 @@ #include "BaseConstVariable.h" #include "gdal_priv.h" #include +#include "LogInfoCls.h" + namespace RasterToolBase { - static bool GDALAllRegisterEnable=false; + static bool GDALAllRegisterEnable = false; - enum ProjectStripDelta{ + enum ProjectStripDelta { Strip_6, // 6度带 Strip_3 }; - enum CoordinateSystemType{ // 坐标系类型 + enum CoordinateSystemType { // 坐标系类型 GeoCoordinateSystem, ProjectCoordinateSystem, UNKNOW }; - struct PointRaster{ // 影像坐标点 + struct PointRaster { // 影像坐标点 double x; double y; double z; }; - struct PointXYZ{ - double x,y,z; + struct PointXYZ { + double x, y, z; }; - struct PointGeo{ - double lon,lat,ati; + struct PointGeo { + double lon, lat, ati; }; - struct PointImage{ - double pixel_x,pixel_y; + struct PointImage { + double pixel_x, pixel_y; }; /// 根据经纬度获取 @@ -56,14 +58,14 @@ namespace RasterToolBase { /// \param lat 纬度 /// \return 对应投影坐标系统的 EPSG编码,-1 表示计算错误 long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat(double long, double lat, - ProjectStripDelta stripState = ProjectStripDelta::Strip_3); + ProjectStripDelta stripState = ProjectStripDelta::Strip_3); long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat); long BASECONSTVARIABLEAPI getProjectEPSGCodeByLon_Lat_inStrip6(double lon, double lat); - QString BASECONSTVARIABLEAPI GetProjectionNameFromEPSG(long epsgCode) ; + QString BASECONSTVARIABLEAPI GetProjectionNameFromEPSG(long epsgCode); long BASECONSTVARIABLEAPI GetEPSGFromRasterFile(QString filepath); @@ -72,9 +74,23 @@ namespace RasterToolBase { CoordinateSystemType BASECONSTVARIABLEAPI getCoordinateSystemTypeByEPSGCode(long EPSGCODE); +};// namespace RasterProjectConvertor + + + + +// 遥感类常用数据 + + + + + + + + + -} // namespace RasterProjectConvertor #endif // LAMPCAE_RASTERTOOLBASE_H diff --git a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h index c2abecf..3d85682 100644 --- a/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h +++ b/BaseCommonLibrary/BaseTool/SARSimulationImageL1.h @@ -208,3 +208,9 @@ private: }; + + + + + + diff --git a/BaseCommonLibrary/ImageOperatorFuntion.cpp b/BaseCommonLibrary/ImageOperatorFuntion.cpp index 67c620a..6313329 100644 --- a/BaseCommonLibrary/ImageOperatorFuntion.cpp +++ b/BaseCommonLibrary/ImageOperatorFuntion.cpp @@ -1,4 +1,4 @@ -#include "stdafx.h" +#include "stdafx.h" #include "ImageOperatorBase.h" #include "BaseTool.h" #include "GeoOperator.h" @@ -25,8 +25,12 @@ #include #include #include -#include // OGRSpatialReference ڿռοת -#include // GDALWarp +#include // OGRSpatialReference 用于空间参考转换 +#include // 用于 GDALWarp 操作 + +#include "gdal_priv.h" +#include "cpl_conv.h" +#include std::shared_ptr OpenDataset(const QString& in_path, GDALAccess rwmode) @@ -105,13 +109,13 @@ GDALDataType getGDALDataType(QString fileptah) CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); GDALDataset* rasterDataset = (GDALDataset*)(GDALOpen( - fileptah.toUtf8().constData(), GA_ReadOnly)); // ��ֻ�ʽ��ȡ�Ӱ�� + fileptah.toUtf8().constData(), GA_ReadOnly)); // 锟斤拷只斤拷式锟斤拷取斤拷影锟斤拷 GDALDataType gdal_datatype = rasterDataset->GetRasterBand(1)->GetRasterDataType(); GDALClose((GDALDatasetH)rasterDataset); - omp_unset_lock(&lock); // �ͷŻ�� - omp_destroy_lock(&lock); // ٻ�� + omp_unset_lock(&lock); // 锟酵放伙拷斤拷 + omp_destroy_lock(&lock); // 劫伙拷斤拷 return gdal_datatype; } @@ -124,14 +128,14 @@ GDALDataType getGDALDataType(QString fileptah) int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype, double memey_size) { - // С + // 计算大小 int size_meta = 0; if (gdal_datatype == GDT_Byte) { size_meta = 1; } else if (gdal_datatype == GDT_UInt16) { - size_meta = 2; // ֻ˫ܹͨ + size_meta = 2; // 只有双通道才能构建 复数矩阵 } else if (gdal_datatype == GDT_UInt16) { size_meta = 2; @@ -172,7 +176,7 @@ int block_num_pre_memory(int block_width, int height, GDALDataType gdal_datatype else { } int block_num = int(memey_size / (size_meta * block_width)); - block_num = block_num > height ? height : block_num; // + block_num = block_num > height ? height : block_num; // 行数 block_num = block_num < 1 ? 1 : block_num; return block_num; } @@ -203,84 +207,84 @@ int ENVI2TIFF(QString in_envi_path, QString out_tiff_path) void ConvertCoordinateSystem(QString inRasterPath, QString outRasterPath, long outepsgcode) { - // עGDAL + // 注册所有GDAL驱动 GDALAllRegister(); - // դļ + // 打开输入栅格文件 GDALDataset* srcDataset = (GDALDataset*)GDALOpen(inRasterPath.toUtf8().constData(), GA_ReadOnly); if (!srcDataset) { - // ļʧ - // qDebug() << "޷ļ" << inRasterPath; + // 错误处理:输出文件打开失败 + // qDebug() << "无法打开输入文件:" << inRasterPath; return; } - // Ŀϵ + // 创建目标坐标系 OGRSpatialReference targetSRS; if (targetSRS.importFromEPSG(outepsgcode) != OGRERR_NONE) { GDALClose(srcDataset); - // qDebug() << "ЧEPSG룺" << outepsgcode; + // qDebug() << "无效的EPSG代码:" << outepsgcode; return; } GDALDataType datetype = srcDataset->GetRasterBand(1)->GetRasterDataType(); - // ȡĿϵWKTʾ + // 获取目标坐标系的WKT表示 char* targetSRSWkt = nullptr; targetSRS.exportToWkt(&targetSRSWkt); bool flag = (datetype == GDT_Byte || datetype == GDT_Int8 || datetype == GDT_Int16 || datetype == GDT_UInt16 || datetype == GDT_Int32 || datetype == GDT_UInt32 || datetype == GDT_Int64 || datetype == GDT_UInt64); - // ͶӰݼWarped VRT + // 创建重投影后的虚拟数据集(Warped VRT) GDALDataset* warpedVRT = flag ? (GDALDataset*)GDALAutoCreateWarpedVRT( srcDataset, - nullptr, // ϵĬʹԴݣ - targetSRSWkt, // Ŀϵ - GRA_NearestNeighbour, // ز˫Բֵ - 0.0, // 0ʾԶ㣩 - nullptr // ѡ + nullptr, // 输入坐标系(默认使用源数据) + targetSRSWkt, // 目标坐标系 + GRA_NearestNeighbour, // 重采样方法:双线性插值 + 0.0, // 最大误差(0表示自动计算) + nullptr // 其他选项 ) : (GDALDataset*)GDALAutoCreateWarpedVRT( srcDataset, - nullptr, // ϵĬʹԴݣ - targetSRSWkt, // Ŀϵ - GRA_Bilinear, // ز˫Բֵ - 0.0, // 0ʾԶ㣩 - nullptr // ѡ + nullptr, // 输入坐标系(默认使用源数据) + targetSRSWkt, // 目标坐标系 + GRA_Bilinear, // 重采样方法:双线性插值 + 0.0, // 最大误差(0表示自动计算) + nullptr // 其他选项 ); - CPLFree(targetSRSWkt); // ͷWKTڴ + CPLFree(targetSRSWkt); // 释放WKT内存 if (!warpedVRT) { GDALClose(srcDataset); - qDebug() << u8"ͶӰתVRTʧ"; + qDebug() << u8"创建投影转换VRT失败"; return; } - // ȡGeoTIFFʽ + // 获取输出驱动(GeoTIFF格式) QString filesuffer = getFileExtension(outRasterPath).toLower(); bool isTiff = filesuffer.contains("tif"); GDALDriver* driver = isTiff ? GetGDALDriverManager()->GetDriverByName("GTiff") : GetGDALDriverManager()->GetDriverByName("ENVI"); if (!driver) { GDALClose(warpedVRT); GDALClose(srcDataset); - // qDebug() << "޷ȡGeoTIFF"; + // qDebug() << "无法获取GeoTIFF驱动"; return; } - // դļ + // 创建输出栅格文件 GDALDataset* dstDataset = driver->CreateCopy( - outRasterPath.toUtf8().constData(), // ļ· - warpedVRT, // ݼVRT - false, // Ƿϸ - nullptr, // ѡ - nullptr, // Ȼص - nullptr // ص + outRasterPath.toUtf8().constData(), // 输出文件路径 + warpedVRT, // 输入数据集(VRT) + false, // 是否严格复制 + nullptr, // 创建选项 + nullptr, // 进度回调 + nullptr // 回调参数 ); if (!dstDataset) { - // qDebug() << "ļʧܣ" << outRasterPath; + // qDebug() << "创建输出文件失败:" << outRasterPath; GDALClose(warpedVRT); GDALClose(srcDataset); return; } - // ͷԴ + // 释放资源 GDALClose(dstDataset); GDALClose(warpedVRT); GDALClose(srcDataset); @@ -320,11 +324,11 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr char* pszSrcWKT = NULL; pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); - // ���û��ͶӰ����?���һ�?1?7 + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 if (strlen(pszSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pszSrcWKT); } @@ -332,12 +336,12 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr char* pdstSrcWKT = NULL; pdstSrcWKT = const_cast(pDRef->GetProjectionRef()); - // ���û��ͶӰ����?���һ�?1?7 + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 if (strlen(pdstSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pdstSrcWKT); } @@ -369,7 +373,7 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, FALSE, 0.0, 1); qDebug() << "no proj "; - //(û��ͶӰ��Ӱ��������߲�??1?7) + //(没锟斤拷投影锟斤拷影锟斤拷锟斤拷锟斤拷锟斤拷卟锟酵?拷锟?1锟?7) if (hTransformArg == NULL) { qDebug() << "hTransformArg create failure"; GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); @@ -392,8 +396,8 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr GDALWarpOptions* psWo = GDALCreateWarpOptions(); - CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // ʹпõCPU - CPLSetConfigOption("GDAL_CACHEMAX", "16000"); // ûСΪ500MB + CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // 使用所有可用的CPU核心 + CPLSetConfigOption("GDAL_CACHEMAX", "16000"); // 设置缓存大小为500MB // psWo->papszWarpOptions = CSLDuplicate(NULL); psWo->eWorkingDataType = dataType; @@ -440,20 +444,20 @@ void ResampleByReferenceRasterB(QString pszSrcFile, QString RefrasterBPath, QStr void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, QString OutrasterCPath) { - // עGDAL + // 注册所有GDAL驱动 GDALAllRegister(); - // 򿪲οդB + // 打开参考栅格B GDALDataset* refDS = (GDALDataset*)GDALOpen(RefrasterBPath.toUtf8().constData(), GA_ReadOnly); if (!refDS) { - qDebug() << "޷򿪲οդB" << RefrasterBPath; + qDebug() << "无法打开参考栅格B:" << RefrasterBPath; return; } - // ȡοդĵ任ͶӰͳߴ + // 获取参考栅格的地理变换、投影和尺寸 double geotransform[6]; if (refDS->GetGeoTransform(geotransform) != CE_None) { - qDebug() << "ȡοդĵ任ʧܡ"; + qDebug() << "获取参考栅格的地理变换失败。"; GDALClose(refDS); return; } @@ -461,28 +465,28 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q const char* proj = refDS->GetProjectionRef(); int cols = refDS->GetRasterXSize(); int rows = refDS->GetRasterYSize(); - GDALClose(refDS); // ȡϢرղοդ + GDALClose(refDS); // 获取信息后关闭参考栅格 - // դA + // 打开输入栅格A GDALDataset* srcDS = (GDALDataset*)GDALOpen(InrasterAPath.toUtf8().constData(), GA_ReadOnly); if (!srcDS) { - qDebug() << "޷դA" << InrasterAPath; + qDebug() << "无法打开输入栅格A:" << InrasterAPath; return; } - // ȡդIJ + // 获取输入栅格的波段数和数据类型 int nBands = srcDS->GetRasterCount(); if (nBands == 0) { - qDebug() << "դûвݡ"; + qDebug() << "输入栅格没有波段数据。"; GDALClose(srcDS); return; } GDALDataType dataType = srcDS->GetRasterBand(1)->GetRasterDataType(); - // դC + // 创建输出栅格C GDALDriver* driver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (!driver) { - qDebug() << "޷ȡGeoTIFF"; + qDebug() << "无法获取GeoTIFF驱动。"; GDALClose(srcDS); return; } @@ -496,16 +500,16 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q nullptr ); if (!dstDS) { - qDebug() << "޷դ" << OutrasterCPath; + qDebug() << "无法创建输出栅格:" << OutrasterCPath; GDALClose(srcDS); return; } - // դĵ任ͶӰ + // 设置输出栅格的地理变换和投影 dstDS->SetGeoTransform(geotransform); dstDS->SetProjection(proj); - // GDAL Warpѡ + // 配置GDAL Warp选项 GDALWarpOptions* psWO = GDALCreateWarpOptions(); psWO->hSrcDS = srcDS; psWO->hDstDS = dstDS; @@ -516,9 +520,9 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q psWO->panSrcBands[i] = i + 1; psWO->panDstBands[i] = i + 1; } - psWO->eResampleAlg = GRA_NearestNeighbour; // ʹز + psWO->eResampleAlg = GRA_NearestNeighbour; // 使用最近邻重采样 - // ʼת + // 初始化坐标转换器 psWO->pfnTransformer = GDALGenImgProjTransform; psWO->pTransformerArg = GDALCreateGenImgProjTransformer( srcDS, GDALGetProjectionRef(srcDS), @@ -526,17 +530,17 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q FALSE, 0.0, 1 ); if (!psWO->pTransformerArg) { - qDebug() << "תʧܡ"; + qDebug() << "创建坐标转换器失败。"; GDALDestroyWarpOptions(psWO); GDALClose(srcDS); GDALClose(dstDS); return; } - // ִWarp + // 执行Warp操作 GDALWarpOperation oWarp; if (oWarp.Initialize(psWO) != CE_None) { - qDebug() << "ʼWarpʧܡ"; + qDebug() << "初始化Warp操作失败。"; GDALDestroyGenImgProjTransformer(psWO->pTransformerArg); GDALDestroyWarpOptions(psWO); GDALClose(srcDS); @@ -546,79 +550,79 @@ void ResampleByReferenceRasterB(QString InrasterAPath, QString RefrasterBPath, Q CPLErr eErr = oWarp.ChunkAndWarpImage(0, 0, cols, rows); if (eErr != CE_None) { - qDebug() << "ִWarpʧܡ"; + qDebug() << "执行Warp操作失败。"; } - // Դ + // 清理资源 GDALDestroyGenImgProjTransformer(psWO->pTransformerArg); GDALDestroyWarpOptions(psWO); GDALClose(srcDS); GDALClose(dstDS); - qDebug() << "زɣѱ" << OutrasterCPath; + qDebug() << "重采样完成,结果已保存至:" << OutrasterCPath; } void cropRasterByLatLon(const char* inputFile, const char* outputFile, double minLon, double maxLon, double minLat, double maxLat) { - // ʼ GDAL + // 初始化 GDAL 库 GDALAllRegister(); - // դݼ + // 打开栅格数据集 GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); if (poDataset == nullptr) { - std::cerr << "Failed to open input raster." << std::endl; + qDebug() << "Failed to open input raster." ; return; } - // ȡդݵĵοϢ + // 获取栅格数据的地理参考信息 double adfGeoTransform[6]; if (poDataset->GetGeoTransform(adfGeoTransform) != CE_None) { - std::cerr << "Failed to get geotransform." << std::endl; + qDebug() << "Failed to get geotransform." ; GDALClose(poDataset); return; } - // ȡӰͶӰϢ + // 获取输入影像的投影信息 const char* projection = poDataset->GetProjectionRef(); - // ݾγȼüӦդ + // 根据经纬度计算出裁剪区域对应的栅格像素坐标 int xMin = (int)((minLon - adfGeoTransform[0]) / adfGeoTransform[1]); int xMax = (int)((maxLon - adfGeoTransform[0]) / adfGeoTransform[1]); int yMin = (int)((maxLat - adfGeoTransform[3]) / adfGeoTransform[5]); int yMax = (int)((minLat - adfGeoTransform[3]) / adfGeoTransform[5]); - // üĿդݼ + // 创建裁剪区域的目标栅格数据集 GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (poDriver == nullptr) { - std::cerr << "Failed to get GTiff driver." << std::endl; + qDebug() << "Failed to get GTiff driver." ; GDALClose(poDataset); return; } - // դݼָߴ + // 创建输出栅格数据集,指定尺寸 int width = xMax - xMin; int height = yMax - yMin; GDALDataset* poOutDataset = poDriver->Create(outputFile, width, height, poDataset->GetRasterCount(), GDT_Float32, nullptr); if (poOutDataset == nullptr) { - std::cerr << "Failed to create output raster." << std::endl; + qDebug() << "Failed to create output raster." ; GDALClose(poDataset); return; } - // դͶӰϢ͵任 + // 设置输出栅格的投影信息和地理变换 poOutDataset->SetProjection(projection); double newGeoTransform[6] = { adfGeoTransform[0] + xMin * adfGeoTransform[1], adfGeoTransform[1], 0.0, adfGeoTransform[3] + yMin * adfGeoTransform[5], 0.0, adfGeoTransform[5] }; poOutDataset->SetGeoTransform(newGeoTransform); - // ѭȡԴݲдĿݼ + // 循环读取源数据并写入目标数据集 for (int i = 0; i < poDataset->GetRasterCount(); ++i) { GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); - // ȡԴ + // 读取源数据 int* pData = new int[width * height]; poBand->RasterIO(GF_Read, xMin, yMin, width, height, pData, width, height, GDT_Int32, 0, 0); - // дĿ + // 写入目标数据 poOutBand->RasterIO(GF_Write, 0, 0, width, height, pData, width, height, GDT_Int32, 0, 0); delete[] pData; @@ -626,28 +630,28 @@ void cropRasterByLatLon(const char* inputFile, const char* outputFile, double mi qDebug() << "Raster cropped and saved to: " << outputFile; - // + // 清理 GDALClose(poDataset); GDALClose(poOutDataset); } ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG, Point2& p) { - // Դϵԭʼϵ + // 创建源坐标系(原始坐标系) OGRSpatialReference sourceSRS; - sourceSRS.importFromEPSG(sourceEPSG); // ʹ EPSG ָϵ + sourceSRS.importFromEPSG(sourceEPSG); // 使用 EPSG 编码来指定坐标系 - // ĿϵĿϵ + // 创建目标坐标系(目标坐标系) OGRSpatialReference targetSRS; - targetSRS.importFromEPSG(targetEPSG); // WGS84 ϵ EPSG:4326 + targetSRS.importFromEPSG(targetEPSG); // WGS84 坐标系 EPSG:4326 - // 任 + // 创建坐标变换对象 OGRCoordinateTransformation* transform = OGRCreateCoordinateTransformation(&sourceSRS, &targetSRS); if (transform == nullptr) { qDebug() << "Failed to create coordinate transformation."; return ErrorCode::FAIL; } - // ת + // 转换坐标 double transformedX = x; double transformedY = y; if (transform->Transform(1, &transformedX, &transformedY)) { @@ -658,7 +662,7 @@ ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG qDebug() << "Coordinate transformation failed."; } - // + // 清理 delete transform; p.x = transformedX; p.y = transformedY; @@ -668,23 +672,23 @@ ErrorCode transformCoordinate(double x, double y, int sourceEPSG, int targetEPSG void transformRaster(const char* inputFile, const char* outputFile, int sourceEPSG, int targetEPSG) { - // ʼ GDAL + // 初始化 GDAL 库 GDALAllRegister(); - // Դդļ + // 打开源栅格文件 GDALDataset* poSrcDS = (GDALDataset*)GDALOpen(inputFile, GA_ReadOnly); if (poSrcDS == nullptr) { qDebug() << "Failed to open input file:" << inputFile; return; } - // ȡԴդĻϢ + // 获取源栅格的基本信息 int nXSize = poSrcDS->GetRasterXSize(); int nYSize = poSrcDS->GetRasterYSize(); int nBands = poSrcDS->GetRasterCount(); GDALDataType eDT = poSrcDS->GetRasterBand(1)->GetRasterDataType(); - // Ŀդļ + // 创建目标栅格文件 GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (poDriver == nullptr) { qDebug() << "GTiff driver not available."; @@ -699,7 +703,7 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP return; } - // ĿդĿռοϵͳ + // 设置目标栅格的空间参考系统 OGRSpatialReference oSRS; oSRS.importFromEPSG(targetEPSG); @@ -708,10 +712,10 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP poDstDS->SetProjection(pszWKT); CPLFree(pszWKT); - // Ԫ + // 复制元数据 poDstDS->SetMetadata(poSrcDS->GetMetadata()); - // ÿε + // 复制每个波段的数据 for (int i = 1; i <= nBands; ++i) { GDALRasterBand* poSrcBand = poSrcDS->GetRasterBand(i); GDALRasterBand* poDstBand = poDstDS->GetRasterBand(i); @@ -726,7 +730,7 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP CPLFree(pafScanline); } - // رݼ + // 关闭数据集 GDALClose(poSrcDS); GDALClose(poDstDS); @@ -735,68 +739,68 @@ void transformRaster(const char* inputFile, const char* outputFile, int sourceEP void resampleRaster(const char* inputRaster, const char* outputRaster, double targetPixelSizeX, double targetPixelSizeY) { - // ʼGDAL + // 初始化GDAL GDALAllRegister(); - // դļ + // 打开输入栅格文件 GDALDataset* poDataset = (GDALDataset*)GDALOpen(inputRaster, GA_ReadOnly); if (poDataset == nullptr) { - std::cerr << "Failed to open raster file." << std::endl; + qDebug() << "Failed to open raster file." ; return; } - // ȡԭʼդĿռο + // 获取原始栅格的空间参考 double adfGeoTransform[6]; if (poDataset->GetGeoTransform(adfGeoTransform) != CE_None) { - std::cerr << "Failed to get geotransform." << std::endl; + qDebug() << "Failed to get geotransform." ; GDALClose(poDataset); return; } - // ȡԭʼդijߴ + // 获取原始栅格的尺寸 int nXSize = poDataset->GetRasterXSize(); int nYSize = poDataset->GetRasterYSize(); - // Ŀդijߴ + // 计算目标栅格的尺寸 double targetXSize = (adfGeoTransform[1] * nXSize) / targetPixelSizeX; double targetYSize = (adfGeoTransform[5] * nYSize) / targetPixelSizeY; - // Ŀݼդ + // 创建目标数据集(输出栅格) GDALDriver* poDriver = GetGDALDriverManager()->GetDriverByName("GTiff"); if (poDriver == nullptr) { - std::cerr << "Failed to get GTiff driver." << std::endl; + qDebug() << "Failed to get GTiff driver." ; GDALClose(poDataset); return; } - // ݼ + // 创建输出数据集 GDALDataset* poOutDataset = poDriver->Create(outputRaster, (int)targetXSize, (int)targetYSize, poDataset->GetRasterCount(), GDT_Float32, nullptr); if (poOutDataset == nullptr) { - std::cerr << "Failed to create output raster." << std::endl; + qDebug() << "Failed to create output raster." ; GDALClose(poDataset); return; } - // ݼĵ任ϵ + // 设置输出数据集的地理变换(坐标系) double targetGeoTransform[6] = { adfGeoTransform[0], targetPixelSizeX, 0, adfGeoTransform[3], 0, -targetPixelSizeY }; poOutDataset->SetGeoTransform(targetGeoTransform); - // ݼͶӰϢ + // 设置输出数据集的投影信息 poOutDataset->SetProjection(poDataset->GetProjectionRef()); - // ز + // 进行重采样 for (int i = 0; i < poDataset->GetRasterCount(); i++) { GDALRasterBand* poBand = poDataset->GetRasterBand(i + 1); GDALRasterBand* poOutBand = poOutDataset->GetRasterBand(i + 1); - // ʹGDALزѡһʵزʽ + // 使用GDAL的重采样方法,选择一个适当的重采样方式 poOutBand->RasterIO(GF_Write, 0, 0, (int)targetXSize, (int)targetYSize, nullptr, (int)targetXSize, (int)targetYSize, poBand->GetRasterDataType(), 0, 0, nullptr); } - // رݼ + // 关闭数据集 GDALClose(poDataset); GDALClose(poOutDataset); @@ -806,10 +810,10 @@ void resampleRaster(const char* inputRaster, const char* outputRaster, double ta std::shared_ptr GetCenterPointInRaster(QString filepath) { qDebug() << "============= GetCenterPointInRaster ======================"; - // QTextCodec* codec = QTextCodec::codecForLocale(); // ȡϵͳĬϱı - // QByteArray byteArray = codec->fromUnicode(filepath); // QStringתΪQByteArray - //,ӦûԶͷ const char* charArray = byteArray.constData(); // - // ȡQByteArrayconst char*ָ + // QTextCodec* codec = QTextCodec::codecForLocale(); // 获取系统默认编码的文本编解码器 + // QByteArray byteArray = codec->fromUnicode(filepath); // 将QString转换为QByteArray + //,这个应该会自动释放 const char* charArray = byteArray.constData(); // + // 获取QByteArray的const char*指针 GDALAllRegister(); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); @@ -817,7 +821,7 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) GDALDataset* poDataset = (GDALDataset*)GDALOpen(filepath.toUtf8().data(), GA_ReadOnly); if (nullptr == poDataset || NULL == poDataset) { qDebug() << "Could not open dataset"; - return nullptr; // ʾȡʧ + return nullptr; // 表示读取失败 } double x, y, z; @@ -834,7 +838,7 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) double dfWidth = poDataset->GetRasterXSize(); double dfHeight = poDataset->GetRasterYSize(); - // ĵ꣨꣩ + // 计算中心点坐标(像素坐标) double dfCenterX = adfGeoTransform[0] + dfWidth * adfGeoTransform[1] / 2.0 + dfHeight * adfGeoTransform[2] / 2.0; double dfCenterY = adfGeoTransform[3] + dfWidth * adfGeoTransform[4] / 2.0 @@ -851,7 +855,7 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) y = dfCenterY; } else { - // ǵϵתWGS84 + // 如果不是地理坐标系,转换到WGS84 OGRSpatialReference oSRS_WGS84; oSRS_WGS84.SetWellKnownGeogCS("WGS84"); @@ -899,10 +903,10 @@ std::shared_ptr GetCenterPointInRaster(QString filepath) long GetEPSGFromRasterFile(QString filepath) { qDebug() << "============= GetEPSGFromRasterFile ======================"; - // QTextCodec* codec = QTextCodec::codecForLocale(); // ȡϵͳĬϱı - // QByteArray byteArray = codec->fromUnicode(filepath); // QStringתΪQByteArray - //,ӦûԶͷ const char* charArray = byteArray.constData(); // - // ȡQByteArrayconst char*ָ + // QTextCodec* codec = QTextCodec::codecForLocale(); // 获取系统默认编码的文本编解码器 + // QByteArray byteArray = codec->fromUnicode(filepath); // 将QString转换为QByteArray + //,这个应该会自动释放 const char* charArray = byteArray.constData(); // + // 获取QByteArray的const char*指针 { if (QFile(filepath).exists()) { @@ -913,9 +917,9 @@ long GetEPSGFromRasterFile(QString filepath) } GDALAllRegister(); - CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // עGDAL + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注册GDAL驱动 // qDebug()<GetProjectionRef(); qDebug() << QString::fromUtf8(pszProjection); - // SpatialReference + // 创建SpatialReference对象 OGRSpatialReference oSRS; if (oSRS.importFromWkt((char**)&pszProjection) != OGRERR_NONE) { qDebug() << ("Error: Unable to import projection information.\n"); @@ -945,7 +949,7 @@ long GetEPSGFromRasterFile(QString filepath) return -1; } - long epsgCode = atoi(epscodestr); // ȡEPSG + long epsgCode = atoi(epscodestr); // 获取EPSG代码 if (epsgCode != 0) { GDALClose(poDataset); @@ -983,16 +987,16 @@ long getProjectEPSGCodeByLon_Lat(double long, double lat, ProjectStripDelta stri } long getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat) { - // EPSG 4534 ~ 4554 3 ȴ - // жǷ йΧ - // ľȷΧ 75E ~ 135E ʵʷΧ 73.5E ~ 136.5E, - // γȷΧ 3N ~ 54Nſ 0N~ 60N - if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // й + // EPSG 4534 ~ 4554 3 度带 + // 首先判断是否是在 中国带宽范围 + // 中心经度范围 :75E ~ 135E 实际范围 73.5E ~ 136.5E, + // 纬度范围 3N ~ 54N,放宽到 0N~ 60N + if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // 中国境内 long code = trunc((lon - 73.5) / 3) + 4534; return code; } - else { // й ʹ ˹ - bool isSouth = lat < 0; // жϱΪʾʵӦÿҪϸµ߼ + else { // 非中国境内 使用 高斯克吕格 + bool isSouth = lat < 0; // 简单判断南北半球,这里仅为示例,实际应用可能需要更细致的逻辑 long prefix = isSouth ? 327000 : 326000; // std::string prefix = isSouth ? "327" : "326"; lon = fmod(lon + 360.0, 360.0); @@ -1004,18 +1008,18 @@ long getProjectEPSGCodeByLon_Lat_inStrip3(double lon, double lat) } long getProjectEPSGCodeByLon_Lat_inStrip6(double lon, double lat) { - // EPSG 4502 ~ 4512 6ȴ - // жǷ йΧ - // ľȷΧ 75E ~ 135E ʵʷΧ 72.0E ~ 138E, - // γȷΧ 3N ~ 54Nſ 0N~ 60N - if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // й + // EPSG 4502 ~ 4512 6度带 + // 首先判断是否是在 中国带宽范围 + // 中心经度范围 :75E ~ 135E 实际范围 72.0E ~ 138E, + // 纬度范围 3N ~ 54N,放宽到 0N~ 60N + if (73.5 <= lon && lon <= 136.5 && 0 <= lat && lat <= 60) { // 中国境内 long code = trunc((lon - 72.0) / 6) + 4502; return code; } - else { // й ʹ UTM// ȷţ6ȴ1ʼ60ÿ6һ + else { // 非中国境内 使用 UTM// 确定带号,6度带从1开始到60,每6度一个带 int zone = static_cast((lon + 180.0) / 6.0) + 1; - bool isSouth = lon < 0; // жǷϰ - long epsgCodeBase = isSouth ? 32700 : 32600; // EPSG + bool isSouth = lon < 0; // 判断是否在南半球 + long epsgCodeBase = isSouth ? 32700 : 32600; // 计算EPSG代码 long prefix = static_cast(epsgCodeBase + zone); return prefix; } @@ -1027,13 +1031,13 @@ QString GetProjectionNameFromEPSG(long epsgCode) qDebug() << "============= GetProjectionNameFromEPSG ======================"; OGRSpatialReference oSRS; - // EPSG + // 设置EPSG代码 if (oSRS.importFromEPSG(epsgCode) != OGRERR_NONE) { qDebug() << "epsgcode not recognition"; return ""; } - // ȡϵƣ + // 获取并输出坐标系的描述(名称) const char* pszName = oSRS.GetAttrValue("GEOGCS"); if (pszName) { qDebug() << "Coordinate system name for EPSG " + QString::number(epsgCode) @@ -1046,19 +1050,19 @@ QString GetProjectionNameFromEPSG(long epsgCode) } // char* wkt = NULL; - // // תΪWKTʽ + // // 转换为WKT格式 // oSRS.exportToWkt(&wkt); // // qDebug() << wkt; // - // // WKTнͶӰƣ򻯴ʵʿҪӵ߼׼ȷȡ + // // 从WKT中解析投影名称,这里简化处理,实际可能需要更复杂的逻辑来准确提取名称 // std::string wktStr(wkt); - // long start = wktStr.find("PROJCS[\"") + 8; // ҵ"PROJCS["ĵһ˫λ - // // startλÿʼһ˫ţ֮ݼΪͶӰ + // long start = wktStr.find("PROJCS[\"") + 8; // 找到"PROJCS["后的第一个双引号位置 + // // 从start位置开始找下一个双引号,这之间的内容即为投影名称 // int end = wktStr.find('\"', start); // QString projName = QString::fromStdString(wktStr.substr(start, end - start)); // - // // ͷWKTַڴ + // // 释放WKT字符串内存 // CPLFree(wkt); // return projName; @@ -1111,11 +1115,11 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int char* pszSrcWKT = NULL; pszSrcWKT = const_cast(pDSrc->GetProjectionRef()); - // ���û��ͶӰ����?���һ�?1?7 + // 锟斤拷锟矫伙拷锟酵队帮拷锟斤拷锟轿?拷锟斤拷锟揭伙拷锟?1锟?7 if (strlen(pszSrcWKT) <= 0) { OGRSpatialReference oSRS; oSRS.importFromEPSG(4326); - // oSRS.SetUTM(50, true); //������ ����120�� + // oSRS.SetUTM(50, true); //锟斤拷锟斤拷锟斤拷 锟斤拷锟斤拷120锟斤拷 // oSRS.SetWellKnownGeogCS("WGS84"); oSRS.exportToWkt(&pszSrcWKT); } @@ -1124,7 +1128,7 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int hTransformArg = GDALCreateGenImgProjTransformer((GDALDatasetH)pDSrc, pszSrcWKT, NULL, pszSrcWKT, FALSE, 0.0, 1); qDebug() << "no proj " << Qt::endl; - //(û��ͶӰ��Ӱ��������߲�??1?7) + //(没锟斤拷投影锟斤拷影锟斤拷锟斤拷锟斤拷锟斤拷卟锟酵?拷锟?1锟?7) if (hTransformArg == NULL) { GDALClose((GDALDatasetH)(GDALDatasetH)pDSrc); return -3; @@ -1152,8 +1156,8 @@ int ResampleGDAL(const char* pszSrcFile, const char* pszOutFile, double* gt, int pDDst->SetGeoTransform(gt); GDALWarpOptions* psWo = GDALCreateWarpOptions(); - CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // ʹпõCPU - CPLSetConfigOption("GDAL_CACHEMAX", "4000"); // ûСΪ500MB + CPLSetConfigOption("GDAL_NUM_THREADS", "ALL_CPUS"); // 使用所有可用的CPU核心 + CPLSetConfigOption("GDAL_CACHEMAX", "4000"); // 设置缓存大小为500MB // psWo->papszWarpOptions = CSLDuplicate(NULL); psWo->eWorkingDataType = dataType; psWo->eResampleAlg = eResample; @@ -1361,7 +1365,7 @@ int alignRaster(QString inputPath, QString referencePath, QString outputPath, GD -/** 2025.03.25 ĺ Eigenʹ****************************/ +/** 2025.03.25 下面的函数存在 Eigen使用****************************/ @@ -1392,8 +1396,8 @@ int saveMatrixXcd2TiFF(Eigen::MatrixXcd data, QString out_tiff_path) Eigen::MatrixXd gt = Eigen::MatrixXd::Zero(2, 3); gdalImage image_tiff = - CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true); // עﱣ - // ļ + CreategdalImage(out_tiff_path, rows, cols, 2, gt, "", false, true); // 注意这里保留仿真结果 + // 保存二进制文件 Eigen::MatrixXd real_img = data.array().real(); Eigen::MatrixXd imag_img = data.array().imag(); image_tiff.saveImage(real_img, 0, 0, 1); @@ -1433,7 +1437,7 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri gdalImage demds(dempath); gdalImage demxyz = CreategdalImage(demxyzpath, demds.height, demds.width, 3, demds.gt, demds.projection, true, true);// X,Y,Z - // ֿ㲢תΪXYZ + // 分块计算并转换为XYZ Eigen::MatrixXd demArr = demds.getData(0, 0, demds.height, demds.width, 1); Eigen::MatrixXd demR = demArr; @@ -1459,8 +1463,8 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri for (int j = 0; j < datacols; j++) { rowidx = i + max_rows_ids; colidx = j; - demds.getLandPoint(rowidx, colidx, demdata(i, j), LandP); // ȡ - LLA2XYZ(LandP, GERpoint); // γתΪϵ + demds.getLandPoint(rowidx, colidx, demdata(i, j), LandP); // 获取地理坐标 + LLA2XYZ(LandP, GERpoint); // 经纬度转换为地心坐标系 xyzdata_x(i, j) = GERpoint.x; xyzdata_y(i, j) = GERpoint.y; xyzdata_z(i, j) = GERpoint.z; @@ -1472,7 +1476,7 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri } - // + // 计算坡向角 gdalImage demsloperxyz = CreategdalImage(demsloperPath, demds.height, demds.width, 4, demds.gt, demds.projection, true, true);// X,Y,Z,cosangle line_invert = 1000; @@ -1507,13 +1511,13 @@ ErrorCode DEM2XYZRasterAndSlopRaster(QString dempath, QString demxyzpath, QStri demds.getLandPoint(rowidx + 1, colidx, demdata(i + 1, j), p3); demds.getLandPoint(rowidx, colidx + 1, demdata(i, j + 1), p4); - pslopeVector = getSlopeVector(p0, p1, p2, p3, p4); // ʸ + pslopeVector = getSlopeVector(p0, p1, p2, p3, p4); // 地面坡向矢量 slopeVector = { pslopeVector.lon,pslopeVector.lat,pslopeVector.ati }; pp = LLA2XYZ(p0); Zaxis.x = pp.lon; Zaxis.y = pp.lat; Zaxis.z = pp.ati; - sloperAngle = getCosAngle(slopeVector, Zaxis); // + sloperAngle = getCosAngle(slopeVector, Zaxis); // 地面坡向角 demsloper_x(i, j) = slopeVector.x; demsloper_y(i, j) = slopeVector.y; @@ -1549,7 +1553,7 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, Eigen::MatrixXd SARData = SARIntensity.getData(0, 0, SARIntensity.height, SARIntensity.width, 1); SARData = SARData.array() * 0; - // ֿ鴦 + // 分块处理 for (int yOff = 0; yOff < looktableds.height; yOff += blockYSize) { processBarShow(yOff, looktableds.height); @@ -1575,9 +1579,267 @@ void CreateSARIntensityByLookTable(QString IntensityRasterPath, } -/* ĺᵼ±󣬿Eigen bugأŲ飬̫ʱ䣬ҲһŲ + + + + + + +/**​ +* @brief 将VRT文件转换为ENVI格式(生成.dat和.hdr文件) +* @param inputVrtPath 输入VRT文件路径 +* @param outputEnviPath 输出ENVI数据文件路径(不含扩展名,自动生成.dat和.hdr) +* @param papszOptions GDAL创建选项(如压缩参数、存储顺序等,默认NULL) +* @return 成功返回true,失败返回false +*/ +bool ConvertVrtToEnvi(QString vrtPath, QString outPath) { + + GDALAllRegister(); + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // 注绞斤拷斤拷锟?1锟?7 + CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); + + const char* inputVrtPath = vrtPath.toUtf8().constData(); + const char* outputEnviPath = outPath.toUtf8().constData(); + + // 注册所有GDAL驱动[7](@ref) + GDALAllRegister(); + + // 打开输入VRT文件[1,3](@ref) + GDALDataset* poVRTDataset = (GDALDataset*)GDALOpen(inputVrtPath, GA_ReadOnly); + if (!poVRTDataset) { + qDebug() << "错误:无法打开VRT文件 " << inputVrtPath ; + return false; + } + + // 获取ENVI驱动[4,7](@ref) + GDALDriver* poENVIDriver = GetGDALDriverManager()->GetDriverByName("ENVI"); + if (!poENVIDriver) { + qDebug() << "错误:ENVI驱动未加载" ; + GDALClose(poVRTDataset); + return false; + } + + // 构造输出文件名(强制添加.dat后缀)[4](@ref) + std::string outputPath = std::string(outputEnviPath) + ".dat"; + + // 执行格式转换(自动生成.hdr头文件)[4,7](@ref) + GDALDataset* poENVIDataset = poENVIDriver->CreateCopy( + outputPath.c_str(), // 输出路径 + poVRTDataset, // 输入数据集 + FALSE, // 非严格模式(允许格式调整) + nullptr, // 用户自定义选项(如压缩参数) + nullptr, nullptr // 进度条和参数(暂不启用) + ); + + // 检查转换结果 + bool success = (poENVIDataset != nullptr); + if (!success) { + qDebug() << "错误:ENVI文件创建失败" ; + } + else { + GDALClose(poENVIDataset); + } + + // 关闭输入数据集 + GDALClose(poVRTDataset); + return success; +} + + + + +// 遥感类 +ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy) +{ + double gridlat = gridy / 110000.0; + double gridlon = gridx / 100000.0; + + long espgcode = GetEPSGFromRasterFile(indemPath.toUtf8().constData()); + if (espgcode == 4326) { + resampleRaster(indemPath.toUtf8().constData(), outdemPath.toUtf8().constData(), gridlon, gridlat); + return ErrorCode::SUCCESS; + } + else { + QMessageBox::warning(nullptr, u8"警告", u8"请输入WGS84坐标的DEM影像"); + return ErrorCode::FAIL; + } +} + + + +ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath) +{ + gdalImageComplex inimg(inComplexPath); + gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); + Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArrb1 = imgArr.array().abs(); + ampimg.saveImage(imgArrb1, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + +ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath) +{ + gdalImageComplex inimg(inComplexPath); + gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); + Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArrb1 = imgArr.array().arg(); + ampimg.saveImage(imgArrb1, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + +ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath) +{ + gdalImageComplex inimg(inComplexPath); + gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); + + + long blocklines = Memory1GB * 2 / 8 / inimg.width; + blocklines = blocklines < 100 ? 100 : blocklines; + Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); + Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); + + long startrow = 0; + for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { + + imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); + imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); + imgArrb1 = imgArr.array().abs().log10() * 20.0; + ampimg.saveImage(imgArrb1, startrow, 0, 1); + } + qDebug() << "影像写入到:" << outRasterPath; + return ErrorCode::SUCCESS; +} + + + + + +void MultiLookRaster(QString inRasterPath, QString outRasterPath, long looklineNumrow, long looklineNumCol) +{ + gdalImage inRaster(inRasterPath); + + int outRows = inRaster.height / looklineNumrow; + int outCols = inRaster.width / looklineNumCol; + int bandnum = 1; + QString project = inRaster.projection; + Eigen::MatrixXd inRasterGt = inRaster.gt; + GDALDataType datetype = inRaster.getDataType(); + + gdalImage outRaster = CreategdalImage(outRasterPath, outRows, outCols, 1, inRasterGt, project, true, true, true, datetype); + + Eigen::MatrixXd inRasterArr = inRaster.getData(0, 0, inRaster.height, inRaster.width, 1); + Eigen::MatrixXd outRasterArr = outRaster.getData(0, 0, outRows, outCols, 1); + + + // 多视处理 +#pragma omp parallel for collapse(2) + for (int row = 0; row < outRows; ++row) { + for (int col = 0; col < outCols; ++col) { + // 计算输入矩阵的窗口位置[2,3](@ref) + const int inputRow = row * looklineNumrow; + const int inputCol = col * looklineNumCol; + + // 动态计算实际窗口大小(处理边界情况)[3](@ref) + const int actualRows = (row == outRows - 1) ? + (inRaster.height - inputRow) : looklineNumrow; + const int actualCols = (col == outCols - 1) ? + (inRaster.width - inputCol) : looklineNumCol; + + // 提取当前窗口数据块[7](@ref) + Eigen::MatrixXd window = inRasterArr.block(inputRow, inputCol, actualRows, actualCols); + + // 计算多视平均值(自动处理数据类型转换)[2,7](@ref) + double sum = 0.0; + if constexpr (std::is_integral_v) { + sum = window.cast().sum(); // 整型数据转换为双精度计算 + } + else { + sum = window.sum(); + } + outRasterArr(row, col) = sum / (actualRows * actualCols); + } + } + + // 可选:处理残留边界(当输入尺寸不是整数倍时) + if ((inRaster.height % looklineNumrow != 0) || (inRaster.width % looklineNumCol != 0)) { + // 底部边界处理[3](@ref) + const int residualRowStart = outRows * looklineNumrow; + const int residualRowSize = inRaster.height - residualRowStart; + if (residualRowSize > 0) { +#pragma omp parallel for + for (int col = 0; col < outCols; ++col) { + const int inputCol = col * looklineNumCol; + const int actualCols = (col == outCols - 1) ? + (inRaster.width - inputCol) : looklineNumCol; + + Eigen::MatrixXd window = inRasterArr.block(residualRowStart, inputCol, + residualRowSize, actualCols); + outRasterArr(outRows - 1, col) = window.mean(); + } + } + + // 右侧边界处理[3](@ref) + const int residualColStart = outCols * looklineNumCol; + const int residualColSize = inRaster.width - residualColStart; + if (residualColSize > 0) { +#pragma omp parallel for + for (int row = 0; row < outRows; ++row) { + const int inputRow = row * looklineNumrow; + const int actualRows = (row == outRows - 1) ? + (inRaster.height - inputRow) : looklineNumrow; + + Eigen::MatrixXd window = inRasterArr.block(inputRow, residualColStart, + actualRows, residualColSize); + outRasterArr(row, outCols - 1) = window.mean(); + } + } + } + + // 保存结果 + outRaster.saveImage(outRasterArr, 0, 0, 1); + +} + + + + + + + + + + + + + +/* 启动下面的函数,会导致编译器错误,可能与Eigen 库 本身的bug相关,不建议排查,太费时间,而且不一定能排查出来 * -*** +*** Eigen::Matrix ReadComplexMatrixData(int start_line, int width, int line_num, std::shared_ptr rasterDataset, GDALDataType gdal_datatype) @@ -1601,7 +1863,7 @@ Eigen::Matrix ReadCompl } bool _flag = false; Eigen::Matrix data_mat( - line_num * width, 2); // ǿ + line_num * width, 2); // 必须强制行优先 if (gdal_datatype == GDT_Byte) { Eigen::MatrixX real_mat(line_num * width, 1); Eigen::MatrixX imag_mat(line_num * width, 1); @@ -1751,14 +2013,14 @@ Eigen::Matrix ReadCompl } else { } - // + // 保存数据 if (_flag) { return data_mat; } else { return Eigen::Matrix( - 0, 0); // ǿ; + 0, 0); // 必须强制行优先; } } @@ -1767,10 +2029,10 @@ ReadMatrixDoubleData(int start_line, int width, int line_num, std::shared_ptr rasterDataset, GDALDataType gdal_datatype, int band_idx) { - // 飬ʹeigen о㣬ټ + // 构建矩阵块,使用eigen 进行矩阵计算,加速计算 bool _flag = false; Eigen::Matrix data_mat( - line_num * width, 1); // ǿ + line_num * width, 1); // 必须强制行优先 if (gdal_datatype == GDT_Byte) { Eigen::MatrixX real_mat(line_num * width, 1); rasterDataset->GetRasterBand(band_idx)->RasterIO(GF_Read, 0, start_line, width, line_num, diff --git a/Toolbox/BaseToolbox/BaseToolbox.vcxproj b/Toolbox/BaseToolbox/BaseToolbox.vcxproj index 5384b55..5ec3f82 100644 --- a/Toolbox/BaseToolbox/BaseToolbox.vcxproj +++ b/Toolbox/BaseToolbox/BaseToolbox.vcxproj @@ -60,12 +60,12 @@ tools_qt5 - core + core;gui;widgets debug tools_qt5 - core + core;gui;widgets debug diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp index 76188ba..1e5fdcd 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.cpp @@ -209,90 +209,6 @@ ErrorCode ImportGF3L1AProcess(QString inMetaxmlPath, QString outWorkDirPath) return errorcode; } -ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath) -{ - gdalImageComplex inimg(inComplexPath); - gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); - - long blocklines = Memory1GB * 2 / 8 / inimg.width; - blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); - - long startrow = 0; - for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); - imgArrb1 = imgArr.array().abs(); - ampimg.saveImage(imgArrb1, startrow, 0, 1); - } - qDebug() << "Ӱд뵽" << outRasterPath; - return ErrorCode::SUCCESS; -} - -ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath) -{ - gdalImageComplex inimg(inComplexPath); - gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); - - - long blocklines = Memory1GB * 2 / 8 / inimg.width; - blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); - - long startrow = 0; - for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); - imgArrb1 = imgArr.array().arg(); - ampimg.saveImage(imgArrb1, startrow, 0, 1); - } - qDebug() << "Ӱд뵽" << outRasterPath; - return ErrorCode::SUCCESS; -} - -ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath) -{ - gdalImageComplex inimg(inComplexPath); - gdalImage ampimg = CreategdalImage(outRasterPath, inimg.height, inimg.width, inimg.band_num, inimg.gt, inimg.projection, true, true); - - - long blocklines = Memory1GB * 2 / 8 / inimg.width; - blocklines = blocklines < 100 ? 100 : blocklines; - Eigen::MatrixXd imgArrb1 = Eigen::MatrixXd::Zero(blocklines, ampimg.width); - Eigen::MatrixXcd imgArr = Eigen::MatrixXcd::Zero(blocklines, inimg.width); - - long startrow = 0; - for (startrow = 0; startrow < inimg.height; startrow = startrow + blocklines) { - - imgArrb1 = ampimg.getData(startrow, 0, blocklines, inimg.width, 1); - imgArr = inimg.getData(startrow, 0, blocklines, inimg.width, 2); - imgArrb1 = imgArr.array().abs().log10() * 20.0; - ampimg.saveImage(imgArrb1, startrow, 0, 1); - } - qDebug() << "Ӱд뵽" << outRasterPath; - return ErrorCode::SUCCESS; -} - -ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy) -{ - double gridlat = gridy / 110000.0; - double gridlon = gridx / 100000.0; - - long espgcode = GetEPSGFromRasterFile(indemPath.toUtf8().constData()); - if (espgcode == 4326) { - resampleRaster(indemPath.toUtf8().constData(), outdemPath.toUtf8().constData(), gridlon, gridlat); - return ErrorCode::SUCCESS; - } - else { - QMessageBox::warning(nullptr, u8"", u8"WGS84DEMӰ"); - return ErrorCode::FAIL; - } -} - ErrorCode RD_PSTN(double& refrange, double& lamda, double& timeR, double& R, double& tx, double& ty, double& tz, double& slopex, double& slopey, double& slopez, GF3PolyfitSatelliteOribtModel& polyfitmodel, SatelliteOribtNode& node, double& d0, double& d1, double& d2, double& d3, double& d4) { @@ -605,7 +521,3 @@ ErrorCode GF3RDProcess(QString inxmlPath, QString indemPath, QString outworkdir, } return ErrorCode::SUCCESS; } - - - - diff --git a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h index 2309c4c..db71e8c 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h +++ b/Toolbox/BaseToolbox/BaseToolbox/GF3CalibrationAndGeocodingClass.h @@ -17,14 +17,7 @@ QVector SearchGF3DataTiff(QString inMetaxmlPath); POLARTYPEENUM getDatasetGF3FilePolsarType(QString fileName); ErrorCode ImportGF3L1AProcess(QString inMetaxmlPath, QString outWorkDirPath); -// תʵ -ErrorCode Complex2AmpRaster(QString inComplexPath, QString outRasterPath); -//תλ -ErrorCode Complex2PhaseRaster(QString inComplexPath, QString outRasterPath); -ErrorCode Complex2dBRaster(QString inComplexPath, QString outRasterPath); - -ErrorCode ResampleDEM(QString indemPath, QString outdemPath, double gridx, double gridy); // RD 㷨 ErrorCode RD_PSTN(double& refrange,double& lamda, double& timeR, double& R, double& tx, double& ty, double& tz, double& slopex, double& slopey, double& slopez, GF3PolyfitSatelliteOribtModel& polyfitmodel, SatelliteOribtNode& node,double& d0,double& d1, double& d2, double& d3, double& d4); @@ -36,6 +29,3 @@ ErrorCode GF3OrthSLC( QString inRasterPath, QString inlooktablePath, QString out // 䴦 ErrorCode GF3RDProcess(QString inxmlPath, QString indemPath, QString outworkdir, double gridx, double gridy); - - - diff --git a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp index 90b6580..af2d5a6 100644 --- a/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp +++ b/Toolbox/BaseToolbox/BaseToolbox/QComplex2AmpPhase.cpp @@ -5,6 +5,7 @@ #include "BaseTool.h" #include "SARSimulationImageL1.h" #include "GF3CalibrationAndGeocodingClass.h" +#include "RasterToolBase.h" QComplex2AmpPhase::QComplex2AmpPhase(QWidget *parent) : QDialog(parent) diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp index 36a432d..334bc9c 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.cpp @@ -639,8 +639,6 @@ void InterploateClipAtiByRefDEM(QString ImageLLPath, QString& ImageDEMPath, QStr } - - int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QString ori_sim_count_tiffPath,long OriHeight,long OriWidth) { gdalImage sim_rc(dem_rc_path); @@ -783,7 +781,6 @@ int ReflectTable_WGS2Range(QString dem_rc_path,QString outOriSimTiffPath,QStrin } - int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath) { gdalImageComplex echodata(L2echodataPath); gdalImage looktable(RangeLooktablePath); @@ -909,6 +906,126 @@ int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePa } +void InterpLookTableRfromDEM(QString lonlatPath, QString DEMPath, QString outllrpath) +{ + gdalImage LLimg(lonlatPath); + gdalImage demimg(DEMPath); + gdalImage LLRimg = CreategdalImageDouble(outllrpath, LLimg.height, LLimg.width, 3, true, true); + + long llimgheight = LLimg.height; + long llimgWidth = LLimg.width; + + Eigen::MatrixXd imglonArr = LLimg.getData(0, 0, llimgheight, llimgWidth, 1); + Eigen::MatrixXd imglatArr = LLimg.getData(0, 0, llimgheight, llimgWidth, 2); + Eigen::MatrixXd demArr = demimg.getData(0, 0, demimg.height, demimg.width, 1); + + Eigen::MatrixXd outRArr = imglonArr.array() * 0; + + LLRimg.saveImage(imglonArr, 0, 0, 1); + LLRimg.saveImage(imglatArr, 0, 0, 2); + + + for (long i = 0; i < llimgheight; i++) { + for (long j = 0; j < llimgWidth; j++) { + double lon = imglonArr(i, j); + double lat = imglatArr(i, j); + Landpoint point = demimg.getRow_Col(lon, lat); + + if (point.lon<1 || point.lon>demimg.width - 2 || point.lat < 1 || point.lat - 2) { + continue; + } + else {} + + Landpoint p0, p11, p21, p12, p22; + + p0.lon = point.lon; + p0.lat = point.lat; + + p11.lon = floor(p0.lon); + p11.lat = floor(p0.lat); + p11.ati = demArr(long(p11.lat), long(p11.lon)); + + p12.lon = ceil(p0.lon); + p12.lat = floor(p0.lat); + p12.ati = demArr(long(p12.lat), long(p12.lon)); + + p21.lon = floor(p0.lon); + p21.lat = ceil(p0.lat); + p21.ati = demArr(long(p21.lat), long(p21.lon)); + + p22.lon = ceil(p0.lon); + p22.lat = ceil(p0.lat); + p22.ati = demArr(long(p22.lat), long(p22.lon)); + + p0.lon = p0.lon - p11.lon; + p0.lat = p0.lat - p11.lat; + + p12.lon = p12.lon - p11.lon; + p12.lat = p12.lat - p11.lat; + + p21.lon = p21.lon - p11.lon; + p21.lat = p21.lat - p11.lat; + + p22.lon = p22.lon - p11.lon; + p22.lat = p22.lat - p11.lat; + + p11.lon = p11.lon - p11.lon; + p11.lat = p11.lat - p11.lat; + + p0.ati = Bilinear_interpolation(p0, p11, p21, p12, p22); + outRArr(i, j) = p0.ati; + + } + } + + LLRimg.saveImage(outRArr, 0, 0, 3); + + return; +} + +void RangeLooktableLLA_2_RangeLooktableXYZ(QString LLAPath, QString outXYZPath) +{ + + gdalImage LLAimg(LLAPath); + gdalImage xyzimg = CreategdalImageDouble(outXYZPath, LLAimg.height, LLAimg.width, 3, true, true); + + long llimgheight = LLAimg.height; + long llimgWidth = LLAimg.width; + + Eigen::MatrixXd lonArr = LLAimg.getData(0, 0, llimgheight, llimgWidth, 1); + Eigen::MatrixXd latArr = LLAimg.getData(0, 0, llimgheight, llimgWidth, 2); + Eigen::MatrixXd atiArr = LLAimg.getData(0, 0, llimgheight, llimgWidth, 3); + + // ʹLLAץΪXYZ + Eigen::MatrixXd xArr = lonArr.array() * 0; + Eigen::MatrixXd yArr = lonArr.array() * 0; + Eigen::MatrixXd zArr = lonArr.array() * 0; + + + + for (long i = 0; i < llimgheight; i++) { + for (long j = 0; j < llimgWidth; j++) { + double lon = lonArr(i, j); + double lat = latArr(i, j); + double ati = atiArr(i, j); + Landpoint p{ lon,lat,ati }; + Landpoint XYZP=LLA2XYZ(p); + + xArr(i, j) = XYZP.lon; + yArr(i, j) = XYZP.lat; + zArr(i, j) = XYZP.ati; + + + } + } + + xyzimg.saveImage(xArr, 0, 0, 1); + xyzimg.saveImage(yArr, 0, 0, 2); + xyzimg.saveImage(zArr, 0, 0, 3); + + return; +} + diff --git a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h index b3a0be9..bf329ae 100644 --- a/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h +++ b/Toolbox/SimulationSARTool/SARImage/ImageNetOperator.h @@ -17,4 +17,10 @@ int ReflectTable_WGS2Range(QString dem_rc_path, QString outOriSimTiffPath, QStr int ResampleEChoDataFromGeoEcho(QString L2echodataPath, QString RangeLooktablePath, QString L1AEchoDataPath); + +void InterpLookTableRfromDEM(QString lonlatPath, QString DEMPath, QString outllrpath); + +void RangeLooktableLLA_2_RangeLooktableXYZ(QString LLAPath, QString outXYZPath); + + #endif diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp new file mode 100644 index 0000000..09b37cd --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.cpp @@ -0,0 +1,114 @@ +#include "QL1ASARProcessDialog.h" +#include "ui_QL1ASARProcessDialog.h" +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include "RasterToolBase.h" +#include "LogInfoCls.h" +#include +#include +#include "ImageNetOperator.h" +#include "ImageOperatorBase.h" + +QL1ASARProcessDialog::QL1ASARProcessDialog(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::QL1ASARProcessDialogClass) +{ + ui->setupUi(this); + + + connect(ui->pushButtonL1BSelect, SIGNAL(clicked()), this, SLOT(onpushButtonL1BSelect_clicked())); + connect(ui->pushButtonL1ASelect, SIGNAL(clicked()), this, SLOT(onpushButtonL1ASelect_clicked())); + connect(ui->pushButtonS1ASelect, SIGNAL(clicked()), this, SLOT(onpushButtonS1ASelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); + + + + +} + +QL1ASARProcessDialog::~QL1ASARProcessDialog() +{ + + + +} + +void QL1ASARProcessDialog::onpushButtonL1BSelect_clicked() +{ + + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡL1Bļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1ADataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } + +} + +void QL1ASARProcessDialog::onpushButtonL1ASelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡL1Aļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditL1ADataPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QL1ASARProcessDialog::onpushButtonS1ASelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡбƷļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineSlAPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QL1ASARProcessDialog::onbuttonBox_accepted() +{ + QString l1arasterpath = ui->lineEditL1ADataPath->text(); + QString s1arasterpath = ui->lineSlAPath->text(); + QString l1brasterpath = ui->lineEditL1BDataPath->text(); + + long nlaz = ui->spinBoxLNAz->value(); + long nlra = ui->spinBoxLNRa->value(); + + qDebug() << "бิƷ ת бȲƷ"; + Complex2AmpRaster(l1arasterpath, s1arasterpath); + + qDebug() << "бȲƷ ת бȲƷ"; + MultiLookRaster(s1arasterpath, l1brasterpath, nlaz, nlra); + + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"Ӵ")); +} + +void QL1ASARProcessDialog::onbuttonBox_rejected() +{ + this->close(); +} diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h new file mode 100644 index 0000000..3e27297 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.h @@ -0,0 +1,30 @@ +#pragma once + +#include + + +namespace Ui { + class QL1ASARProcessDialogClass; + +}; + +class QL1ASARProcessDialog : public QDialog +{ + Q_OBJECT + +public: + QL1ASARProcessDialog(QWidget *parent = nullptr); + ~QL1ASARProcessDialog(); + + +public slots: + + void onpushButtonL1BSelect_clicked(); + void onpushButtonL1ASelect_clicked(); + void onpushButtonS1ASelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); + +private: + Ui::QL1ASARProcessDialogClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui new file mode 100644 index 0000000..b3957fd --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QL1ASARProcessDialog.ui @@ -0,0 +1,232 @@ + + + QL1ASARProcessDialogClass + + + + 0 + 0 + 475 + 354 + + + + QL1ASARProcessDialog + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 30 + + + + 单视振幅产品: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + L1B: + + + + + + + + 0 + 30 + + + + L1A产品: + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + + + + + + + + 多视参数 + + + + + + + 0 + 30 + + + + + 100 + 16777215 + + + + 方位向视数: + + + + + + + + 0 + 30 + + + + + + + + + 0 + 30 + + + + + 100 + 16777215 + + + + 方位向视数: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp new file mode 100644 index 0000000..4fbc603 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.cpp @@ -0,0 +1,124 @@ +#include "QLonLatInterpAtiFromDEM.h" +#include "ui_QLonLatInterpAtiFromDEM.h" +#include "BaseConstVariable.h" +#include "BaseTool.h" +#include "RasterToolBase.h" +#include "LogInfoCls.h" +#include +#include +#include "ImageNetOperator.h" + +QLonLatInterpAtiFromDEM::QLonLatInterpAtiFromDEM(QWidget *parent) + : QDialog(parent) + ,ui(new Ui::QLonLatInterpAtiFromDEMClass) +{ + ui->setupUi(this); + + connect(ui->pushButtonLonLatRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLonLatRasterSelect_clicked())); + connect(ui->pushButtonDEMRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonDEMRasterSelect_clicked())); + connect(ui->pushButtonLLARasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonLLARasterSelect_clicked())); + connect(ui->pushButtonXYZRasterSelect, SIGNAL(clicked()), this, SLOT(onpushButtonXYZRasterSelect_clicked())); + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(onbuttonBox_accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(onbuttonBox_rejected())); + + +} + +QLonLatInterpAtiFromDEM::~QLonLatInterpAtiFromDEM() +{ + +} + +void QLonLatInterpAtiFromDEM::onpushButtonLonLatRasterSelect_clicked() +{ + + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditLonLatRasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } + +} + +void QLonLatInterpAtiFromDEM::onpushButtonDEMRasterSelect_clicked() +{ + QString fileNames = QFileDialog::getOpenFileName( + this, // + tr(u8"ѡDEMļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditDEMRasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QLonLatInterpAtiFromDEM::onpushButtonLLARasterSelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡ񱣴ļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditLLARasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QLonLatInterpAtiFromDEM::onpushButtonXYZRasterSelect_clicked() +{ + QString fileNames = QFileDialog::getSaveFileName( + this, // + tr(u8"ѡתļ"), // + QString(), // Ĭ· + tr(ENVI_FILE_FORMAT_FILTER) // ļ + ); + // ûѡļ + if (!fileNames.isEmpty()) { + QString message = "ѡļУ\n"; + this->ui->lineEditXYZRasterPath->setText(fileNames); + } + else { + QMessageBox::information(this, tr(u8"ûѡļ"), tr(u8"ûѡκļ")); + } +} + +void QLonLatInterpAtiFromDEM::onbuttonBox_accepted() +{ + QString llrasterpath = ui->lineEditLonLatRasterPath->text(); + QString demrasterpath = ui->lineEditDEMRasterPath->text(); + QString llarasterpath = ui->lineEditLLARasterPath->text(); + QString xyzrasterpath = ui->lineEditXYZRasterPath->text(); + + qDebug() << "DEM߳С"; + InterpLookTableRfromDEM(llrasterpath, demrasterpath, llarasterpath); + qDebug() << "γתΪXYZС"; + RangeLooktableLLA_2_RangeLooktableXYZ(llarasterpath, xyzrasterpath); + QMessageBox::information(this, tr(u8"ʾ"), tr(u8"")); +} + +void QLonLatInterpAtiFromDEM::onbuttonBox_rejected() +{ + this->close(); +} + diff --git a/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h new file mode 100644 index 0000000..b728ef8 --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +namespace Ui { + class QLonLatInterpAtiFromDEMClass; +} + +class QLonLatInterpAtiFromDEM : public QDialog +{ + Q_OBJECT + +public: + QLonLatInterpAtiFromDEM(QWidget *parent = nullptr); + ~QLonLatInterpAtiFromDEM(); + + +public slots: + void onpushButtonLonLatRasterSelect_clicked(); + void onpushButtonDEMRasterSelect_clicked(); + void onpushButtonLLARasterSelect_clicked(); + void onpushButtonXYZRasterSelect_clicked(); + void onbuttonBox_accepted(); + void onbuttonBox_rejected(); + + +private: + Ui::QLonLatInterpAtiFromDEMClass* ui; +}; diff --git a/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui new file mode 100644 index 0000000..4a31eca --- /dev/null +++ b/Toolbox/SimulationSARTool/SARImage/QLonLatInterpAtiFromDEM.ui @@ -0,0 +1,191 @@ + + + QLonLatInterpAtiFromDEMClass + + + + 0 + 0 + 600 + 400 + + + + QLonLatInterpAtiFromDEM + + + + + + + 0 + 30 + + + + 经纬度数据矩阵: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 待采样DEM: + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 采样矩阵(LLA): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + 采样矩阵(XYZ): + + + + + + + + 0 + 30 + + + + + + + + + + + + 0 + 30 + + + + 选择 + + + + + + + + 0 + 30 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.cpp b/Toolbox/SimulationSARTool/SimulationSARTool.cpp index 0d16cc6..0d01313 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.cpp +++ b/Toolbox/SimulationSARTool/SimulationSARTool.cpp @@ -13,6 +13,8 @@ #include "QLookTableResampleFromWGS84ToRange.h" #include "QSARSimulationComplexEchoDataDialog.h" #include "QSimulationBPImageMultiProduction.h" +#include "QLonLatInterpAtiFromDEM.h" +#include "QL1ASARProcessDialog.h" void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWidget* toolbox) @@ -31,6 +33,7 @@ void RegisterPreToolBox(LAMPMainWidget::RasterMainWidget* mainwindows, ToolBoxWi emit toolbox->addBoxToolItemSIGNAL(new QLookTableResampleFromWGS84ToRangeToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSARSimulationComplexEchoDataDialogToolButton(toolbox)); emit toolbox->addBoxToolItemSIGNAL(new QSimulationBPImageMultiProductionToolButton(toolbox)); + emit toolbox->addBoxToolItemSIGNAL(new QLonLatInterpAtiFromDEMToolButton(toolbox)); } @@ -279,3 +282,37 @@ void QSimulationBPImageMultiProductionToolButton::run() QSimulationBPImageMultiProduction* dialog = new QSimulationBPImageMultiProduction; dialog->show(); } + +QLonLatInterpAtiFromDEMToolButton::QLonLatInterpAtiFromDEMToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"бƽ"); +} + +QLonLatInterpAtiFromDEMToolButton::~QLonLatInterpAtiFromDEMToolButton() +{ +} + +void QLonLatInterpAtiFromDEMToolButton::run() +{ + QLonLatInterpAtiFromDEM* dialog = new QLonLatInterpAtiFromDEM; + dialog->show(); +} + +QL1ASARProcessDialogToolButton::QL1ASARProcessDialogToolButton(QWidget* parent) +{ + this->toolPath = QVector(0); + this->toolPath.push_back(u8"񹤾߿"); + this->toolname = QString(u8"L1AƷ"); +} + +QL1ASARProcessDialogToolButton::~QL1ASARProcessDialogToolButton() +{ +} + +void QL1ASARProcessDialogToolButton::run() +{ + QL1ASARProcessDialog* dialog = new QL1ASARProcessDialog; + dialog->show(); +} diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.h b/Toolbox/SimulationSARTool/SimulationSARTool.h index 011b236..9c20a47 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.h +++ b/Toolbox/SimulationSARTool/SimulationSARTool.h @@ -175,3 +175,31 @@ public: }; + + + + +class SIMULATIONSARTOOL_EXPORT QLonLatInterpAtiFromDEMToolButton : public QToolAbstract { + Q_OBJECT +public: + QLonLatInterpAtiFromDEMToolButton(QWidget* parent = nullptr); + ~QLonLatInterpAtiFromDEMToolButton(); +public: + virtual void run() override; + +}; + + + + + +class SIMULATIONSARTOOL_EXPORT QL1ASARProcessDialogToolButton : public QToolAbstract { + Q_OBJECT +public: + QL1ASARProcessDialogToolButton(QWidget* parent = nullptr); + ~QL1ASARProcessDialogToolButton(); +public: + virtual void run() override; + +}; + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj index 62fb8ce..e4bdf9f 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj @@ -221,6 +221,8 @@ + + @@ -256,6 +258,8 @@ + + @@ -295,6 +299,8 @@ + + diff --git a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters index b8510fa..e32b42e 100644 --- a/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters +++ b/Toolbox/SimulationSARTool/SimulationSARTool.vcxproj.filters @@ -157,6 +157,12 @@ SARImage + + SARImage + + + SARImage + @@ -207,6 +213,12 @@ SARImage + + SARImage + + + SARImage + @@ -260,6 +272,12 @@ SARImage + + SARImage + + + SARImage +