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