/src/gdal/frmts/pds/vicardataset.h
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: VICAR Driver; JPL/MIPL VICAR Format |
4 | | * Purpose: Implementation of VICARDataset |
5 | | * Author: Even Rouault, <even.rouault at spatialys.com> |
6 | | * |
7 | | ****************************************************************************** |
8 | | * Copyright (c) 2014, Sebastian Walter <sebastian dot walter at fu-berlin dot |
9 | | *de> Copyright (c) 2019, Even Rouault, <even.rouault at spatialys.com> |
10 | | * |
11 | | * SPDX-License-Identifier: MIT |
12 | | ****************************************************************************/ |
13 | | |
14 | | #ifndef VICARDATASET_H |
15 | | #define VICARDATASET_H |
16 | | |
17 | | #include "cpl_string.h" |
18 | | #include "gdal_frmts.h" |
19 | | #include "ogr_spatialref.h" |
20 | | #include "ogrsf_frmts.h" |
21 | | #include "rawdataset.h" |
22 | | #include "vicarkeywordhandler.h" |
23 | | #include <array> |
24 | | |
25 | | /************************************************************************/ |
26 | | /* ==================================================================== */ |
27 | | /* VICARDataset */ |
28 | | /* ==================================================================== */ |
29 | | /************************************************************************/ |
30 | | |
31 | | class VICARDataset final : public RawDataset |
32 | | { |
33 | | friend class VICARRawRasterBand; |
34 | | friend class VICARBASICRasterBand; |
35 | | |
36 | | VSILFILE *fpImage = nullptr; |
37 | | |
38 | | VICARKeywordHandler oKeywords; |
39 | | |
40 | | enum CompressMethod |
41 | | { |
42 | | COMPRESS_NONE, |
43 | | COMPRESS_BASIC, |
44 | | COMPRESS_BASIC2, |
45 | | }; |
46 | | |
47 | | CompressMethod m_eCompress = COMPRESS_NONE; |
48 | | |
49 | | int m_nRecordSize = 0; |
50 | | vsi_l_offset m_nImageOffsetWithoutNBB = 0; |
51 | | int m_nLastRecordOffset = 0; |
52 | | std::vector<vsi_l_offset> m_anRecordOffsets{}; // for BASIC/BASIC2 |
53 | | std::vector<GByte> m_abyCodedBuffer{}; |
54 | | vsi_l_offset m_nLabelSize = 0; |
55 | | |
56 | | CPLJSONObject m_oJSonLabel; |
57 | | CPLStringList m_aosVICARMD; |
58 | | |
59 | | bool m_bGotTransform = false; |
60 | | std::array<double, 6> m_adfGeoTransform = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}}; |
61 | | |
62 | | OGRSpatialReference m_oSRS; |
63 | | |
64 | | std::unique_ptr<OGRLayer> m_poLayer; |
65 | | |
66 | | bool m_bGeoRefFormatIsMIPL = true; |
67 | | |
68 | | CPLString m_osLatitudeType; // creation only |
69 | | CPLString m_osLongitudeDirection; // creation only |
70 | | CPLString m_osTargetName; // creation only |
71 | | bool m_bIsLabelWritten = true; // creation only |
72 | | bool m_bUseSrcLabel = true; // creation only |
73 | | bool m_bUseSrcMap = false; // creation only |
74 | | bool m_bInitToNodata = false; // creation only |
75 | | CPLJSONObject m_oSrcJSonLabel; // creation only |
76 | | |
77 | | const char *GetKeyword(const char *pszPath, const char *pszDefault = ""); |
78 | | void WriteLabel(); |
79 | | void PatchLabel(); |
80 | | void BuildLabel(); |
81 | | void InvalidateLabel(); |
82 | | |
83 | | static VICARDataset *CreateInternal(const char *pszFilename, int nXSize, |
84 | | int nYSize, int nBands, |
85 | | GDALDataType eType, |
86 | | char **papszOptions); |
87 | | |
88 | | void ReadProjectionFromMapGroup(); |
89 | | void BuildLabelPropertyMap(CPLJSONObject &oLabel); |
90 | | #if defined(HAVE_TIFF) && defined(HAVE_GEOTIFF) |
91 | | void ReadProjectionFromGeoTIFFGroup(); |
92 | | void BuildLabelPropertyGeoTIFF(CPLJSONObject &oLabel); |
93 | | #endif |
94 | | |
95 | | CPLErr Close() override; |
96 | | |
97 | | public: |
98 | | VICARDataset(); |
99 | | virtual ~VICARDataset(); |
100 | | |
101 | | CPLErr GetGeoTransform(double *padfTransform) override; |
102 | | CPLErr SetGeoTransform(double *padfTransform) override; |
103 | | |
104 | | const OGRSpatialReference *GetSpatialRef() const override; |
105 | | CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override; |
106 | | |
107 | | bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override; |
108 | | |
109 | | char **GetMetadataDomainList() override; |
110 | | char **GetMetadata(const char *pszDomain = "") override; |
111 | | CPLErr SetMetadata(char **papszMD, const char *pszDomain = "") override; |
112 | | |
113 | | int GetLayerCount() override |
114 | 0 | { |
115 | 0 | return m_poLayer ? 1 : 0; |
116 | 0 | } |
117 | | |
118 | | OGRLayer *GetLayer(int i) override |
119 | 0 | { |
120 | 0 | return (m_poLayer && i == 0) ? m_poLayer.get() : nullptr; |
121 | 0 | } |
122 | | |
123 | | static GDALDataset *Open(GDALOpenInfo *); |
124 | | static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize, |
125 | | int nBands, GDALDataType eType, |
126 | | char **papszOptions); |
127 | | static GDALDataset *CreateCopy(const char *pszFilename, |
128 | | GDALDataset *poSrcDS, int bStrict, |
129 | | char **papszOptions, |
130 | | GDALProgressFunc pfnProgress, |
131 | | void *pProgressData); |
132 | | |
133 | | static GDALDataType GetDataTypeFromFormat(const char *pszFormat); |
134 | | static bool GetSpacings(const VICARKeywordHandler &keywords, |
135 | | uint64_t &nPixelOffset, uint64_t &nLineOffset, |
136 | | uint64_t &nBandOffset, |
137 | | uint64_t &nImageOffsetWithoutNBB, uint64_t &nNBB, |
138 | | uint64_t &nImageSize); |
139 | | }; |
140 | | |
141 | | #endif // VICARDATASET_H |