Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: gdal "raster compare" subcommand 5 : * Author: Even Rouault <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2025, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #ifndef GDALALG_RASTER_COMPARE_INCLUDED 14 : #define GDALALG_RASTER_COMPARE_INCLUDED 15 : 16 : #include "gdalalg_raster_pipeline.h" 17 : 18 : //! @cond Doxygen_Suppress 19 : 20 : /************************************************************************/ 21 : /* GDALRasterCompareAlgorithm */ 22 : /************************************************************************/ 23 : 24 : class GDALRasterCompareAlgorithm /* non final */ 25 : : public GDALRasterPipelineStepAlgorithm 26 : { 27 : public: 28 : static constexpr const char *NAME = "compare"; 29 : static constexpr const char *DESCRIPTION = "Compare two raster datasets."; 30 : static constexpr const char *HELP_URL = 31 : "/programs/gdal_raster_compare.html"; 32 : 33 : explicit GDALRasterCompareAlgorithm(bool standaloneStep = false); 34 : 35 6 : bool IsNativelyStreamingCompatible() const override 36 : { 37 6 : return false; 38 : } 39 : 40 27 : bool CanBeLastStep() const override 41 : { 42 27 : return true; 43 : } 44 : 45 : private: 46 : bool RunStep(GDALPipelineStepRunContext &ctxt) override; 47 : 48 : bool BinaryComparison(std::vector<std::string> &aosReport, 49 : GDALDataset *poRefDS, GDALDataset *poInputDS); 50 : 51 : void DatasetComparison(std::vector<std::string> &aosReport, 52 : GDALDataset *poRefDS, GDALDataset *poInputDS, 53 : GDALProgressFunc pfnProgress, void *pProgressData); 54 : 55 : static void CRSComparison(std::vector<std::string> &aosReport, 56 : GDALDataset *poRefDS, GDALDataset *poInputDS); 57 : 58 : static void GeoTransformComparison(std::vector<std::string> &aosReport, 59 : GDALDataset *poRefDS, 60 : GDALDataset *poInputDS); 61 : 62 : void BandComparison(std::vector<std::string> &aosReport, 63 : const std::string &bandId, 64 : bool doBandBasedPixelComparison, 65 : GDALRasterBand *poRefBand, GDALRasterBand *poInputBand, 66 : GDALProgressFunc pfnProgress, void *pProgressData); 67 : 68 : static void MetadataComparison(std::vector<std::string> &aosReport, 69 : const std::string &metadataDomain, 70 : CSLConstList aosRef, CSLConstList aosInput); 71 : 72 : GDALArgDatasetValue m_referenceDataset{}; 73 : bool m_skipAllOptional = false; 74 : bool m_skipBinary = false; 75 : bool m_skipCRS = false; 76 : bool m_skipGeotransform = false; 77 : bool m_skipOverview = false; 78 : bool m_skipMetadata = false; 79 : bool m_skipRPC = false; 80 : bool m_skipGeolocation = false; 81 : bool m_skipSubdataset = false; 82 : // If adding a new skip flag, make sure that m_skipAll takes it into account 83 : int m_retCode = 0; 84 : }; 85 : 86 : /************************************************************************/ 87 : /* GDALRasterCompareAlgorithmStandalone */ 88 : /************************************************************************/ 89 : 90 366 : class GDALRasterCompareAlgorithmStandalone final 91 : : public GDALRasterCompareAlgorithm 92 : { 93 : public: 94 183 : GDALRasterCompareAlgorithmStandalone() 95 183 : : GDALRasterCompareAlgorithm(/* standaloneStep = */ true) 96 : { 97 183 : } 98 : 99 : ~GDALRasterCompareAlgorithmStandalone() override; 100 : }; 101 : 102 : //! @endcond 103 : 104 : #endif