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