Line data Source code
1 : /******************************************************************************
2 : * $Id $
3 : *
4 : * Project: GeoRSS Translator
5 : * Purpose: Definition of classes for OGR GeoRSS driver.
6 : * Author: Even Rouault, even dot rouault at spatialys.com
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2008-2010, Even Rouault <even dot rouault at spatialys.com>
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_GEORSS_H_INCLUDED
31 : #define OGR_GEORSS_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "ogr_p.h"
35 : #include "cpl_hash_set.h"
36 :
37 : #ifdef HAVE_EXPAT
38 : #include "ogr_expat.h"
39 : #endif
40 :
41 : constexpr int PARSER_BUF_SIZE = 8192;
42 :
43 : class OGRGeoRSSDataSource;
44 :
45 : typedef enum
46 : {
47 : GEORSS_ATOM,
48 : GEORSS_RSS,
49 : GEORSS_RSS_RDF,
50 : } OGRGeoRSSFormat;
51 :
52 : typedef enum
53 : {
54 : GEORSS_GML,
55 : GEORSS_SIMPLE,
56 : GEORSS_W3C_GEO
57 : } OGRGeoRSSGeomDialect;
58 :
59 : /************************************************************************/
60 : /* OGRGeoRSSLayer */
61 : /************************************************************************/
62 :
63 : class OGRGeoRSSLayer final : public OGRLayer
64 : {
65 : OGRFeatureDefn *poFeatureDefn;
66 : OGRSpatialReference *poSRS;
67 : OGRGeoRSSDataSource *poDS;
68 : OGRGeoRSSFormat eFormat;
69 :
70 : bool bWriteMode;
71 : int nTotalFeatureCount;
72 :
73 : // TODO(schwehr): Remove eof?
74 : bool eof;
75 : int nNextFID;
76 : VSILFILE *fpGeoRSS; /* Large file API */
77 : bool bHasReadSchema;
78 : #ifdef HAVE_EXPAT
79 : XML_Parser oParser;
80 : XML_Parser oSchemaParser;
81 : #endif
82 : OGRGeometry *poGlobalGeom;
83 : bool bStopParsing;
84 : bool bInFeature;
85 : bool hasFoundLat;
86 : bool hasFoundLon;
87 : #ifdef HAVE_EXPAT
88 : double latVal;
89 : double lonVal;
90 : #endif
91 : char *pszSubElementName;
92 : char *pszSubElementValue;
93 : int nSubElementValueLen;
94 : #ifdef HAVE_EXPAT
95 : int iCurrentField;
96 : #endif
97 : bool bInSimpleGeometry;
98 : bool bInGMLGeometry;
99 : bool bInGeoLat;
100 : bool bInGeoLong;
101 : #ifdef HAVE_EXPAT
102 : bool bFoundGeom;
103 : bool bSameSRS;
104 : #endif
105 : OGRwkbGeometryType eGeomType;
106 : char *pszGMLSRSName;
107 : bool bInTagWithSubTag;
108 : char *pszTagWithSubTag;
109 : int currentDepth;
110 : int featureDepth;
111 : int geometryDepth;
112 : #ifdef HAVE_EXPAT
113 : OGRFieldDefn *currentFieldDefn;
114 : int nWithoutEventCounter;
115 : int nDataHandlerCounter;
116 : #endif
117 : CPLHashSet *setOfFoundFields;
118 :
119 : OGRFeature *poFeature;
120 : OGRFeature **ppoFeatureTab;
121 : int nFeatureTabLength;
122 : int nFeatureTabIndex;
123 :
124 : private:
125 : #ifdef HAVE_EXPAT
126 : void AddStrToSubElementValue(const char *pszStr);
127 : #endif
128 : bool IsStandardField(const char *pszName);
129 :
130 : public:
131 : OGRGeoRSSLayer(const char *pszFilename, const char *layerName,
132 : OGRGeoRSSDataSource *poDS, OGRSpatialReference *poSRSIn,
133 : bool bWriteMode = false);
134 : ~OGRGeoRSSLayer() override;
135 :
136 : void ResetReading() override;
137 : OGRFeature *GetNextFeature() override;
138 :
139 : OGRErr ICreateFeature(OGRFeature *poFeature) override;
140 : OGRErr CreateField(const OGRFieldDefn *poField, int bApproxOK) override;
141 :
142 : OGRFeatureDefn *GetLayerDefn() override;
143 :
144 : int TestCapability(const char *) override;
145 :
146 : GIntBig GetFeatureCount(int bForce) override;
147 :
148 : GDALDataset *GetDataset() override;
149 :
150 : void LoadSchema();
151 :
152 : #ifdef HAVE_EXPAT
153 : void startElementCbk(const char *pszName, const char **ppszAttr);
154 : void endElementCbk(const char *pszName);
155 : void dataHandlerCbk(const char *data, int nLen);
156 :
157 : void startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr);
158 : void endElementLoadSchemaCbk(const char *pszName);
159 : void dataHandlerLoadSchemaCbk(const char *data, int nLen);
160 : #endif
161 : };
162 :
163 : /************************************************************************/
164 : /* OGRGeoRSSDataSource */
165 : /************************************************************************/
166 :
167 : typedef enum
168 : {
169 : GEORSS_VALIDITY_UNKNOWN,
170 : GEORSS_VALIDITY_INVALID,
171 : GEORSS_VALIDITY_VALID
172 : } OGRGeoRSSValidity;
173 :
174 : class OGRGeoRSSDataSource final : public OGRDataSource
175 : {
176 : char *pszName;
177 :
178 : OGRGeoRSSLayer **papoLayers;
179 : int nLayers;
180 :
181 : /* Export related */
182 : VSILFILE *fpOutput; /* Virtual file API */
183 :
184 : #ifdef HAVE_EXPAT
185 : OGRGeoRSSValidity validity;
186 : #endif
187 : OGRGeoRSSFormat eFormat;
188 : OGRGeoRSSGeomDialect eGeomDialect;
189 : bool bUseExtensions;
190 : bool bWriteHeaderAndFooter;
191 : #ifdef HAVE_EXPAT
192 : XML_Parser oCurrentParser;
193 : int nDataHandlerCounter;
194 : #endif
195 :
196 : public:
197 : OGRGeoRSSDataSource();
198 : ~OGRGeoRSSDataSource() override;
199 :
200 : int Open(const char *pszFilename, int bUpdate);
201 :
202 : int Create(const char *pszFilename, char **papszOptions);
203 :
204 0 : const char *GetName() override
205 : {
206 0 : return pszName;
207 : }
208 :
209 3 : int GetLayerCount() override
210 : {
211 3 : return nLayers;
212 : }
213 :
214 : OGRLayer *GetLayer(int) override;
215 :
216 : OGRLayer *ICreateLayer(const char *pszName,
217 : const OGRGeomFieldDefn *poGeomFieldDefn,
218 : CSLConstList papszOptions) override;
219 : int TestCapability(const char *) override;
220 :
221 95 : VSILFILE *GetOutputFP()
222 : {
223 95 : return fpOutput;
224 : }
225 :
226 68 : OGRGeoRSSFormat GetFormat()
227 : {
228 68 : return eFormat;
229 : }
230 :
231 95 : OGRGeoRSSGeomDialect GetGeomDialect()
232 : {
233 95 : return eGeomDialect;
234 : }
235 :
236 99 : bool GetUseExtensions()
237 : {
238 99 : return bUseExtensions;
239 : }
240 :
241 : #ifdef HAVE_EXPAT
242 : void startElementValidateCbk(const char *pszName, const char **ppszAttr);
243 : void dataHandlerValidateCbk(const char *data, int nLen);
244 : #endif
245 : };
246 :
247 : #endif /* ndef _OGR_GeoRSS_H_INCLUDED */
|