1 : /******************************************************************************
2 : * $Id: ogr_elastic.h 23836 2012-01-31 19:32:04Z rouault $
3 : *
4 : * Project: ElasticSearch Translator
5 : * Purpose:
6 : * Author:
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2011, Adam Estrada
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_ELASTIC_H_INCLUDED
31 : #define _OGR_ELASTIC_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "ogr_p.h"
35 : #include "cpl_hash_set.h"
36 :
37 : class OGRElasticDataSource;
38 :
39 : /************************************************************************/
40 : /* OGRElasticLayer */
41 : /************************************************************************/
42 :
43 : class OGRElasticLayer : public OGRLayer {
44 : OGRFeatureDefn* poFeatureDefn;
45 : OGRSpatialReference* poSRS;
46 : OGRElasticDataSource* poDS;
47 : CPLString sIndex;
48 : void* pAttributes;
49 : char* pszLayerName;
50 :
51 : public:
52 : OGRElasticLayer(const char *pszFilename,
53 : const char* layerName,
54 : OGRElasticDataSource* poDS,
55 : OGRSpatialReference *poSRSIn,
56 : int bWriteMode = FALSE);
57 : ~OGRElasticLayer();
58 :
59 : void ResetReading();
60 : OGRFeature * GetNextFeature();
61 :
62 : OGRErr CreateFeature(OGRFeature *poFeature);
63 : OGRErr CreateField(OGRFieldDefn *poField, int bApproxOK);
64 :
65 : OGRFeatureDefn * GetLayerDefn();
66 :
67 : int TestCapability(const char *);
68 :
69 : OGRSpatialReference *GetSpatialRef();
70 :
71 : int GetFeatureCount(int bForce);
72 :
73 : void PushIndex();
74 : CPLString BuildMap();
75 : };
76 :
77 : /************************************************************************/
78 : /* OGRElasticDataSource */
79 : /************************************************************************/
80 :
81 : class OGRElasticDataSource : public OGRDataSource {
82 : char* pszName;
83 : char* pszServer;
84 :
85 : OGRElasticLayer** papoLayers;
86 : int nLayers;
87 :
88 : public:
89 : OGRElasticDataSource();
90 : ~OGRElasticDataSource();
91 :
92 : int Open(const char * pszFilename,
93 : int bUpdate);
94 :
95 : int Create(const char *pszFilename,
96 : char **papszOptions);
97 :
98 14 : const char* GetName() {
99 14 : return pszName;
100 : }
101 :
102 0 : int GetLayerCount() {
103 0 : return nLayers;
104 : }
105 : OGRLayer* GetLayer(int);
106 :
107 : OGRLayer * CreateLayer(const char * pszLayerName,
108 : OGRSpatialReference *poSRS,
109 : OGRwkbGeometryType eType,
110 : char ** papszOptions);
111 :
112 : int TestCapability(const char *);
113 :
114 : void UploadFile(const CPLString &url, const CPLString &data);
115 : void DeleteIndex(const CPLString &url);
116 :
117 : int bOverwrite;
118 : int nBulkUpload;
119 : char* pszWriteMap;
120 : char* pszMapping;
121 : };
122 :
123 : /************************************************************************/
124 : /* OGRElasticDriver */
125 : /************************************************************************/
126 :
127 389 : class OGRElasticDriver : public OGRSFDriver {
128 : public:
129 : ~OGRElasticDriver();
130 :
131 : const char* GetName();
132 : OGRDataSource* Open(const char *, int);
133 : OGRDataSource* CreateDataSource(const char * pszName, char **papszOptions);
134 : int TestCapability(const char *);
135 :
136 : };
137 :
138 :
139 : #endif /* ndef _OGR_Elastic_H_INCLUDED */
|