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 : * 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 : GDALGeoTransform m_gt{}; 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 : CSLConstList 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(GDALProgressFunc = nullptr, void * = nullptr) override; 96 : 97 : CPL_DISALLOW_COPY_ASSIGN(VICARDataset) 98 : 99 : public: 100 : VICARDataset(); 101 : ~VICARDataset() override; 102 : 103 : CPLErr GetGeoTransform(GDALGeoTransform >) const override; 104 : CPLErr SetGeoTransform(const GDALGeoTransform >) override; 105 : 106 : const OGRSpatialReference *GetSpatialRef() const override; 107 : CPLErr SetSpatialRef(const OGRSpatialReference *poSRS) override; 108 : 109 : bool GetRawBinaryLayout(GDALDataset::RawBinaryLayout &) override; 110 : 111 : char **GetMetadataDomainList() override; 112 : CSLConstList GetMetadata(const char *pszDomain = "") override; 113 : CPLErr SetMetadata(CSLConstList papszMD, 114 : const char *pszDomain = "") override; 115 : 116 237 : int GetLayerCount() const override 117 : { 118 237 : return m_poLayer ? 1 : 0; 119 : } 120 : 121 20 : const OGRLayer *GetLayer(int i) const override 122 : { 123 20 : return (m_poLayer && i == 0) ? m_poLayer.get() : nullptr; 124 : } 125 : 126 : static GDALDataset *Open(GDALOpenInfo *); 127 : static GDALDataset *Create(const char *pszFilename, int nXSize, int nYSize, 128 : int nBands, GDALDataType eType, 129 : CSLConstList papszOptions); 130 : static GDALDataset *CreateCopy(const char *pszFilename, 131 : GDALDataset *poSrcDS, int bStrict, 132 : CSLConstList papszOptions, 133 : GDALProgressFunc pfnProgress, 134 : void *pProgressData); 135 : 136 : static GDALDataType GetDataTypeFromFormat(const char *pszFormat); 137 : static bool GetSpacings(const VICARKeywordHandler &keywords, 138 : uint64_t &nPixelOffset, uint64_t &nLineOffset, 139 : uint64_t &nBandOffset, 140 : uint64_t &nImageOffsetWithoutNBB, uint64_t &nNBB, 141 : uint64_t &nImageSize); 142 : }; 143 : 144 : #endif // VICARDATASET_H