1 : /******************************************************************************
2 : * $Id: ogr_bna.h 20996 2010-10-28 18:38:15Z rouault $
3 : *
4 : * Project: BNA Translator
5 : * Purpose: Definition of classes for OGR .bna driver.
6 : * Author: Even Rouault, even dot rouault at mines dash paris dot org
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2007, Even Rouault
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 : #ifndef _OGR_BNA_H_INCLUDED
31 : #define _OGR_BNA_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 :
35 : #include "ogrbnaparser.h"
36 :
37 : class OGRBNADataSource;
38 :
39 : /************************************************************************/
40 : /* OGRBNALayer */
41 : /************************************************************************/
42 :
43 : typedef struct
44 : {
45 : int offset;
46 : int line;
47 : } OffsetAndLine;
48 :
49 : class OGRBNALayer : public OGRLayer
50 : {
51 : OGRFeatureDefn* poFeatureDefn;
52 :
53 : OGRBNADataSource* poDS;
54 : int bWriter;
55 :
56 : int nIDs;
57 : int eof;
58 : int failed;
59 : int curLine;
60 : int nNextFID;
61 : VSILFILE* fpBNA;
62 : int nFeatures;
63 : int partialIndexTable;
64 : OffsetAndLine* offsetAndLineFeaturesTable;
65 :
66 : BNAFeatureType bnaFeatureType;
67 :
68 : OGRFeature * BuildFeatureFromBNARecord (BNARecord* record, long fid);
69 : void FastParseUntil ( int interestFID);
70 : void WriteFeatureAttributes(VSILFILE* fp, OGRFeature *poFeature);
71 : void WriteCoord(VSILFILE* fp, double dfX, double dfY);
72 :
73 : public:
74 : OGRBNALayer(const char *pszFilename,
75 : const char* layerName,
76 : BNAFeatureType bnaFeatureType,
77 : OGRwkbGeometryType eLayerGeomType,
78 : int bWriter,
79 : OGRBNADataSource* poDS,
80 : int nIDs = NB_MAX_BNA_IDS);
81 : ~OGRBNALayer();
82 :
83 : void SetFeatureIndexTable(int nFeatures,
84 : OffsetAndLine* offsetAndLineFeaturesTable,
85 : int partialIndexTable);
86 :
87 : void ResetReading();
88 : OGRFeature * GetNextFeature();
89 :
90 : OGRErr CreateFeature( OGRFeature *poFeature );
91 : OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK );
92 :
93 398 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
94 :
95 : OGRFeature * GetFeature( long nFID );
96 :
97 : int TestCapability( const char * );
98 :
99 : };
100 :
101 : /************************************************************************/
102 : /* OGRBNADataSource */
103 : /************************************************************************/
104 :
105 : class OGRBNADataSource : public OGRDataSource
106 : {
107 : char* pszName;
108 :
109 : OGRBNALayer** papoLayers;
110 : int nLayers;
111 :
112 : int bUpdate;
113 :
114 : /* Export related */
115 : VSILFILE *fpOutput; /* Virtual file API */
116 : int bUseCRLF;
117 : int bMultiLine;
118 : int nbOutID;
119 : int bEllipsesAsEllipses;
120 : int nbPairPerLine;
121 : int coordinatePrecision;
122 : char* pszCoordinateSeparator;
123 :
124 : public:
125 : OGRBNADataSource();
126 : ~OGRBNADataSource();
127 :
128 48 : VSILFILE *GetOutputFP() { return fpOutput; }
129 48 : int GetUseCRLF() { return bUseCRLF; }
130 48 : int GetMultiLine() { return bMultiLine; }
131 48 : int GetNbOutId() { return nbOutID; }
132 12 : int GetEllipsesAsEllipses() { return bEllipsesAsEllipses; }
133 48 : int GetNbPairPerLine() { return nbPairPerLine; }
134 1128 : int GetCoordinatePrecision() { return coordinatePrecision; }
135 596 : const char* GetCoordinateSeparator() { return pszCoordinateSeparator; }
136 :
137 : int Open( const char * pszFilename,
138 : int bUpdate );
139 :
140 : int Create( const char *pszFilename,
141 : char **papszOptions );
142 :
143 22 : const char* GetName() { return pszName; }
144 :
145 202 : int GetLayerCount() { return nLayers; }
146 : OGRLayer* GetLayer( int );
147 :
148 : OGRLayer * CreateLayer( const char * pszLayerName,
149 : OGRSpatialReference *poSRS,
150 : OGRwkbGeometryType eType,
151 : char ** papszOptions );
152 :
153 : int TestCapability( const char * );
154 : };
155 :
156 : /************************************************************************/
157 : /* OGRBNADriver */
158 : /************************************************************************/
159 :
160 : class OGRBNADriver : public OGRSFDriver
161 389 : {
162 : public:
163 : ~OGRBNADriver();
164 :
165 : const char* GetName();
166 : OGRDataSource* Open( const char *, int );
167 : OGRDataSource* CreateDataSource( const char * pszName, char **papszOptions );
168 : int DeleteDataSource( const char *pszFilename );
169 : int TestCapability( const char * );
170 :
171 : };
172 :
173 :
174 : #endif /* ndef _OGR_BNA_H_INCLUDED */
|