1 /******************************************************************************
2  * $Id: msgdataset.h d23b5a0d22b88657e4fc31f2513701842f0b0585 2019-08-11 03:09:59 +0200 Even Rouault $
3  *
4  * Project:  MSG Driver
5  * Purpose:  GDALDataset driver for MSG translator for read support.
6  * Author:   Bas Retsios, retsios@itc.nl
7  *
8  ******************************************************************************
9  * Copyright (c) 2004, ITC
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ******************************************************************************/
29 
30 #include "gdal_priv.h"
31 #include "cpl_csv.h"
32 #include "ogr_spatialref.h"
33 #include "msgcommand.h"
34 
35 #include <string>
36 #include <fstream>
37 
38 /************************************************************************/
39 /*                            MSGRasterBand                             */
40 /************************************************************************/
41 
42 class MSGDataset;
43 class ReflectanceCalculator;
44 
45 class MSGRasterBand final: public GDALRasterBand
46 {
47   friend class MSGDataset;
48 
49   public:
50     MSGRasterBand( MSGDataset *, int );
51     virtual ~MSGRasterBand();
52     virtual CPLErr IReadBlock( int, int, void * ) override;
53 
54   private:
55     double rRadiometricCorrection(unsigned int iDN, int iChannel, int iRow, int iCol, MSGDataset* poGDS) const;
56     bool fScanNorth;
57     int iLowerShift; // nr of pixels that lower HRV image is shifted compared to upper
58     int iSplitLine; // line from top where the HRV image splits
59     int iLowerWestColumnPlanned;
60     int iSatellite; // satellite number 1,2,3,4 for MSG1, MSG2, MSG3 and MSG4
61     ReflectanceCalculator* m_rc;
62     static const double rRTOA[12];
63 };
64 
65 /************************************************************************/
66 /*                      MSGDataset                                       */
67 /************************************************************************/
68 class MSGDataset final: public GDALDataset
69 {
70   friend class MSGRasterBand;
71 
72   public:
73     MSGDataset();
74     virtual ~MSGDataset();
75 
76     static GDALDataset *Open( GDALOpenInfo * );
77     virtual const char *_GetProjectionRef() override;
78     virtual CPLErr _SetProjection( const char * ) override;
GetSpatialRef()79     const OGRSpatialReference* GetSpatialRef() const override {
80         return GetSpatialRefFromOldGetProjectionRef();
81     }
SetSpatialRef(const OGRSpatialReference * poSRS)82     CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override {
83         return OldSetProjectionFromSetSpatialRef(poSRS);
84     }
85 
86     virtual CPLErr GetGeoTransform( double * padfTransform ) override;
87 
88   private:
89     MSGCommand command;
90     double adfGeoTransform[6]; // Calculate and store once as GetGeoTransform may be called multiple times
91     char   *pszProjection;
92     OGRSpatialReference oSRS;
93     OGRSpatialReference oLL;
94     OGRCoordinateTransformation *poTransform;
95     double rCalibrationOffset[12];
96     double rCalibrationSlope[12];
97     static int iCurrentSatellite; // satellite number 1,2,3,4 for MSG1, MSG2, MSG3 and MSG4
98     static const double rCentralWvl[12];
99     static const double rVc[12];
100     static const double rA[12];
101     static const double rB[12];
102     static const int iCentralPixelVIS_IR;
103     static const int iCentralPixelHRV;
104     static const char *metadataDomain;
105 };
106