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 8 : bool IsNativelyStreamingCompatible() const override 36 : { 37 8 : return false; 38 : } 39 : 40 16 : bool CanBeLastStep() const override 41 : { 42 16 : return true; 43 : } 44 : 45 204 : int GetOutputType() const override 46 : { 47 204 : return 0; 48 : } 49 : 50 : private: 51 : bool RunStep(GDALPipelineStepRunContext &ctxt) override; 52 : 53 : bool BinaryComparison(std::vector<std::string> &aosReport, 54 : GDALDataset *poRefDS, GDALDataset *poInputDS); 55 : 56 : void DatasetComparison(std::vector<std::string> &aosReport, 57 : GDALDataset *poRefDS, GDALDataset *poInputDS, 58 : GDALProgressFunc pfnProgress, void *pProgressData); 59 : 60 : static void CRSComparison(std::vector<std::string> &aosReport, 61 : GDALDataset *poRefDS, GDALDataset *poInputDS); 62 : 63 : static void GeoTransformComparison(std::vector<std::string> &aosReport, 64 : GDALDataset *poRefDS, 65 : GDALDataset *poInputDS); 66 : 67 : void BandComparison(std::vector<std::string> &aosReport, 68 : const std::string &bandId, 69 : bool doBandBasedPixelComparison, 70 : GDALRasterBand *poRefBand, GDALRasterBand *poInputBand, 71 : GDALProgressFunc pfnProgress, void *pProgressData); 72 : 73 : static void MetadataComparison(std::vector<std::string> &aosReport, 74 : const std::string &metadataDomain, 75 : CSLConstList aosRef, CSLConstList aosInput); 76 : 77 : GDALArgDatasetValue m_referenceDataset{}; 78 : bool m_skipAllOptional = false; 79 : bool m_skipBinary = false; 80 : bool m_skipCRS = false; 81 : bool m_skipGeotransform = false; 82 : bool m_skipOverview = false; 83 : bool m_skipMetadata = false; 84 : bool m_skipRPC = false; 85 : bool m_skipGeolocation = false; 86 : bool m_skipSubdataset = false; 87 : // If adding a new skip flag, make sure that m_skipAll takes it into account 88 : int m_retCode = 0; 89 : }; 90 : 91 : /************************************************************************/ 92 : /* GDALRasterCompareAlgorithmStandalone */ 93 : /************************************************************************/ 94 : 95 420 : class GDALRasterCompareAlgorithmStandalone final 96 : : public GDALRasterCompareAlgorithm 97 : { 98 : public: 99 210 : GDALRasterCompareAlgorithmStandalone() 100 210 : : GDALRasterCompareAlgorithm(/* standaloneStep = */ true) 101 : { 102 210 : } 103 : 104 : ~GDALRasterCompareAlgorithmStandalone() override; 105 : }; 106 : 107 : //! @endcond 108 : 109 : #endif