Coverage Report

Created: 2026-06-30 08:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gdal/frmts/miramon/miramon_dataset.h
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Project:  MiraMon Raster Driver
4
 * Purpose:  Implements MMRDataset class: responsible for generating the
5
 *           main dataset or the subdatasets as needed.
6
 * Author:   Abel Pau
7
 *
8
 ******************************************************************************
9
 * Copyright (c) 2025, Xavier Pons
10
 *
11
 * SPDX-License-Identifier: MIT
12
 ****************************************************************************/
13
14
#ifndef MMRDATASET_H_INCLUDED
15
#define MMRDATASET_H_INCLUDED
16
17
#include <cstddef>
18
#include <vector>
19
#include <optional>
20
#include <array>
21
22
#include "gdal_pam.h"
23
#include "gdal_rat.h"
24
25
#include "../miramon_common/mm_gdal_constants.h"  // For MM_EXT_DBF_N_FIELDS
26
#include "miramon_rel.h"
27
28
/* ==================================================================== */
29
/*                              MMRDataset                              */
30
/* ==================================================================== */
31
32
class MMRRasterBand;
33
class MMRRel;
34
35
/*
36
    * -oo  RAT_OR_CT
37
    Controls whether the Raster Attribute Table (RAT) and/or the Color Table (CT) are exposed.
38
39
      ALL
40
            Expose both the attribute table and the color table. Note that in some software this option may cause visualization and/or legend issues.
41
      RAT
42
            Expose the attribute table only, without the color table.
43
      PER_BAND_ONLY
44
            Expose the color table only, without the attribute table.
45
    */
46
enum class RAT_OR_CT
47
{
48
    ALL,
49
    RAT,
50
    CT
51
};
52
53
class MMRDataset final : public GDALPamDataset
54
{
55
  public:
56
    explicit MMRDataset(GDALOpenInfo *poOpenInfo);  // Used in reading
57
    MMRDataset(GDALProgressFunc pfnProgress, void *pProgressData,
58
               CSLConstList papszOptions, CPLString osFilename,
59
               GDALDataset &oSrcDS, const CPLString &osUsrPattern,
60
               const CPLString &osPattern);  // Used in writing
61
    MMRDataset(const MMRDataset &) =
62
        delete;  // I don't want to construct a MMRDataset from another MMRDataset (effc++)
63
    MMRDataset &operator=(const MMRDataset &) =
64
        delete;  // I don't want to assign a MMRDataset to another MMRDataset (effc++)
65
    ~MMRDataset() override;
66
67
    static int Identify(GDALOpenInfo *);
68
    static GDALDataset *Open(GDALOpenInfo *);
69
    static GDALDataset *CreateCopy(const char *pszFilename,
70
                                   GDALDataset *poSrcDS, int bStrict,
71
                                   CSLConstList papszOptions,
72
                                   GDALProgressFunc pfnProgress,
73
                                   void *pProgressData);
74
75
    MMRRel *GetRel()
76
1.72k
    {
77
1.72k
        return m_pMMRRel.get();
78
1.72k
    }
79
80
    RAT_OR_CT GetRatOrCT() const
81
1.72k
    {
82
1.72k
        return nRatOrCT;
83
1.72k
    }
84
85
  private:
86
    void ReadProjection();
87
    void UpdateProjection(GDALDataset &oSrcDS);
88
    void AssignBandsToSubdataSets();
89
    void CreateSubdatasetsFromBands();
90
    bool CreateRasterBands();
91
    bool BandInTheSameDataset(int nIBand1, int nIBan2) const;
92
93
    int UpdateGeoTransform();
94
    const OGRSpatialReference *GetSpatialRef() const override;
95
    CPLErr GetGeoTransform(GDALGeoTransform &gt) const override;
96
    static CPLString
97
    CreateAssociatedMetadataFileName(const CPLString &osFileName);
98
    static CPLString CreatePatternFileName(const CPLString &osFileName,
99
                                           const CPLString &osPattern);
100
    static bool BandInOptionsList(CSLConstList papszOptions,
101
                                  const CPLString &pszType,
102
                                  const CPLString &osBand);
103
    static bool IsCategoricalBand(GDALDataset &oSrcDS,
104
                                  GDALRasterBand &pRasterBand,
105
                                  CSLConstList papszOptions,
106
                                  const CPLString &osIndexBand);
107
    void WriteRGBMap();
108
109
    bool IsValid() const
110
1.67k
    {
111
1.67k
        return m_bIsValid;
112
1.67k
    }
113
114
    GDALGeoTransform m_gt{};
115
    OGRSpatialReference m_oSRS{};
116
117
    bool m_bIsValid =
118
        false;  // Determines if the created object is valid or not.
119
    std::unique_ptr<MMRRel> m_pMMRRel = nullptr;
120
121
    std::vector<gdal::GCP> m_aoGCPs{};
122
123
    // Numbers of subdatasets (if any) in this dataset.
124
    int m_nNSubdataSets = 0;
125
126
    // To expose CT, RAT or both
127
    RAT_OR_CT nRatOrCT = RAT_OR_CT::ALL;
128
129
    // For writing part
130
    //
131
    // EPSG number
132
    CPLString m_osEPSG = "";
133
    // Global raster dimensions
134
    int m_nWidth = 0;
135
    int m_nHeight = 0;
136
137
    double m_dfMinX = MM_UNDEFINED_STATISTICAL_VALUE;
138
    double m_dfMaxX = -MM_UNDEFINED_STATISTICAL_VALUE;
139
    double m_dfMinY = MM_UNDEFINED_STATISTICAL_VALUE;
140
    double m_dfMaxY = -MM_UNDEFINED_STATISTICAL_VALUE;
141
142
    // If a RGB combination can be done, then a map ".mmm" will be generated
143
    int m_nIBandR = -1;
144
    int m_nIBandG = -1;
145
    int m_nIBandB = -1;
146
};
147
148
#endif  // MMRDATASET_H_INCLUDED