1 : /******************************************************************************
2 : * $Id: ogr_csv.h 25040 2012-10-03 21:32:49Z rcoup $
3 : *
4 : * Project: CSV Translator
5 : * Purpose: Definition of classes for OGR .csv driver.
6 : * Author: Frank Warmerdam, warmerdam@pobox.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2004, Frank Warmerdam
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_CSV_H_INCLUDED
31 : #define _OGR_CSV_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 :
35 : typedef enum
36 : {
37 : OGR_CSV_GEOM_NONE,
38 : OGR_CSV_GEOM_AS_WKT,
39 : OGR_CSV_GEOM_AS_XYZ,
40 : OGR_CSV_GEOM_AS_XY,
41 : OGR_CSV_GEOM_AS_YX,
42 : } OGRCSVGeometryFormat;
43 :
44 : class OGRCSVDataSource;
45 :
46 : char **OGRCSVReadParseLineL( VSILFILE * fp, char chDelimiter, int bDontHonourStrings );
47 :
48 : /************************************************************************/
49 : /* OGRCSVLayer */
50 : /************************************************************************/
51 :
52 : class OGRCSVLayer : public OGRLayer
53 : {
54 : OGRFeatureDefn *poFeatureDefn;
55 :
56 : VSILFILE *fpCSV;
57 :
58 : int nNextFID;
59 :
60 : int bHasFieldNames;
61 :
62 : OGRFeature * GetNextUnfilteredFeature();
63 :
64 : int bNew;
65 : int bInWriteMode;
66 : int bUseCRLF;
67 : int bNeedRewindBeforeRead;
68 : OGRCSVGeometryFormat eGeometryFormat;
69 :
70 : char* pszFilename;
71 : int bCreateCSVT;
72 : int bWriteBOM;
73 : char chDelimiter;
74 :
75 : int iWktGeomReadField;
76 : int bFirstFeatureAppendedDuringSession;
77 :
78 : /*http://www.faa.gov/airports/airport_safety/airportdata_5010/menu/index.cfm specific */
79 : int iNfdcLatitudeS, iNfdcLongitudeS;
80 : int bDontHonourStrings;
81 :
82 : /* GNIS specific */
83 : int iLongitudeField, iLatitudeField;
84 :
85 : int nTotalFeatures;
86 :
87 : public:
88 : OGRCSVLayer( const char *pszName, VSILFILE *fp, const char *pszFilename,
89 : int bNew, int bInWriteMode, char chDelimiter,
90 : const char* pszNfdcRunwaysGeomField,
91 : const char* pszGeonamesGeomFieldPrefix );
92 : ~OGRCSVLayer();
93 :
94 : void ResetReading();
95 : OGRFeature * GetNextFeature();
96 :
97 31953 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
98 :
99 : int TestCapability( const char * );
100 :
101 : virtual OGRErr CreateField( OGRFieldDefn *poField,
102 : int bApproxOK = TRUE );
103 :
104 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
105 :
106 : void SetCRLF(int);
107 : void SetWriteGeometry(OGRCSVGeometryFormat eGeometryFormat);
108 : void SetCreateCSVT(int bCreateCSVT);
109 : void SetWriteBOM(int bWriteBOM);
110 :
111 : virtual int GetFeatureCount( int bForce = TRUE );
112 : };
113 :
114 : /************************************************************************/
115 : /* OGRCSVDataSource */
116 : /************************************************************************/
117 :
118 : class OGRCSVDataSource : public OGRDataSource
119 : {
120 : char *pszName;
121 :
122 : OGRCSVLayer **papoLayers;
123 : int nLayers;
124 :
125 : int bUpdate;
126 :
127 : CPLString osDefaultCSVName;
128 :
129 : public:
130 : OGRCSVDataSource();
131 : ~OGRCSVDataSource();
132 :
133 : int Open( const char * pszFilename,
134 : int bUpdate, int bForceAccept );
135 : int OpenTable( const char * pszFilename,
136 : const char* pszNfdcRunwaysGeomField = NULL,
137 : const char* pszGeonamesGeomFieldPrefix = NULL);
138 :
139 40 : const char *GetName() { return pszName; }
140 :
141 141 : int GetLayerCount() { return nLayers; }
142 : OGRLayer *GetLayer( int );
143 :
144 : virtual OGRLayer *CreateLayer( const char *pszName,
145 : OGRSpatialReference *poSpatialRef = NULL,
146 : OGRwkbGeometryType eGType = wkbUnknown,
147 : char ** papszOptions = NULL );
148 :
149 : virtual OGRErr DeleteLayer(int);
150 :
151 : int TestCapability( const char * );
152 :
153 2 : void SetDefaultCSVName( const char *pszName )
154 2 : { osDefaultCSVName = pszName; }
155 : };
156 :
157 : /************************************************************************/
158 : /* OGRCSVDriver */
159 : /************************************************************************/
160 :
161 : class OGRCSVDriver : public OGRSFDriver
162 226 : {
163 : public:
164 : ~OGRCSVDriver();
165 :
166 : const char *GetName();
167 : OGRDataSource *Open( const char *, int );
168 : OGRDataSource *CreateDataSource( const char *, char ** );
169 : int TestCapability( const char * );
170 :
171 : virtual OGRErr DeleteDataSource( const char *pszName );
172 :
173 : };
174 :
175 :
176 : #endif /* ndef _OGR_CSV_H_INCLUDED */
|