1
/******************************************************************************
2
* $Id: ogr_gft.h 22268 2011-04-30 13:10:40Z rouault $
4
* Project: GFT Translator
5
* Purpose: Definition of classes for OGR Google Fusion Tables driver.
6
* Author: Even Rouault, even dot rouault at mines dash paris dot org
8
******************************************************************************
9
* Copyright (c) 2011, Even Rouault <even dot rouault at mines dash paris dot org>
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:
18
* The above copyright notice and this permission notice shall be included
19
* in all copies or substantial portions of the Software.
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
****************************************************************************/
30
#ifndef _OGR_GFT_H_INCLUDED
31
#define _OGR_GFT_H_INCLUDED
33
#include "ogrsf_frmts.h"
38
/************************************************************************/
40
/************************************************************************/
41
class OGRGFTDataSource;
43
class OGRGFTLayer : public OGRLayer
46
OGRGFTDataSource* poDS;
48
OGRFeatureDefn* poFeatureDefn;
49
OGRSpatialReference *poSRS;
56
int bHiddenGeometryField;
58
OGRFeature * GetNextRawFeature();
62
virtual int FetchNextRows() = 0;
64
std::vector<CPLString> aosRows;
67
OGRFeature* BuildFeatureFromSQL(const char* pszLine);
69
static CPLString LaunderColName(const char* pszColName);
72
OGRGFTLayer(OGRGFTDataSource* poDS);
75
virtual void ResetReading();
76
virtual OGRFeature * GetNextFeature();
78
virtual OGRFeatureDefn * GetLayerDefn();
80
virtual int TestCapability( const char * );
82
virtual OGRSpatialReference*GetSpatialRef();
84
virtual const char * GetGeometryColumn();
86
virtual OGRErr SetNextByIndex( long nIndex );
88
const char * GetDefaultGeometryColumnName() { return "geometry"; }
90
static int ParseCSVResponse(char* pszLine,
91
std::vector<CPLString>& aosRes);
92
static CPLString PatchSQL(const char* pszSQL);
94
int GetGeometryFieldIndex() { return iGeometryField; }
95
int GetLatitudeFieldIndex() { return iLatitudeField; }
96
int GetLongitudeFieldIndex() { return iLongitudeField; }
98
int GetFeaturesToFetch() { return atoi(CPLGetConfigOption("GFT_PAGE_SIZE", "500")); }
101
/************************************************************************/
102
/* OGRGFTTableLayer */
103
/************************************************************************/
105
class OGRGFTTableLayer : public OGRGFTLayer
107
CPLString osTableName;
109
CPLString osGeomColumnName;
111
int bHasTriedCreateTable;
112
void CreateTableIfNecessary();
117
void BuildWhere(void);
119
CPLString osTransaction;
121
int nFeaturesInTransaction;
124
virtual int FetchNextRows();
126
OGRwkbGeometryType eGTypeForCreation;
128
std::vector<CPLString> aosColumnInternalName;
131
OGRGFTTableLayer(OGRGFTDataSource* poDS,
132
const char* pszTableName,
133
const char* pszTableId = "",
134
const char* pszGeomColumnName = "");
137
virtual void ResetReading();
139
virtual OGRFeatureDefn * GetLayerDefn();
141
virtual const char * GetName() { return osTableName.c_str(); }
142
virtual int GetFeatureCount( int bForce = TRUE );
144
virtual OGRFeature * GetFeature( long nFID );
146
virtual void SetSpatialFilter( OGRGeometry * );
147
virtual OGRErr SetAttributeFilter( const char * );
149
virtual OGRErr CreateField( OGRFieldDefn *poField,
150
int bApproxOK = TRUE );
151
virtual OGRErr CreateFeature( OGRFeature *poFeature );
152
virtual OGRErr SetFeature( OGRFeature *poFeature );
153
virtual OGRErr DeleteFeature( long nFID );
155
virtual OGRErr StartTransaction();
156
virtual OGRErr CommitTransaction();
157
virtual OGRErr RollbackTransaction();
159
const CPLString& GetTableId() const { return osTableId; }
161
virtual int TestCapability( const char * );
163
void SetGeometryType(OGRwkbGeometryType eGType);
166
/************************************************************************/
167
/* OGRGFTResultLayer */
168
/************************************************************************/
170
class OGRGFTResultLayer : public OGRGFTLayer
175
virtual int FetchNextRows();
178
OGRGFTResultLayer(OGRGFTDataSource* poDS,
180
~OGRGFTResultLayer();
182
virtual void ResetReading();
187
/************************************************************************/
188
/* OGRGFTDataSource */
189
/************************************************************************/
191
class OGRGFTDataSource : public OGRDataSource
195
OGRLayer** papoLayers;
202
int FetchAuth(const char* pszEmail, const char* pszPassword);
204
void DeleteLayer( const char *pszLayerName );
206
int bMustCleanPersistant;
212
int Open( const char * pszFilename,
215
virtual const char* GetName() { return pszName; }
217
virtual int GetLayerCount() { return nLayers; }
218
virtual OGRLayer* GetLayer( int );
219
virtual OGRLayer *GetLayerByName(const char *);
221
virtual int TestCapability( const char * );
223
virtual OGRLayer *CreateLayer( const char *pszName,
224
OGRSpatialReference *poSpatialRef = NULL,
225
OGRwkbGeometryType eGType = wkbUnknown,
226
char ** papszOptions = NULL );
227
virtual OGRErr DeleteLayer(int);
229
virtual OGRLayer* ExecuteSQL( const char *pszSQLCommand,
230
OGRGeometry *poSpatialFilter,
231
const char *pszDialect );
232
virtual void ReleaseResultSet( OGRLayer * poLayer );
234
const CPLString& GetAuth() const { return osAuth; }
235
const char* GetAPIURL() const;
236
int IsReadWrite() const { return bReadWrite; }
237
char** AddHTTPOptions(char** papszOptions = NULL);
238
CPLHTTPResult* RunSQL(const char* pszUnescapedSQL);
241
/************************************************************************/
243
/************************************************************************/
245
class OGRGFTDriver : public OGRSFDriver
250
virtual const char* GetName();
251
virtual OGRDataSource* Open( const char *, int );
252
virtual OGRDataSource* CreateDataSource( const char * pszName,
253
char **papszOptions );
254
virtual int TestCapability( const char * );
257
char **OGRGFTCSVSplitLine( const char *pszString, char chDelimiter );
258
char* OGRGFTGotoNextLine(char* pszData);
260
#endif /* ndef _OGR_GFT_H_INCLUDED */