Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OGR 4 : * Purpose: Implements OGRAVCBinDataSource class. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com> 9 : * 10 : * Permission is hereby granted, free of charge, to any person obtaining a 11 : * copy of this software and associated documentation files (the "Software"), 12 : * to deal in the Software without restriction, including without limitation 13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 : * and/or sell copies of the Software, and to permit persons to whom the 15 : * Software is furnished to do so, subject to the following conditions: 16 : * 17 : * The above copyright notice and this permission notice shall be included 18 : * in all copies or substantial portions of the Software. 19 : * 20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 : * DEALINGS IN THE SOFTWARE. 27 : ****************************************************************************/ 28 : 29 : #include "ogr_avc.h" 30 : #include "cpl_conv.h" 31 : #include "cpl_string.h" 32 : 33 : /************************************************************************/ 34 : /* OGRAVCBinDataSource() */ 35 : /************************************************************************/ 36 : 37 415 : OGRAVCBinDataSource::OGRAVCBinDataSource() 38 415 : : papoLayers(nullptr), nLayers(0), pszName(nullptr), psAVC(nullptr) 39 : { 40 415 : poSRS = nullptr; 41 415 : } 42 : 43 : /************************************************************************/ 44 : /* ~OGRAVCBinDataSource() */ 45 : /************************************************************************/ 46 : 47 830 : OGRAVCBinDataSource::~OGRAVCBinDataSource() 48 : 49 : { 50 415 : if (psAVC) 51 : { 52 3 : AVCE00ReadClose(psAVC); 53 3 : psAVC = nullptr; 54 : } 55 : 56 415 : CPLFree(pszName); 57 : 58 422 : for (int i = 0; i < nLayers; i++) 59 7 : delete papoLayers[i]; 60 : 61 415 : CPLFree(papoLayers); 62 830 : } 63 : 64 : /************************************************************************/ 65 : /* Open() */ 66 : /************************************************************************/ 67 : 68 415 : int OGRAVCBinDataSource::Open(const char *pszNewName, int bTestOpen) 69 : 70 : { 71 : /* -------------------------------------------------------------------- */ 72 : /* Open the source file. Suppress error reporting if we are in */ 73 : /* TestOpen mode. */ 74 : /* -------------------------------------------------------------------- */ 75 415 : if (bTestOpen) 76 415 : CPLPushErrorHandler(CPLQuietErrorHandler); 77 : 78 415 : psAVC = AVCE00ReadOpen(pszNewName); 79 : 80 415 : if (bTestOpen) 81 : { 82 415 : CPLPopErrorHandler(); 83 415 : CPLErrorReset(); 84 : } 85 : 86 415 : if (psAVC == nullptr) 87 412 : return FALSE; 88 : 89 3 : pszName = CPLStrdup(pszNewName); 90 3 : pszCoverageName = CPLStrdup(psAVC->pszCoverName); 91 : 92 : // Read SRS first 93 41 : for (int iSection = 0; iSection < psAVC->numSections; iSection++) 94 : { 95 38 : AVCE00Section *psSec = psAVC->pasSections + iSection; 96 : 97 38 : switch (psSec->eType) 98 : { 99 2 : case AVCFilePRJ: 100 : { 101 4 : AVCBinFile *hFile = AVCBinReadOpen( 102 2 : psAVC->pszCoverPath, psSec->pszFilename, psAVC->eCoverType, 103 2 : psSec->eType, psAVC->psDBCSInfo); 104 2 : if (hFile && poSRS == nullptr) 105 : { 106 2 : char **papszPRJ = AVCBinReadNextPrj(hFile); 107 : 108 2 : poSRS = new OGRSpatialReference(); 109 2 : poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER); 110 2 : if (poSRS->importFromESRI(papszPRJ) != OGRERR_NONE) 111 : { 112 0 : CPLError(CE_Warning, CPLE_AppDefined, 113 : "Failed to parse PRJ section, ignoring."); 114 0 : delete poSRS; 115 0 : poSRS = nullptr; 116 : } 117 : } 118 2 : if (hFile) 119 : { 120 2 : AVCBinReadClose(hFile); 121 : } 122 : } 123 2 : break; 124 : 125 36 : default: 126 36 : break; 127 : } 128 : } 129 : 130 : /* -------------------------------------------------------------------- */ 131 : /* Create layers for the "interesting" sections of the coverage. */ 132 : /* -------------------------------------------------------------------- */ 133 : 134 3 : papoLayers = static_cast<OGRLayer **>( 135 3 : CPLCalloc(sizeof(OGRLayer *), psAVC->numSections)); 136 3 : nLayers = 0; 137 : 138 41 : for (int iSection = 0; iSection < psAVC->numSections; iSection++) 139 : { 140 38 : AVCE00Section *psSec = psAVC->pasSections + iSection; 141 : 142 38 : switch (psSec->eType) 143 : { 144 7 : case AVCFileARC: 145 : case AVCFilePAL: 146 : case AVCFileCNT: 147 : case AVCFileLAB: 148 : case AVCFileRPL: 149 : case AVCFileTXT: 150 : case AVCFileTX6: 151 7 : papoLayers[nLayers++] = new OGRAVCBinLayer(this, psSec); 152 7 : break; 153 : 154 31 : default: 155 31 : break; 156 : } 157 : } 158 : 159 3 : return nLayers > 0; 160 : } 161 : 162 : /************************************************************************/ 163 : /* TestCapability() */ 164 : /************************************************************************/ 165 : 166 0 : int OGRAVCBinDataSource::TestCapability(CPL_UNUSED const char *pszCap) 167 : { 168 0 : return FALSE; 169 : } 170 : 171 : /************************************************************************/ 172 : /* GetLayer() */ 173 : /************************************************************************/ 174 : 175 11 : OGRLayer *OGRAVCBinDataSource::GetLayer(int iLayer) 176 : 177 : { 178 11 : if (iLayer < 0 || iLayer >= nLayers) 179 0 : return nullptr; 180 : 181 11 : return papoLayers[iLayer]; 182 : }