Line data Source code
1 : /******************************************************************************
2 : *
3 : * Project: OGR
4 : * Purpose: Implements OGRAVCE00DataSource class.
5 : * Author: Frank Warmerdam, warmerdam@pobox.com
6 : * James Flemer <jflemer@alum.rpi.edu>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2002, Frank Warmerdam <warmerdam@pobox.com>
10 : * Copyright (c) 2006, James Flemer <jflemer@alum.rpi.edu>
11 : *
12 : * Permission is hereby granted, free of charge, to any person obtaining a
13 : * copy of this software and associated documentation files (the "Software"),
14 : * to deal in the Software without restriction, including without limitation
15 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 : * and/or sell copies of the Software, and to permit persons to whom the
17 : * Software is furnished to do so, subject to the following conditions:
18 : *
19 : * The above copyright notice and this permission notice shall be included
20 : * in all copies or substantial portions of the Software.
21 : *
22 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 : * DEALINGS IN THE SOFTWARE.
29 : ****************************************************************************/
30 :
31 : #include "ogr_avc.h"
32 : #include "cpl_conv.h"
33 : #include "cpl_string.h"
34 :
35 : /************************************************************************/
36 : /* OGRAVCE00DataSource() */
37 : /************************************************************************/
38 :
39 4 : OGRAVCE00DataSource::OGRAVCE00DataSource()
40 4 : : nLayers(0), pszName(nullptr), psE00(nullptr), papoLayers(nullptr)
41 : {
42 4 : }
43 :
44 : /************************************************************************/
45 : /* ~OGRAVCE00DataSource() */
46 : /************************************************************************/
47 :
48 8 : OGRAVCE00DataSource::~OGRAVCE00DataSource()
49 :
50 : {
51 4 : if (psE00)
52 : {
53 3 : AVCE00ReadCloseE00(psE00);
54 3 : psE00 = nullptr;
55 : }
56 :
57 4 : CPLFree(pszName);
58 :
59 11 : for (int i = 0; i < nLayers; i++)
60 7 : delete papoLayers[i];
61 :
62 4 : CPLFree(papoLayers);
63 8 : }
64 :
65 : /************************************************************************/
66 : /* Open() */
67 : /************************************************************************/
68 :
69 4 : int OGRAVCE00DataSource::Open(const char *pszNewName, int bTestOpen)
70 :
71 : {
72 : /* -------------------------------------------------------------------- */
73 : /* Open the source file. Suppress error reporting if we are in */
74 : /* TestOpen mode. */
75 : /* -------------------------------------------------------------------- */
76 4 : bool bCompressed = false;
77 :
78 4 : if (bTestOpen)
79 4 : CPLPushErrorHandler(CPLQuietErrorHandler);
80 :
81 4 : psE00 = AVCE00ReadOpenE00(pszNewName);
82 :
83 5 : if (CPLGetLastErrorNo() == CPLE_OpenFailed &&
84 1 : strstr(CPLGetLastErrorMsg(), "compressed E00") != nullptr)
85 : {
86 1 : bCompressed = true;
87 : }
88 :
89 4 : if (bTestOpen)
90 : {
91 4 : CPLPopErrorHandler();
92 4 : CPLErrorReset();
93 : }
94 :
95 4 : if (psE00 == nullptr)
96 : {
97 1 : if (bCompressed)
98 : {
99 1 : CPLError(CE_Failure, CPLE_OpenFailed,
100 : "This looks like a compressed E00 file and cannot be "
101 : "processed directly. You may need to uncompress it "
102 : "first using the E00compr library or the e00conv "
103 : "program.");
104 : }
105 1 : return FALSE;
106 : }
107 :
108 3 : pszName = CPLStrdup(pszNewName);
109 : /* pszCoverageName = CPLStrdup( psE00->pszCoverName ); */
110 3 : pszCoverageName = CPLStrdup(pszNewName);
111 :
112 : /* -------------------------------------------------------------------- */
113 : /* Create layers for the "interesting" sections of the coverage. */
114 : /* -------------------------------------------------------------------- */
115 3 : papoLayers = static_cast<OGRAVCE00Layer **>(
116 3 : CPLCalloc(sizeof(OGRAVCE00Layer *), psE00->numSections));
117 3 : nLayers = 0;
118 :
119 24 : for (int iSection = 0; iSection < psE00->numSections; iSection++)
120 : {
121 21 : AVCE00Section *psSec = psE00->pasSections + iSection;
122 :
123 21 : switch (psSec->eType)
124 : {
125 7 : case AVCFileARC:
126 : case AVCFilePAL:
127 : case AVCFileCNT:
128 : case AVCFileLAB:
129 : case AVCFileRPL:
130 : case AVCFileTXT:
131 7 : papoLayers[nLayers++] = new OGRAVCE00Layer(this, psSec);
132 7 : break;
133 :
134 0 : case AVCFileTX6:
135 0 : break;
136 :
137 12 : case AVCFileTABLE:
138 12 : CheckAddTable(psSec);
139 12 : break;
140 :
141 2 : case AVCFilePRJ:
142 : {
143 : #if 0
144 : poSRS = new OGRSpatialReference();
145 : poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
146 : AVCE00File *hFile
147 : = AVCE00ReadOpen( psE00->pszCoverPath,
148 : psSec->pszFilename,
149 : psE00->eCoverType,
150 : psSec->eType,
151 : psE00->psDBCSInfo);
152 : if( hFile && poSRS == NULL )
153 : {
154 : char **papszPRJ = AVCE00ReadNextPrj( hFile );
155 :
156 : poSRS = new OGRSpatialReference();
157 : poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
158 : if( poSRS->importFromESRI( papszPRJ ) != OGRERR_NONE )
159 : {
160 : CPLError( CE_Warning, CPLE_AppDefined,
161 : "Failed to parse PRJ section, ignoring." );
162 : delete poSRS;
163 : poSRS = NULL;
164 : }
165 : AVCE00ReadClose( hFile );
166 : }
167 : #endif
168 : }
169 2 : break;
170 :
171 21 : default:;
172 : }
173 : }
174 :
175 3 : return nLayers > 0;
176 : }
177 :
178 12 : int OGRAVCE00DataSource::CheckAddTable(AVCE00Section *psTblSection)
179 : {
180 12 : int nCount = 0;
181 43 : for (int i = 0; i < nLayers; ++i)
182 : {
183 31 : if (papoLayers[i]->CheckSetupTable(psTblSection))
184 3 : ++nCount;
185 : }
186 12 : return nCount;
187 : }
188 :
189 : /************************************************************************/
190 : /* TestCapability() */
191 : /************************************************************************/
192 :
193 0 : int OGRAVCE00DataSource::TestCapability(const char * /* pszCap */)
194 : {
195 0 : return FALSE;
196 : }
197 :
198 : /************************************************************************/
199 : /* GetLayer() */
200 : /************************************************************************/
201 :
202 11 : OGRLayer *OGRAVCE00DataSource::GetLayer(int iLayer)
203 :
204 : {
205 11 : if (iLayer < 0 || iLayer >= nLayers)
206 0 : return nullptr;
207 :
208 11 : return papoLayers[iLayer];
209 : }
210 :
211 : /************************************************************************/
212 : /* GetSpatialRef() */
213 : /************************************************************************/
214 7 : OGRSpatialReference *OGRAVCE00DataSource::DSGetSpatialRef()
215 : {
216 7 : if (m_bSRSFetched)
217 4 : return poSRS;
218 3 : m_bSRSFetched = true;
219 3 : if (psE00 == nullptr)
220 0 : return nullptr;
221 :
222 13 : for (int iSection = 0; iSection < psE00->numSections; iSection++)
223 : {
224 12 : AVCE00Section *psSec = psE00->pasSections + iSection;
225 12 : if (psSec->eType == AVCFilePRJ)
226 : {
227 2 : AVCE00ReadGotoSectionE00(psE00, psSec, 0);
228 2 : void *obj = AVCE00ReadNextObjectE00(psE00);
229 2 : if (psE00->hParseInfo->eFileType == AVCFilePRJ)
230 : {
231 2 : char **pszPRJ = static_cast<char **>(obj);
232 2 : if (pszPRJ)
233 : {
234 2 : poSRS = new OGRSpatialReference();
235 2 : poSRS->SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);
236 2 : if (poSRS->importFromESRI(pszPRJ) != OGRERR_NONE)
237 : {
238 0 : CPLError(CE_Warning, CPLE_AppDefined,
239 : "Failed to parse PRJ section, ignoring.");
240 0 : delete poSRS;
241 0 : poSRS = nullptr;
242 : }
243 : }
244 : }
245 2 : break;
246 : }
247 : }
248 :
249 3 : return poSRS;
250 : }
|