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