My Project
 All Classes
pcidskdataset2.h
1 /******************************************************************************
2  * $Id: pcidskdataset2.h 8e5eeb35bf76390e3134a4ea7076dab7d478ea0e 2018-11-14 22:55:13 +0100 Even Rouault $
3  *
4  * Project: PCIDSK Database File
5  * Purpose: Read/write PCIDSK Database File used by the PCI software, using
6  * the external PCIDSK library.
7  * Author: Frank Warmerdam, warmerdam@pobox.com
8  *
9  ******************************************************************************
10  * Copyright (c) 2009, Frank Warmerdam <warmerdam@pobox.com>
11  * Copyright (c) 2009-2013, Even Rouault <even dot rouault at mines-paris dot org>
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 PCIDSKDATASET2_H_INCLUDED
33 #define PCIDSKDATASET2_H_INCLUDED
34 
35 #define GDAL_PCIDSK_DRIVER
36 
37 #include "cpl_string.h"
38 #include "gdal_pam.h"
39 #include "ogrsf_frmts.h"
40 #include "ogr_spatialref.h"
41 #include "pcidsk.h"
42 #include "pcidsk_pct.h"
43 #include "pcidsk_vectorsegment.h"
44 
45 #include <unordered_map>
46 
47 using namespace PCIDSK;
48 
49 class OGRPCIDSKLayer;
50 
51 /************************************************************************/
52 /* PCIDSK2Dataset */
53 /************************************************************************/
54 
55 class PCIDSK2Dataset final: public GDALPamDataset
56 {
57  friend class PCIDSK2Band;
58 
59  mutable OGRSpatialReference* m_poSRS = nullptr;
60  CPLString osLastMDValue;
61  char **papszLastMDListValue;
62 
63  PCIDSK::PCIDSKFile *poFile;
64 
65  std::vector<OGRPCIDSKLayer*> apoLayers;
66 
67  static GDALDataType PCIDSKTypeToGDAL( PCIDSK::eChanType eType );
68  void ProcessRPC();
69 
70  public:
72  virtual ~PCIDSK2Dataset();
73 
74  static int Identify( GDALOpenInfo * );
75  static GDALDataset *Open( GDALOpenInfo * );
76  static GDALDataset *LLOpen( const char *pszFilename, PCIDSK::PCIDSKFile *,
77  GDALAccess eAccess,
78  char** papszSiblingFiles = nullptr );
79  static GDALDataset *Create( const char * pszFilename,
80  int nXSize, int nYSize, int nBands,
81  GDALDataType eType,
82  char **papszParmList );
83 
84  char **GetFileList() override;
85  CPLErr GetGeoTransform( double * padfTransform ) override;
86  CPLErr SetGeoTransform( double * ) override;
87 
88  const OGRSpatialReference* GetSpatialRef() const override;
89  CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
90 
91  virtual char **GetMetadataDomainList() override;
92  CPLErr SetMetadata( char **, const char * ) override;
93  char **GetMetadata( const char* ) override;
94  CPLErr SetMetadataItem(const char*,const char*,const char*) override;
95  const char *GetMetadataItem( const char*, const char*) override;
96 
97  virtual void FlushCache() override;
98 
99  virtual CPLErr IBuildOverviews( const char *, int, int *,
100  int, int *, GDALProgressFunc, void * ) override;
101 
102  virtual int GetLayerCount() override { return (int) apoLayers.size(); }
103  virtual OGRLayer *GetLayer( int ) override;
104 
105  virtual int TestCapability( const char * ) override;
106 
107  virtual OGRLayer *ICreateLayer( const char *, OGRSpatialReference *,
108  OGRwkbGeometryType, char ** ) override;
109 };
110 
111 /************************************************************************/
112 /* PCIDSK2Band */
113 /************************************************************************/
114 
115 class PCIDSK2Band final: public GDALPamRasterBand
116 {
117  friend class PCIDSK2Dataset;
118 
119  PCIDSK::PCIDSKChannel *poChannel;
120  PCIDSK::PCIDSKFile *poFile;
121 
122  void RefreshOverviewList();
123  std::vector<PCIDSK2Band*> apoOverviews;
124 
125  CPLString osLastMDValue;
126  char **papszLastMDListValue;
127 
128  bool CheckForColorTable();
129  GDALColorTable *poColorTable;
130  bool bCheckedForColorTable;
131  int nPCTSegNumber;
132 
133  char **papszCategoryNames;
134 
135  void Initialize();
136 
137  public:
138  PCIDSK2Band( PCIDSK::PCIDSKFile *poFileIn,
139  PCIDSK::PCIDSKChannel *poChannelIn );
140  explicit PCIDSK2Band( PCIDSK::PCIDSKChannel * );
141  virtual ~PCIDSK2Band();
142 
143  virtual CPLErr IReadBlock( int, int, void * ) override;
144  virtual CPLErr IWriteBlock( int, int, void * ) override;
145 
146  virtual int GetOverviewCount() override;
147  virtual GDALRasterBand *GetOverview(int) override;
148 
149  virtual GDALColorInterp GetColorInterpretation() override;
150  virtual GDALColorTable *GetColorTable() override;
151  virtual CPLErr SetColorTable( GDALColorTable * ) override;
152 
153  virtual void SetDescription( const char * ) override;
154 
155  virtual char **GetMetadataDomainList() override;
156  CPLErr SetMetadata( char **, const char * ) override;
157  char **GetMetadata( const char* ) override;
158  CPLErr SetMetadataItem(const char*,const char*,const char*) override;
159  const char *GetMetadataItem( const char*, const char*) override;
160 
161  virtual char **GetCategoryNames() override;
162 };
163 
164 /************************************************************************/
165 /* OGRPCIDSKLayer */
166 /************************************************************************/
167 
168 class OGRPCIDSKLayer final: public OGRLayer
169 {
170  PCIDSK::PCIDSKVectorSegment *poVecSeg;
171  PCIDSK::PCIDSKSegment *poSeg;
172 
173  OGRFeatureDefn *poFeatureDefn;
174 
175  OGRFeature * GetNextUnfilteredFeature();
176 
177  int iRingStartField;
178  PCIDSK::ShapeId hLastShapeId;
179 
180  bool bUpdateAccess;
181 
182  OGRSpatialReference *poSRS;
183 
184  std::unordered_map<std::string, int> m_oMapFieldNameToIdx{};
185 
186  public:
187  OGRPCIDSKLayer( PCIDSK::PCIDSKSegment*, PCIDSK::PCIDSKVectorSegment *, bool bUpdate );
188  virtual ~OGRPCIDSKLayer();
189 
190  void ResetReading() override;
191  OGRFeature * GetNextFeature() override;
192  OGRFeature *GetFeature( GIntBig nFeatureId ) override;
193  virtual OGRErr ISetFeature( OGRFeature *poFeature ) override;
194 
195  OGRFeatureDefn * GetLayerDefn() override { return poFeatureDefn; }
196 
197  int TestCapability( const char * ) override;
198 
199  OGRErr DeleteFeature( GIntBig nFID ) override;
200  virtual OGRErr ICreateFeature( OGRFeature *poFeature ) override;
201  virtual OGRErr CreateField( OGRFieldDefn *poField,
202  int bApproxOK = TRUE ) override;
203 
204  GIntBig GetFeatureCount( int ) override;
205  OGRErr GetExtent( OGREnvelope *psExtent, int bForce ) override;
206  virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce) override
207  { return OGRLayer::GetExtent(iGeomField, psExtent, bForce); }
208 };
209 
210 #endif /* PCIDSKDATASET2_H_INCLUDED */
Definition: pcidskdataset2.h:168
Definition: pcidskdataset2.h:115
Definition: pcidskdataset2.h:55