Line data Source code
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 : 26 : #include <algorithm> 27 : #include <limits> 28 : #include <string> 29 : 30 : #include "cpl_conv.h" 31 : #include "cpl_error.h" 32 : #include "cpl_string.h" 33 : #include "cpl_vsi.h" 34 : #include "gdal.h" 35 : #include "gdal_frmts.h" 36 : #include "gdal_priv.h" 37 : #include "ogr_core.h" 38 : #include "ogr_spatialref.h" 39 : #include "ogr_srs_api.h" 40 : 41 : class ENVIRasterBand; 42 : 43 : class ENVIDataset final : public RawDataset 44 : { 45 : friend class ENVIRasterBand; 46 : 47 : VSILFILE *fpImage; // Image data file. 48 : VSILFILE *fp; // Header file 49 : char *pszHDRFilename; 50 : 51 : bool bFoundMapinfo; 52 : bool bHeaderDirty; 53 : bool bFillFile; 54 : 55 : GDALGeoTransform m_gt{}; 56 : 57 : OGRSpatialReference m_oSRS{}; 58 : 59 : CPLStringList m_aosHeader{}; 60 : 61 : CPLString osStaFilename{}; 62 : 63 : std::vector<GDAL_GCP> m_asGCPs{}; 64 : 65 : Interleave eInterleave = Interleave::BSQ; 66 : 67 : bool ProcessMapinfo(const char *); 68 : void ProcessRPCinfo(const char *, int, int); 69 : void ProcessGeoPoints(const char *); 70 : void ProcessStatsFile(); 71 : static int byteSwapInt(int); 72 : static float byteSwapFloat(float); 73 : static double byteSwapDouble(double); 74 : static void SetENVIDatum(OGRSpatialReference *, const char *); 75 : static void SetENVIEllipse(OGRSpatialReference *, char **); 76 : void WriteProjectionInfo(); 77 : bool ParseRpcCoeffsMetaDataString(const char *psName, char *papszVal[], 78 : int &idx); 79 : bool WriteRpcInfo(); 80 : bool WritePseudoGcpInfo(); 81 : 82 93 : void SetFillFile() 83 : { 84 93 : bFillFile = true; 85 93 : } 86 : 87 : static char **SplitList(const char *); 88 : 89 : static int GetEnviType(GDALDataType eType); 90 : 91 : CPL_DISALLOW_COPY_ASSIGN(ENVIDataset) 92 : 93 : CPLErr Close() override; 94 : 95 : public: 96 : ENVIDataset(); 97 : ~ENVIDataset() override; 98 : 99 : CPLErr FlushCache(bool bAtClosing) override; 100 : CPLErr GetGeoTransform(GDALGeoTransform >) const override; 101 : CPLErr SetGeoTransform(const GDALGeoTransform >) override; 102 : 103 : const OGRSpatialReference *GetSpatialRef() const override; 104 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override; 105 : 106 : char **GetFileList() override; 107 : 108 : void SetDescription(const char *) override; 109 : 110 : CPLErr SetMetadata(char **papszMetadata, 111 : const char *pszDomain = "") override; 112 : CPLErr SetMetadataItem(const char *pszName, const char *pszValue, 113 : const char *pszDomain = "") override; 114 : CPLErr SetGCPs(int nGCPCount, const GDAL_GCP *pasGCPList, 115 : const OGRSpatialReference *poSRS) override; 116 : int GetGCPCount() override; 117 : const GDAL_GCP *GetGCPs() override; 118 : 119 : bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override; 120 : 121 : static GDALDataset *Open(GDALOpenInfo *); 122 : static ENVIDataset *Open(GDALOpenInfo *, bool bFileSizeCheck); 123 : static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize, 124 : int nBands, GDALDataType eType, 125 : char **papszOptions); 126 : }; 127 : 128 : /************************************************************************/ 129 : /* ==================================================================== */ 130 : /* ENVIRasterBand */ 131 : /* ==================================================================== */ 132 : /************************************************************************/ 133 : 134 : class ENVIRasterBand final : public RawRasterBand 135 : { 136 : CPL_DISALLOW_COPY_ASSIGN(ENVIRasterBand) 137 : 138 : public: 139 : ENVIRasterBand(GDALDataset *poDSIn, int nBandIn, VSILFILE *fpRawIn, 140 : vsi_l_offset nImgOffsetIn, int nPixelOffsetIn, 141 : int nLineOffsetIn, GDALDataType eDataTypeIn, 142 : RawRasterBand::ByteOrder eByteOrderIn); 143 : 144 : void SetDescription(const char *) override; 145 : CPLErr SetNoDataValue(double) override; 146 : CPLErr SetColorInterpretation(GDALColorInterp eColorInterp) override; 147 : CPLErr SetOffset(double) override; 148 : CPLErr SetScale(double) override; 149 : 150 : CPLErr SetCategoryNames(char **) override; 151 : }; 152 : 153 : #endif // GDAL_FRMTS_RAW_ENVIDATASET_H_INCLUDED