Line data Source code
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 : * Permission is hereby granted, free of charge, to any person obtaining a
12 : * copy of this software and associated documentation files (the "Software"),
13 : * to deal in the Software without restriction, including without limitation
14 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 : * and/or sell copies of the Software, and to permit persons to whom the
16 : * Software is furnished to do so, subject to the following conditions:
17 : *
18 : * The above copyright notice and this permission notice shall be included
19 : * in all copies or substantial portions of the Software.
20 : *
21 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 : * DEALINGS IN THE SOFTWARE.
28 : ****************************************************************************/
29 :
30 : #ifndef VICARDATASET_H
31 : #define VICARDATASET_H
32 :
33 : #include "cpl_string.h"
34 : #include "gdal_frmts.h"
35 : #include "ogr_spatialref.h"
36 : #include "ogrsf_frmts.h"
37 : #include "rawdataset.h"
38 : #include "vicarkeywordhandler.h"
39 : #include <array>
40 :
41 : /************************************************************************/
42 : /* ==================================================================== */
43 : /* VICARDataset */
44 : /* ==================================================================== */
45 : /************************************************************************/
46 :
47 : class VICARDataset final : public RawDataset
48 : {
49 : friend class VICARRawRasterBand;
50 : friend class VICARBASICRasterBand;
51 :
52 : VSILFILE *fpImage = nullptr;
53 :
54 : VICARKeywordHandler oKeywords;
55 :
56 : enum CompressMethod
57 : {
58 : COMPRESS_NONE,
59 : COMPRESS_BASIC,
60 : COMPRESS_BASIC2,
61 : };
62 :
63 : CompressMethod m_eCompress = COMPRESS_NONE;
64 :
65 : int m_nRecordSize = 0;
66 : vsi_l_offset m_nImageOffsetWithoutNBB = 0;
67 : int m_nLastRecordOffset = 0;
68 : std::vector<vsi_l_offset> m_anRecordOffsets{}; // for BASIC/BASIC2
69 : std::vector<GByte> m_abyCodedBuffer{};
70 : vsi_l_offset m_nLabelSize = 0;
71 :
72 : CPLJSONObject m_oJSonLabel;
73 : CPLStringList m_aosVICARMD;
74 :
75 : bool m_bGotTransform = false;
76 : std::array<double, 6> m_adfGeoTransform = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
77 :
78 : OGRSpatialReference m_oSRS;
79 :
80 : std::unique_ptr<OGRLayer> m_poLayer;
81 :
82 : bool m_bGeoRefFormatIsMIPL = true;
83 :
84 : CPLString m_osLatitudeType; // creation only
85 : CPLString m_osLongitudeDirection; // creation only
86 : CPLString m_osTargetName; // creation only
87 : bool m_bIsLabelWritten = true; // creation only
88 : bool m_bUseSrcLabel = true; // creation only
89 : bool m_bUseSrcMap = false; // creation only
90 : bool m_bInitToNodata = false; // creation only
91 : CPLJSONObject m_oSrcJSonLabel; // creation only
92 :
93 : const char *GetKeyword(const char *pszPath, const char *pszDefault = "");
94 : void WriteLabel();
95 : void PatchLabel();
96 : void BuildLabel();
97 : void InvalidateLabel();
98 :
99 : static VICARDataset *CreateInternal(const char *pszFilename, int nXSize,
100 : int nYSize, int nBands,
101 : GDALDataType eType,
102 : char **papszOptions);
103 :
104 : void ReadProjectionFromMapGroup();
105 : void ReadProjectionFromGeoTIFFGroup();
106 : void BuildLabelPropertyMap(CPLJSONObject &oLabel);
107 : void BuildLabelPropertyGeoTIFF(CPLJSONObject &oLabel);
108 :
109 : CPLErr Close() override;
110 :
111 : public:
112 : VICARDataset();
113 : virtual ~VICARDataset();
114 :
115 : CPLErr GetGeoTransform(double *padfTransform) override;
116 : CPLErr SetGeoTransform(double *padfTransform) override;
117 :
118 : const OGRSpatialReference *GetSpatialRef() const override;
119 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
120 :
121 : bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override;
122 :
123 : char **GetMetadataDomainList() override;
124 : char **GetMetadata(const char *pszDomain = "") override;
125 : CPLErr SetMetadata(char **papszMD, const char *pszDomain = "") override;
126 :
127 216 : int GetLayerCount() override
128 : {
129 216 : return m_poLayer ? 1 : 0;
130 : }
131 :
132 20 : OGRLayer *GetLayer(int i) override
133 : {
134 20 : return (m_poLayer && i == 0) ? m_poLayer.get() : nullptr;
135 : }
136 :
137 : static GDALDataset *Open(GDALOpenInfo *);
138 : static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
139 : int nBands, GDALDataType eType,
140 : char **papszOptions);
141 : static GDALDataset *CreateCopy(const char *pszFilename,
142 : GDALDataset *poSrcDS, int bStrict,
143 : char **papszOptions,
144 : GDALProgressFunc pfnProgress,
145 : void *pProgressData);
146 :
147 : static GDALDataType GetDataTypeFromFormat(const char *pszFormat);
148 : static bool GetSpacings(const VICARKeywordHandler &keywords,
149 : GUInt64 &nPixelOffset, GUInt64 &nLineOffset,
150 : GUInt64 &nBandOffset,
151 : GUInt64 &nImageOffsetWithoutNBB, GUInt64 &nNBB,
152 : GUInt64 &nImageSize);
153 : };
154 :
155 : #endif // VICARDATASET_H
|