1 /****************************************************************************** 2 * $Id$ 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 "pcidsk.h" 38 #include "pcidsk_pct.h" 39 #include "ogrsf_frmts.h" 40 #include "pcidsk_vectorsegment.h" 41 #include "gdal_pam.h" 42 #include "cpl_string.h" 43 #include "ogr_spatialref.h" 44 45 using namespace PCIDSK; 46 47 class OGRPCIDSKLayer; 48 49 /************************************************************************/ 50 /* PCIDSK2Dataset */ 51 /************************************************************************/ 52 53 class PCIDSK2Dataset : public GDALPamDataset 54 { 55 friend class PCIDSK2Band; 56 57 CPLString osSRS; 58 CPLString osLastMDValue; 59 char **papszLastMDListValue; 60 61 PCIDSKFile *poFile; 62 63 std::vector<OGRPCIDSKLayer*> apoLayers; 64 65 static GDALDataType PCIDSKTypeToGDAL( eChanType eType ); 66 void ProcessRPC(); 67 68 public: 69 PCIDSK2Dataset(); 70 ~PCIDSK2Dataset(); 71 72 static int Identify( GDALOpenInfo * ); 73 static GDALDataset *Open( GDALOpenInfo * ); 74 static GDALDataset *LLOpen( const char *pszFilename, PCIDSK::PCIDSKFile *, 75 GDALAccess eAccess, 76 char** papszSiblingFiles = NULL ); 77 static GDALDataset *Create( const char * pszFilename, 78 int nXSize, int nYSize, int nBands, 79 GDALDataType eType, 80 char **papszParmList ); 81 82 char **GetFileList(void); 83 CPLErr GetGeoTransform( double * padfTransform ); 84 CPLErr SetGeoTransform( double * ); 85 const char *GetProjectionRef(); 86 CPLErr SetProjection( const char * ); 87 88 virtual char **GetMetadataDomainList(); 89 CPLErr SetMetadata( char **, const char * ); 90 char **GetMetadata( const char* ); 91 CPLErr SetMetadataItem(const char*,const char*,const char*); 92 const char *GetMetadataItem( const char*, const char*); 93 94 virtual void FlushCache(void); 95 96 virtual CPLErr IBuildOverviews( const char *, int, int *, 97 int, int *, GDALProgressFunc, void * ); 98 GetLayerCount()99 virtual int GetLayerCount() { return (int) apoLayers.size(); } 100 virtual OGRLayer *GetLayer( int ); 101 102 virtual int TestCapability( const char * ); 103 104 virtual OGRLayer *ICreateLayer( const char *, OGRSpatialReference *, 105 OGRwkbGeometryType, char ** ); 106 }; 107 108 /************************************************************************/ 109 /* PCIDSK2Band */ 110 /************************************************************************/ 111 112 class PCIDSK2Band : public GDALPamRasterBand 113 { 114 friend class PCIDSK2Dataset; 115 116 PCIDSKChannel *poChannel; 117 PCIDSKFile *poFile; 118 119 void RefreshOverviewList(); 120 std::vector<PCIDSK2Band*> apoOverviews; 121 122 CPLString osLastMDValue; 123 char **papszLastMDListValue; 124 125 bool CheckForColorTable(); 126 GDALColorTable *poColorTable; 127 bool bCheckedForColorTable; 128 int nPCTSegNumber; 129 130 char **papszCategoryNames; 131 132 void Initialize(); 133 134 public: 135 PCIDSK2Band( PCIDSK2Dataset *, PCIDSKFile *, int ); 136 PCIDSK2Band( PCIDSKChannel * ); 137 ~PCIDSK2Band(); 138 139 virtual CPLErr IReadBlock( int, int, void * ); 140 virtual CPLErr IWriteBlock( int, int, void * ); 141 142 virtual int GetOverviewCount(); 143 virtual GDALRasterBand *GetOverview(int); 144 145 virtual GDALColorInterp GetColorInterpretation(); 146 virtual GDALColorTable *GetColorTable(); 147 virtual CPLErr SetColorTable( GDALColorTable * ); 148 149 virtual void SetDescription( const char * ); 150 151 virtual char **GetMetadataDomainList(); 152 CPLErr SetMetadata( char **, const char * ); 153 char **GetMetadata( const char* ); 154 CPLErr SetMetadataItem(const char*,const char*,const char*); 155 const char *GetMetadataItem( const char*, const char*); 156 157 virtual char **GetCategoryNames(); 158 }; 159 160 /************************************************************************/ 161 /* OGRPCIDSKLayer */ 162 /************************************************************************/ 163 164 class OGRPCIDSKLayer : public OGRLayer 165 { 166 PCIDSK::PCIDSKVectorSegment *poVecSeg; 167 PCIDSK::PCIDSKSegment *poSeg; 168 169 OGRFeatureDefn *poFeatureDefn; 170 171 OGRFeature * GetNextUnfilteredFeature(); 172 173 int iRingStartField; 174 PCIDSK::ShapeId hLastShapeId; 175 176 bool bUpdateAccess; 177 178 OGRSpatialReference *poSRS; 179 180 public: 181 OGRPCIDSKLayer( PCIDSK::PCIDSKSegment*, bool bUpdate ); 182 ~OGRPCIDSKLayer(); 183 184 void ResetReading(); 185 OGRFeature * GetNextFeature(); 186 OGRFeature *GetFeature( GIntBig nFeatureId ); 187 virtual OGRErr ISetFeature( OGRFeature *poFeature ); 188 GetLayerDefn()189 OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; } 190 191 int TestCapability( const char * ); 192 193 OGRErr DeleteFeature( GIntBig nFID ); 194 virtual OGRErr ICreateFeature( OGRFeature *poFeature ); 195 virtual OGRErr CreateField( OGRFieldDefn *poField, 196 int bApproxOK = TRUE ); 197 198 GIntBig GetFeatureCount( int ); 199 OGRErr GetExtent( OGREnvelope *psExtent, int bForce ); 200 }; 201 202 #endif /* PCIDSKDATASET2_H_INCLUDED */ 203