1 : /******************************************************************************
2 : * $Id: ogr_csv.h 25806 2013-03-26 18:30:18Z warmerdam $
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 bIsEurostatTSV;
86 : int nEurostatDims;
87 :
88 : int nTotalFeatures;
89 :
90 : public:
91 : OGRCSVLayer( const char *pszName, VSILFILE *fp, const char *pszFilename,
92 : int bNew, int bInWriteMode, char chDelimiter,
93 : const char* pszNfdcRunwaysGeomField,
94 : const char* pszGeonamesGeomFieldPrefix );
95 : ~OGRCSVLayer();
96 :
97 : void ResetReading();
98 : OGRFeature * GetNextFeature();
99 :
100 32215 : OGRFeatureDefn * GetLayerDefn() { return poFeatureDefn; }
101 :
102 : int TestCapability( const char * );
103 :
104 : virtual OGRErr CreateField( OGRFieldDefn *poField,
105 : int bApproxOK = TRUE );
106 :
107 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
108 :
109 : void SetCRLF(int);
110 : void SetWriteGeometry(OGRCSVGeometryFormat eGeometryFormat);
111 : void SetCreateCSVT(int bCreateCSVT);
112 : void SetWriteBOM(int bWriteBOM);
113 :
114 : virtual int GetFeatureCount( int bForce = TRUE );
115 :
116 : OGRErr WriteHeader();
117 : };
118 :
119 : /************************************************************************/
120 : /* OGRCSVDataSource */
121 : /************************************************************************/
122 :
123 : class OGRCSVDataSource : public OGRDataSource
124 : {
125 : char *pszName;
126 :
127 : OGRCSVLayer **papoLayers;
128 : int nLayers;
129 :
130 : int bUpdate;
131 :
132 : CPLString osDefaultCSVName;
133 :
134 : public:
135 : OGRCSVDataSource();
136 : ~OGRCSVDataSource();
137 :
138 : int Open( const char * pszFilename,
139 : int bUpdate, int bForceAccept );
140 : int OpenTable( const char * pszFilename,
141 : const char* pszNfdcRunwaysGeomField = NULL,
142 : const char* pszGeonamesGeomFieldPrefix = NULL);
143 :
144 106 : const char *GetName() { return pszName; }
145 :
146 224 : int GetLayerCount() { return nLayers; }
147 : OGRLayer *GetLayer( int );
148 :
149 : virtual OGRLayer *CreateLayer( const char *pszName,
150 : OGRSpatialReference *poSpatialRef = NULL,
151 : OGRwkbGeometryType eGType = wkbUnknown,
152 : char ** papszOptions = NULL );
153 :
154 : virtual OGRErr DeleteLayer(int);
155 :
156 : int TestCapability( const char * );
157 :
158 10 : void SetDefaultCSVName( const char *pszName )
159 10 : { osDefaultCSVName = pszName; }
160 :
161 : static CPLString GetRealExtension(CPLString osFilename);
162 : };
163 :
164 : /************************************************************************/
165 : /* OGRCSVDriver */
166 : /************************************************************************/
167 :
168 : class OGRCSVDriver : public OGRSFDriver
169 244 : {
170 : public:
171 : ~OGRCSVDriver();
172 :
173 : const char *GetName();
174 : OGRDataSource *Open( const char *, int );
175 : OGRDataSource *CreateDataSource( const char *, char ** );
176 : int TestCapability( const char * );
177 :
178 : virtual OGRErr DeleteDataSource( const char *pszName );
179 :
180 : };
181 :
182 :
183 : #endif /* ndef _OGR_CSV_H_INCLUDED */
|