Line data Source code
1 : /****************************************************************************** 2 : * $Id$ 3 : * 4 : * Project: GDAL 5 : * Purpose: Implements Arc/Info ASCII Grid Format. 6 : * Author: Frank Warmerdam, warmerdam@pobox.com 7 : * 8 : ****************************************************************************** 9 : * Copyright (c) 2001, Frank Warmerdam (warmerdam@pobox.com) 10 : * Copyright (c) 2007-2012, Even Rouault <even dot rouault at spatialys.com> 11 : * Copyright (c) 2014, Kyle Shannon <kyle at pobox dot 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_AAIGRID_AAIGRIDDATASET_H_INCLUDED 33 : #define GDAL_FRMTS_AAIGRID_AAIGRIDDATASET_H_INCLUDED 34 : 35 : // We need cpl_port as first include to avoid VSIStatBufL being not 36 : // defined on i586-mingw32msvc. 37 : #include "cpl_port.h" 38 : #include "gdal_frmts.h" 39 : 40 : #include <cctype> 41 : #include <climits> 42 : #include <cmath> 43 : #include <cstddef> 44 : #include <cstdio> 45 : #include <cstdlib> 46 : #include <cstring> 47 : #if HAVE_FCNTL_H 48 : #include <fcntl.h> 49 : #endif 50 : 51 : #include <algorithm> 52 : #include <limits> 53 : #include <string> 54 : 55 : #include "cpl_conv.h" 56 : #include "cpl_error.h" 57 : #include "cpl_progress.h" 58 : #include "cpl_string.h" 59 : #include "cpl_vsi.h" 60 : #include "gdal.h" 61 : #include "gdal_pam.h" 62 : #include "gdal_priv.h" 63 : #include "ogr_core.h" 64 : #include "ogr_spatialref.h" 65 : 66 : typedef enum 67 : { 68 : FORMAT_AAIG, 69 : FORMAT_GRASSASCII, 70 : FORMAT_ISG, 71 : } GridFormat; 72 : 73 : /************************************************************************/ 74 : /* ==================================================================== */ 75 : /* AAIGDataset */ 76 : /* ==================================================================== */ 77 : /************************************************************************/ 78 : 79 : class AAIGRasterBand; 80 : 81 : class AAIGDataset CPL_NON_FINAL : public GDALPamDataset 82 : { 83 : friend class AAIGRasterBand; 84 : 85 : VSILFILE *fp; 86 : 87 : char **papszPrj; 88 : CPLString osPrjFilename; 89 : OGRSpatialReference m_oSRS{}; 90 : 91 : unsigned char achReadBuf[256]; 92 : GUIntBig nBufferOffset; 93 : int nOffsetInBuffer; 94 : 95 : char Getc(); 96 : GUIntBig Tell() const; 97 : int Seek(GUIntBig nOffset); 98 : 99 : protected: 100 : GDALDataType eDataType; 101 : double adfGeoTransform[6]; 102 : bool bNoDataSet; 103 : double dfNoDataValue; 104 : CPLString osUnits{}; 105 : 106 : virtual int ParseHeader(const char *pszHeader, const char *pszDataType); 107 : 108 : public: 109 : AAIGDataset(); 110 : ~AAIGDataset() override; 111 : 112 : char **GetFileList(void) override; 113 : 114 : static GDALDataset *CommonOpen(GDALOpenInfo *poOpenInfo, 115 : GridFormat eFormat); 116 : 117 : static GDALDataset *Open(GDALOpenInfo *); 118 : static int Identify(GDALOpenInfo *); 119 : static CPLErr Delete(const char *pszFilename); 120 : static CPLErr Remove(const char *pszFilename, int bRepError); 121 : static GDALDataset *CreateCopy(const char *pszFilename, 122 : GDALDataset *poSrcDS, int bStrict, 123 : char **papszOptions, 124 : GDALProgressFunc pfnProgress, 125 : void *pProgressData); 126 : 127 : CPLErr GetGeoTransform(double *) override; 128 : const OGRSpatialReference *GetSpatialRef() const override; 129 : }; 130 : 131 : /************************************************************************/ 132 : /* ==================================================================== */ 133 : /* GRASSASCIIDataset */ 134 : /* ==================================================================== */ 135 : /************************************************************************/ 136 : 137 : class GRASSASCIIDataset final : public AAIGDataset 138 : { 139 : int ParseHeader(const char *pszHeader, const char *pszDataType) override; 140 : 141 : public: 142 2 : GRASSASCIIDataset() : AAIGDataset() 143 : { 144 2 : } 145 : 146 4 : ~GRASSASCIIDataset() override 147 2 : { 148 4 : } 149 : 150 : static GDALDataset *Open(GDALOpenInfo *); 151 : static int Identify(GDALOpenInfo *); 152 : }; 153 : 154 : /************************************************************************/ 155 : /* ==================================================================== */ 156 : /* ISGDataset */ 157 : /* ==================================================================== */ 158 : /************************************************************************/ 159 : 160 : class ISGDataset final : public AAIGDataset 161 : { 162 : int ParseHeader(const char *pszHeader, const char *pszDataType) override; 163 : 164 : public: 165 7 : ISGDataset() : AAIGDataset() 166 : { 167 7 : } 168 : 169 : static GDALDataset *Open(GDALOpenInfo *); 170 : static int Identify(GDALOpenInfo *); 171 : }; 172 : 173 : /************************************************************************/ 174 : /* ==================================================================== */ 175 : /* AAIGRasterBand */ 176 : /* ==================================================================== */ 177 : /************************************************************************/ 178 : 179 : class AAIGRasterBand final : public GDALPamRasterBand 180 : { 181 : friend class AAIGDataset; 182 : 183 : GUIntBig *panLineOffset; 184 : 185 : public: 186 : AAIGRasterBand(AAIGDataset *, int); 187 : ~AAIGRasterBand() override; 188 : 189 : double GetNoDataValue(int *) override; 190 : CPLErr SetNoDataValue(double) override; 191 : CPLErr IReadBlock(int, int, void *) override; 192 : }; 193 : 194 : #endif // GDAL_FRMTS_AAIGRID_AAIGRIDDATASET_H_INCLUDED