1 : /******************************************************************************
2 : * $Id: ogr_svg.h 22110 2011-04-03 19:05:10Z rouault $
3 : *
4 : * Project: SVG Translator
5 : * Purpose: Definition of classes for OGR .svg driver.
6 : * Author: Even Rouault, even dot rouault at mines dash paris dot org
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2011, Even Rouault
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_SVG_H_INCLUDED
31 : #define _OGR_SVG_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 :
35 : #ifdef HAVE_EXPAT
36 : #include "ogr_expat.h"
37 : #endif
38 :
39 : class OGRSVGDataSource;
40 :
41 : typedef enum
42 : {
43 : SVG_POINTS,
44 : SVG_LINES,
45 : SVG_POLYGONS,
46 : } SVGGeometryType;
47 :
48 : /************************************************************************/
49 : /* OGRSVGLayer */
50 : /************************************************************************/
51 :
52 : class OGRSVGLayer : public OGRLayer
53 : {
54 : OGRFeatureDefn* poFeatureDefn;
55 : OGRSpatialReference *poSRS;
56 : OGRSVGDataSource* poDS;
57 : CPLString osLayerName;
58 :
59 : SVGGeometryType svgGeomType;
60 :
61 : int nTotalFeatures;
62 : int nNextFID;
63 : VSILFILE* fpSVG; /* Large file API */
64 :
65 : #ifdef HAVE_EXPAT
66 : XML_Parser oParser;
67 : XML_Parser oSchemaParser;
68 : #endif
69 : char* pszSubElementValue;
70 : int nSubElementValueLen;
71 : int iCurrentField;
72 :
73 : OGRFeature* poFeature;
74 : OGRFeature ** ppoFeatureTab;
75 : int nFeatureTabLength;
76 : int nFeatureTabIndex;
77 :
78 : int depthLevel;
79 : int interestingDepthLevel;
80 : int inInterestingElement;
81 :
82 : int bStopParsing;
83 : int nWithoutEventCounter;
84 : int nDataHandlerCounter;
85 :
86 : OGRSVGLayer *poCurLayer;
87 :
88 : private:
89 : void LoadSchema();
90 :
91 : public:
92 : OGRSVGLayer(const char *pszFilename,
93 : const char* layerName,
94 : SVGGeometryType svgGeomType,
95 : OGRSVGDataSource* poDS);
96 : ~OGRSVGLayer();
97 :
98 : virtual void ResetReading();
99 : virtual OGRFeature * GetNextFeature();
100 :
101 6 : virtual const char* GetName() { return osLayerName.c_str(); }
102 : virtual OGRwkbGeometryType GetGeomType();
103 :
104 : virtual int GetFeatureCount( int bForce = TRUE );
105 :
106 : virtual OGRFeatureDefn * GetLayerDefn();
107 :
108 : virtual int TestCapability( const char * );
109 :
110 : virtual OGRSpatialReference*GetSpatialRef();
111 :
112 : #ifdef HAVE_EXPAT
113 : void startElementCbk(const char *pszName, const char **ppszAttr);
114 : void endElementCbk(const char *pszName);
115 : void dataHandlerCbk(const char *data, int nLen);
116 :
117 : void startElementLoadSchemaCbk(const char *pszName, const char **ppszAttr);
118 : void endElementLoadSchemaCbk(const char *pszName);
119 : void dataHandlerLoadSchemaCbk(const char *data, int nLen);
120 : #endif
121 : };
122 :
123 : /************************************************************************/
124 : /* OGRSVGDataSource */
125 : /************************************************************************/
126 :
127 : typedef enum
128 : {
129 : SVG_VALIDITY_UNKNOWN,
130 : SVG_VALIDITY_INVALID,
131 : SVG_VALIDITY_VALID
132 : } OGRSVGValidity;
133 :
134 : class OGRSVGDataSource : public OGRDataSource
135 : {
136 : char* pszName;
137 :
138 : OGRSVGLayer** papoLayers;
139 : int nLayers;
140 :
141 : OGRSVGValidity eValidity;
142 : int bIsCloudmade;
143 :
144 : #ifdef HAVE_EXPAT
145 : XML_Parser oCurrentParser;
146 : int nDataHandlerCounter;
147 : #endif
148 :
149 : public:
150 : OGRSVGDataSource();
151 : ~OGRSVGDataSource();
152 :
153 : int Open( const char * pszFilename,
154 : int bUpdate );
155 :
156 1 : virtual const char* GetName() { return pszName; }
157 :
158 11 : virtual int GetLayerCount() { return nLayers; }
159 : virtual OGRLayer* GetLayer( int );
160 :
161 : virtual int TestCapability( const char * );
162 :
163 :
164 : #ifdef HAVE_EXPAT
165 : void startElementValidateCbk(const char *pszName, const char **ppszAttr);
166 : void dataHandlerValidateCbk(const char *data, int nLen);
167 : #endif
168 : };
169 :
170 : /************************************************************************/
171 : /* OGRSVGDriver */
172 : /************************************************************************/
173 :
174 : class OGRSVGDriver : public OGRSFDriver
175 226 : {
176 : public:
177 : ~OGRSVGDriver();
178 :
179 : const char* GetName();
180 : OGRDataSource* Open( const char *, int );
181 :
182 : virtual int TestCapability( const char * );
183 : };
184 :
185 : #endif /* ndef _OGR_SVG_H_INCLUDED */
|