1 /******************************************************************************
2  * $Id: rasterlitedataset.h 27566 2014-08-05 09:37:57Z rouault $
3  *
4  * Project:  GDAL Rasterlite driver
5  * Purpose:  Implement GDAL Rasterlite support using OGR SQLite driver
6  * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
7  *
8  **********************************************************************
9  * Copyright (c) 2009-2013, Even Rouault <even dot rouault at mines-paris dot org>
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 #ifndef RASTERLITE_DATASET_INCLUDED
31 #define RASTERLITE_DATASET_INCLUDED
32 
33 #include "gdal_pam.h"
34 #include "ogr_api.h"
35 
36 char** RasterliteGetTileDriverOptions(char** papszOptions);
37 
38 OGRDataSourceH RasterliteOpenSQLiteDB(const char* pszFilename,
39                                       GDALAccess eAccess);
40 CPLString RasterliteGetPixelSizeCond(double dfPixelXSize,
41                                      double dfPixelYSize,
42                                      const char* pszTablePrefixWithDot = "");
43 CPLString RasterliteGetSpatialFilterCond(double minx, double miny,
44                                          double maxx, double maxy);
45 
46 class RasterliteBand;
47 
48 /************************************************************************/
49 /* ==================================================================== */
50 /*                              RasterliteDataset                       */
51 /* ==================================================================== */
52 /************************************************************************/
53 
54 class RasterliteDataset : public GDALPamDataset
55 {
56     friend class RasterliteBand;
57 
58   public:
59                  RasterliteDataset();
60                  RasterliteDataset(RasterliteDataset* poMainDS, int nLevel);
61 
62     virtual     ~RasterliteDataset();
63 
64     virtual char      **GetMetadataDomainList();
65     virtual char **GetMetadata( const char *pszDomain );
66     virtual const char *GetMetadataItem( const char *pszName,
67                                          const char *pszDomain );
68     virtual CPLErr GetGeoTransform( double* padfGeoTransform );
69     virtual const char* GetProjectionRef();
70 
71     virtual char** GetFileList();
72 
73     virtual CPLErr IBuildOverviews( const char * pszResampling,
74                                     int nOverviews, int * panOverviewList,
75                                     int nBands, int * panBandList,
76                                     GDALProgressFunc pfnProgress, void * pProgressData );
77 
78     static GDALDataset *Open( GDALOpenInfo * );
79     static int          Identify( GDALOpenInfo * );
80 
81   protected:
82     virtual int         CloseDependentDatasets();
83 
84   private:
85 
86     int bMustFree;
87     RasterliteDataset* poMainDS;
88     int nLevel;
89 
90     char** papszMetadata;
91     char** papszImageStructure;
92     char** papszSubDatasets;
93 
94     int nResolutions;
95     double* padfXResolutions, *padfYResolutions;
96     RasterliteDataset** papoOverviews;
97     int nLimitOvrCount;
98 
99     int bValidGeoTransform;
100     double adfGeoTransform[6];
101     char* pszSRS;
102 
103     GDALColorTable* poCT;
104 
105     CPLString osTableName;
106     CPLString osFileName;
107 
108     int bCheckForExistingOverview;
109     CPLString osOvrFileName;
110 
111     OGRDataSourceH hDS;
112 
113     void AddSubDataset( const char* pszDSName);
114     int  GetBlockParams(OGRLayerH hRasterLyr, int nLevel, int* pnBands,
115                         GDALDataType* peDataType,
116                         int* pnBlockXSize, int* pnBlockYSize);
117     CPLErr CleanOverviews();
118     CPLErr CleanOverviewLevel(int nOvrFactor);
119     CPLErr ReloadOverviews();
120     CPLErr CreateOverviewLevel(const char * pszResampling,
121                                int nOvrFactor,
122                                char** papszOptions,
123                                GDALProgressFunc pfnProgress,
124                                void * pProgressData);
125 };
126 
127 /************************************************************************/
128 /* ==================================================================== */
129 /*                              RasterliteBand                          */
130 /* ==================================================================== */
131 /************************************************************************/
132 
133 class RasterliteBand: public GDALPamRasterBand
134 {
135     friend class RasterliteDataset;
136 
137   public:
138                             RasterliteBand( RasterliteDataset* poDS, int nBand,
139                                             GDALDataType eDataType,
140                                             int nBlockXSize, int nBlockYSize);
141 
142     virtual GDALColorInterp GetColorInterpretation();
143     virtual GDALColorTable* GetColorTable();
144 
145     virtual int             GetOverviewCount();
146     virtual GDALRasterBand* GetOverview(int nLevel);
147 
148     virtual CPLErr          IReadBlock( int, int, void * );
149 };
150 
151 GDALDataset *
152 RasterliteCreateCopy( const char * pszFilename, GDALDataset *poSrcDS,
153                        int bStrict, char ** papszOptions,
154                        GDALProgressFunc pfnProgress, void * pProgressData );
155 
156 CPLErr RasterliteDelete(const char* pszFilename);
157 
158 #endif // RASTERLITE_DATASET_INCLUDED
159