/src/gdal/frmts/raw/envidataset.h
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * |
3 | | * Project: ENVI .hdr Driver |
4 | | * Purpose: Implementation of ENVI .hdr labelled raw raster support. |
5 | | * Author: Frank Warmerdam, warmerdam@pobox.com |
6 | | * Maintainer: Chris Padwick (cpadwick at ittvis.com) |
7 | | * |
8 | | ****************************************************************************** |
9 | | * Copyright (c) 2002, Frank Warmerdam |
10 | | * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com> |
11 | | * |
12 | | * SPDX-License-Identifier: MIT |
13 | | ****************************************************************************/ |
14 | | |
15 | | #ifndef GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED |
16 | | #define GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED |
17 | | |
18 | | #include "cpl_port.h" |
19 | | #include "rawdataset.h" |
20 | | |
21 | | #include <climits> |
22 | | #include <cmath> |
23 | | #include <cstdlib> |
24 | | #include <cstring> |
25 | | #if HAVE_FCNTL_H |
26 | | #include <fcntl.h> |
27 | | #endif |
28 | | |
29 | | #include <algorithm> |
30 | | #include <limits> |
31 | | #include <string> |
32 | | |
33 | | #include "cpl_conv.h" |
34 | | #include "cpl_error.h" |
35 | | #include "cpl_string.h" |
36 | | #include "cpl_vsi.h" |
37 | | #include "gdal.h" |
38 | | #include "gdal_frmts.h" |
39 | | #include "gdal_priv.h" |
40 | | #include "ogr_core.h" |
41 | | #include "ogr_spatialref.h" |
42 | | #include "ogr_srs_api.h" |
43 | | |
44 | | class ENVIRasterBand; |
45 | | |
46 | | class ENVIDataset final : public RawDataset |
47 | | { |
48 | | friend class ENVIRasterBand; |
49 | | |
50 | | VSILFILE *fpImage; // Image data file. |
51 | | VSILFILE *fp; // Header file |
52 | | char *pszHDRFilename; |
53 | | |
54 | | bool bFoundMapinfo; |
55 | | bool bHeaderDirty; |
56 | | bool bFillFile; |
57 | | |
58 | | double adfGeoTransform[6]; |
59 | | |
60 | | OGRSpatialReference m_oSRS{}; |
61 | | |
62 | | CPLStringList m_aosHeader{}; |
63 | | |
64 | | CPLString osStaFilename{}; |
65 | | |
66 | | std::vector<GDAL_GCP> m_asGCPs{}; |
67 | | |
68 | | Interleave eInterleave = Interleave::BSQ; |
69 | | |
70 | | bool ReadHeader(VSILFILE *); |
71 | | bool ProcessMapinfo(const char *); |
72 | | void ProcessRPCinfo(const char *, int, int); |
73 | | void ProcessGeoPoints(const char *); |
74 | | void ProcessStatsFile(); |
75 | | static int byteSwapInt(int); |
76 | | static float byteSwapFloat(float); |
77 | | static double byteSwapDouble(double); |
78 | | static void SetENVIDatum(OGRSpatialReference *, const char *); |
79 | | static void SetENVIEllipse(OGRSpatialReference *, char **); |
80 | | void WriteProjectionInfo(); |
81 | | bool ParseRpcCoeffsMetaDataString(const char *psName, char *papszVal[], |
82 | | int &idx); |
83 | | bool WriteRpcInfo(); |
84 | | bool WritePseudoGcpInfo(); |
85 | | |
86 | | void SetFillFile() |
87 | 0 | { |
88 | 0 | bFillFile = true; |
89 | 0 | } |
90 | | |
91 | | static char **SplitList(const char *); |
92 | | |
93 | | static int GetEnviType(GDALDataType eType); |
94 | | |
95 | | CPL_DISALLOW_COPY_ASSIGN(ENVIDataset) |
96 | | |
97 | | CPLErr Close() override; |
98 | | |
99 | | public: |
100 | | ENVIDataset(); |
101 | | ~ENVIDataset() override; |
102 | | |
103 | | CPLErr FlushCache(bool bAtClosing) override; |
104 | | CPLErr GetGeoTransform(double *padfTransform) override; |
105 | | CPLErr SetGeoTransform(double *) override; |
106 | | |
107 | | const OGRSpatialReference *GetSpatialRef() const override; |
108 | | CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override; |
109 | | |
110 | | char **GetFileList() override; |
111 | | |
112 | | void SetDescription(const char *) override; |
113 | | |
114 | | CPLErr SetMetadata(char **papszMetadata, |
115 | | const char *pszDomain = "") override; |
116 | | CPLErr SetMetadataItem(const char *pszName, const char *pszValue, |
117 | | const char *pszDomain = "") override; |
118 | | CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, |
119 | | const OGRSpatialReference *poSRS) override; |
120 | | int GetGCPCount() override; |
121 | | const GDAL_GCP *GetGCPs() override; |
122 | | |
123 | | bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override; |
124 | | |
125 | | static GDALDataset *Open(GDALOpenInfo *); |
126 | | static ENVIDataset *Open(GDALOpenInfo *, bool bFileSizeCheck); |
127 | | static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize, |
128 | | int nBands, GDALDataType eType, |
129 | | char **papszOptions); |
130 | | }; |
131 | | |
132 | | /************************************************************************/ |
133 | | /* ==================================================================== */ |
134 | | /* ENVIRasterBand */ |
135 | | /* ==================================================================== */ |
136 | | /************************************************************************/ |
137 | | |
138 | | class ENVIRasterBand final : public RawRasterBand |
139 | | { |
140 | | CPL_DISALLOW_COPY_ASSIGN(ENVIRasterBand) |
141 | | |
142 | | public: |
143 | | ENVIRasterBand(GDALDataset *poDSIn, int nBandIn, VSILFILE *fpRawIn, |
144 | | vsi_l_offset nImgOffsetIn, int nPixelOffsetIn, |
145 | | int nLineOffsetIn, GDALDataType eDataTypeIn, |
146 | | RawRasterBand::ByteOrder eByteOrderIn); |
147 | | |
148 | | void SetDescription(const char *) override; |
149 | | CPLErr SetNoDataValue(double) override; |
150 | | CPLErr SetColorInterpretation(GDALColorInterp eColorInterp) override; |
151 | | CPLErr SetOffset(double) override; |
152 | | CPLErr SetScale(double) override; |
153 | | |
154 | | CPLErr SetCategoryNames(char **) override; |
155 | | }; |
156 | | |
157 | | #endif // GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED |