1 : /******************************************************************************
2 : * $Id: ogr_bna.h 10646 2007-01-18 02:38:10Z warmerdam $
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 : FILE* 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(FILE* fp, OGRFeature *poFeature);
71 :
72 : public:
73 : OGRBNALayer(const char *pszFilename,
74 : const char* layerName,
75 : BNAFeatureType bnaFeatureType,
76 : OGRwkbGeometryType eLayerGeomType,
77 : int bWriter,
78 : OGRBNADataSource* poDS,
79 : int nIDs = NB_MAX_BNA_IDS);
80 : ~OGRBNALayer();
81 :
82 : void SetFeatureIndexTable(int nFeatures,
83 : OffsetAndLine* offsetAndLineFeaturesTable,
84 : int partialIndexTable);
85 :
86 : void ResetReading();
87 : OGRFeature * GetNextFeature();
88 :
89 : OGRErr CreateFeature( OGRFeature *poFeature );
90 : OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK );
91 :
92 199 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
93 :
94 : OGRFeature * GetFeature( long nFID );
95 :
96 : int TestCapability( const char * );
97 :
98 : };
99 :
100 : /************************************************************************/
101 : /* OGRBNADataSource */
102 : /************************************************************************/
103 :
104 : class OGRBNADataSource : public OGRDataSource
105 : {
106 : char* pszName;
107 :
108 : OGRBNALayer** papoLayers;
109 : int nLayers;
110 :
111 : int bUpdate;
112 :
113 : /* Export related */
114 : FILE *fpOutput;
115 : int bUseCRLF;
116 : int bMultiLine;
117 : int nbOutID;
118 : int bEllipsesAsEllipses;
119 : int nbPairPerLine;
120 : int coordinatePrecision;
121 : char* pszCoordinateSeparator;
122 :
123 : public:
124 : OGRBNADataSource();
125 : ~OGRBNADataSource();
126 :
127 24 : FILE *GetOutputFP() { return fpOutput; }
128 24 : int GetUseCRLF() { return bUseCRLF; }
129 24 : int GetMultiLine() { return bMultiLine; }
130 24 : int GetNbOutId() { return nbOutID; }
131 6 : int GetEllipsesAsEllipses() { return bEllipsesAsEllipses; }
132 24 : int GetNbPairPerLine() { return nbPairPerLine; }
133 48 : int GetCoordinatePrecision() { return coordinatePrecision; }
134 40 : const char* GetCoordinateSeparator() { return pszCoordinateSeparator; }
135 :
136 : int Open( const char * pszFilename,
137 : int bUpdate );
138 :
139 : int Create( const char *pszFilename,
140 : char **papszOptions );
141 :
142 11 : const char* GetName() { return pszName; }
143 :
144 101 : int GetLayerCount() { return nLayers; }
145 : OGRLayer* GetLayer( int );
146 :
147 : OGRLayer * CreateLayer( const char * pszLayerName,
148 : OGRSpatialReference *poSRS,
149 : OGRwkbGeometryType eType,
150 : char ** papszOptions );
151 :
152 : int TestCapability( const char * );
153 : };
154 :
155 : /************************************************************************/
156 : /* OGRBNADriver */
157 : /************************************************************************/
158 :
159 : class OGRBNADriver : public OGRSFDriver
160 64 : {
161 : public:
162 : ~OGRBNADriver();
163 :
164 : const char* GetName();
165 : OGRDataSource* Open( const char *, int );
166 : OGRDataSource* CreateDataSource( const char * pszName, char **papszOptions );
167 : int DeleteDataSource( const char *pszFilename );
168 : int TestCapability( const char * );
169 :
170 : };
171 :
172 :
173 : #endif /* ndef _OGR_BNA_H_INCLUDED */
|