Line data Source code
1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: ENVI .hdr Driver
5 : * Purpose: Implementation of ENVI .hdr labelled raw raster support.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : * Maintainer: Chris Padwick (cpadwick at ittvis.com)
8 : *
9 : ******************************************************************************
10 : * Copyright (c) 2002, Frank Warmerdam
11 : * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com>
12 : *
13 : * Permission is hereby granted, free of charge, to any person obtaining a
14 : * copy of this software and associated documentation files (the "Software"),
15 : * to deal in the Software without restriction, including without limitation
16 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 : * and/or sell copies of the Software, and to permit persons to whom the
18 : * Software is furnished to do so, subject to the following conditions:
19 : *
20 : * The above copyright notice and this permission notice shall be included
21 : * in all copies or substantial portions of the Software.
22 : *
23 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 : * DEALINGS IN THE SOFTWARE.
30 : ****************************************************************************/
31 :
32 : #ifndef GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED
33 : #define GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED
34 :
35 : #include "cpl_port.h"
36 : #include "rawdataset.h"
37 :
38 : #include <climits>
39 : #include <cmath>
40 : #include <cstdlib>
41 : #include <cstring>
42 : #if HAVE_FCNTL_H
43 : #include <fcntl.h>
44 : #endif
45 :
46 : #include <algorithm>
47 : #include <limits>
48 : #include <string>
49 :
50 : #include "cpl_conv.h"
51 : #include "cpl_error.h"
52 : #include "cpl_string.h"
53 : #include "cpl_vsi.h"
54 : #include "gdal.h"
55 : #include "gdal_frmts.h"
56 : #include "gdal_priv.h"
57 : #include "ogr_core.h"
58 : #include "ogr_spatialref.h"
59 : #include "ogr_srs_api.h"
60 :
61 : class ENVIRasterBand;
62 :
63 : class ENVIDataset final : public RawDataset
64 : {
65 : friend class ENVIRasterBand;
66 :
67 : VSILFILE *fpImage; // Image data file.
68 : VSILFILE *fp; // Header file
69 : char *pszHDRFilename;
70 :
71 : bool bFoundMapinfo;
72 : bool bHeaderDirty;
73 : bool bFillFile;
74 :
75 : double adfGeoTransform[6];
76 :
77 : OGRSpatialReference m_oSRS{};
78 :
79 : CPLStringList m_aosHeader{};
80 :
81 : CPLString osStaFilename{};
82 :
83 : std::vector<GDAL_GCP> m_asGCPs{};
84 :
85 : bool ReadHeader(VSILFILE *);
86 : bool ProcessMapinfo(const char *);
87 : void ProcessRPCinfo(const char *, int, int);
88 : void ProcessGeoPoints(const char *);
89 : void ProcessStatsFile();
90 : static int byteSwapInt(int);
91 : static float byteSwapFloat(float);
92 : static double byteSwapDouble(double);
93 : static void SetENVIDatum(OGRSpatialReference *, const char *);
94 : static void SetENVIEllipse(OGRSpatialReference *, char **);
95 : void WriteProjectionInfo();
96 : bool ParseRpcCoeffsMetaDataString(const char *psName, char *papszVal[],
97 : int &idx);
98 : bool WriteRpcInfo();
99 : bool WritePseudoGcpInfo();
100 :
101 92 : void SetFillFile()
102 : {
103 92 : bFillFile = true;
104 92 : }
105 :
106 : static char **SplitList(const char *);
107 :
108 : enum Interleave
109 : {
110 : BSQ,
111 : BIL,
112 : BIP
113 : } interleave;
114 :
115 : static int GetEnviType(GDALDataType eType);
116 :
117 : CPL_DISALLOW_COPY_ASSIGN(ENVIDataset)
118 :
119 : CPLErr Close() override;
120 :
121 : public:
122 : ENVIDataset();
123 : ~ENVIDataset() override;
124 :
125 : CPLErr FlushCache(bool bAtClosing) override;
126 : CPLErr GetGeoTransform(double *padfTransform) override;
127 : CPLErr SetGeoTransform(double *) override;
128 :
129 : const OGRSpatialReference *GetSpatialRef() const override;
130 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override;
131 :
132 : char **GetFileList() override;
133 :
134 : void SetDescription(const char *) override;
135 :
136 : CPLErr SetMetadata(char **papszMetadata,
137 : const char *pszDomain = "") override;
138 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue,
139 : const char *pszDomain = "") override;
140 : CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList,
141 : const OGRSpatialReference *poSRS) override;
142 : int GetGCPCount() override;
143 : const GDAL_GCP *GetGCPs() override;
144 :
145 : bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override;
146 :
147 : static GDALDataset *Open(GDALOpenInfo *);
148 : static ENVIDataset *Open(GDALOpenInfo *, bool bFileSizeCheck);
149 : static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize,
150 : int nBands, GDALDataType eType,
151 : char **papszOptions);
152 : };
153 :
154 : /************************************************************************/
155 : /* ==================================================================== */
156 : /* ENVIRasterBand */
157 : /* ==================================================================== */
158 : /************************************************************************/
159 :
160 : class ENVIRasterBand final : public RawRasterBand
161 : {
162 : CPL_DISALLOW_COPY_ASSIGN(ENVIRasterBand)
163 :
164 : public:
165 : ENVIRasterBand(GDALDataset *poDSIn, int nBandIn, VSILFILE *fpRawIn,
166 : vsi_l_offset nImgOffsetIn, int nPixelOffsetIn,
167 : int nLineOffsetIn, GDALDataType eDataTypeIn,
168 : RawRasterBand::ByteOrder eByteOrderIn);
169 :
170 : void SetDescription(const char *) override;
171 : CPLErr SetNoDataValue(double) override;
172 : CPLErr SetColorInterpretation(GDALColorInterp eColorInterp) override;
173 : CPLErr SetOffset(double) override;
174 : CPLErr SetScale(double) override;
175 :
176 : CPLErr SetCategoryNames(char **) override;
177 : };
178 :
179 : #endif // GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED
|