1 : /******************************************************************************
2 : * $Id$
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Definitions of OGR OGRGeoJSON driver types.
6 : * Author: Mateusz Loskot, mateusz@loskot.net
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2007, Mateusz Loskot
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 : #ifndef OGR_GEOJSON_H_INCLUDED
30 : #define OGR_GEOJSON_H_INCLUDED
31 :
32 : #include <ogrsf_frmts.h>
33 : #include <cstdio>
34 : #include <vector> // used by OGRGeoJSONLayer
35 :
36 : class OGRGeoJSONDataSource;
37 :
38 : /************************************************************************/
39 : /* OGRGeoJSONLayer */
40 : /************************************************************************/
41 :
42 : class OGRGeoJSONLayer : public OGRLayer
43 : {
44 : public:
45 :
46 : static const char* const DefaultName;
47 : static const char* const DefaultFIDColumn;
48 : static const OGRwkbGeometryType DefaultGeometryType;
49 :
50 : OGRGeoJSONLayer( const char* pszName,
51 : OGRSpatialReference* poSRS,
52 : OGRwkbGeometryType eGType,
53 : char** papszOptions,
54 : OGRGeoJSONDataSource* poDS );
55 : ~OGRGeoJSONLayer();
56 :
57 : //
58 : // OGRLayer Interface
59 : //
60 : OGRFeatureDefn* GetLayerDefn();
61 : OGRSpatialReference* GetSpatialRef();
62 :
63 : int GetFeatureCount( int bForce = TRUE );
64 : void ResetReading();
65 : OGRFeature* GetNextFeature();
66 : OGRFeature* GetFeature( long nFID );
67 : OGRErr CreateFeature( OGRFeature* poFeature );
68 : OGRErr CreateField(OGRFieldDefn* poField, int bApproxOK);
69 : int TestCapability( const char* pszCap );
70 : const char* GetFIDColumn();
71 : void SetFIDColumn( const char* pszFIDColumn );
72 :
73 : //
74 : // OGRGeoJSONLayer Interface
75 : //
76 : void AddFeature( OGRFeature* poFeature );
77 : void SetSpatialRef( OGRSpatialReference* poSRS );
78 : void DetectGeometryType();
79 : bool EvaluateSpatialFilter( OGRGeometry* poGeometry );
80 :
81 : private:
82 :
83 : typedef std::vector<OGRFeature*> FeaturesSeq;
84 : FeaturesSeq seqFeatures_;
85 : FeaturesSeq::iterator iterCurrent_;
86 :
87 : OGRGeoJSONDataSource* poDS_;
88 : OGRFeatureDefn* poFeatureDefn_;
89 : OGRSpatialReference* poSRS_;
90 : CPLString sFIDColumn_;
91 : int nOutCounter_;
92 : };
93 :
94 : /************************************************************************/
95 : /* OGRGeoJSONDataSource */
96 : /************************************************************************/
97 :
98 : class OGRGeoJSONDataSource : public OGRDataSource
99 : {
100 : public:
101 :
102 : OGRGeoJSONDataSource();
103 : ~OGRGeoJSONDataSource();
104 :
105 : //
106 : // OGRDataSource Interface
107 : //
108 : int Open( const char* pszSource );
109 : const char* GetName();
110 : int GetLayerCount();
111 : OGRLayer* GetLayer( int nLayer );
112 : OGRLayer* CreateLayer( const char* pszName,
113 : OGRSpatialReference* poSRS = NULL,
114 : OGRwkbGeometryType eGType = wkbUnknown,
115 : char** papszOptions = NULL );
116 : int TestCapability( const char* pszCap );
117 :
118 : //
119 : // OGRGeoJSONDataSource Interface
120 : //
121 : int Create( const char* pszName, char** papszOptions );
122 26 : FILE* GetOutputFile() const { return fpOut_; }
123 :
124 : enum GeometryTranslation
125 : {
126 : eGeometryPreserve,
127 : eGeometryAsCollection,
128 : };
129 :
130 : void SetGeometryTranslation( GeometryTranslation type );
131 :
132 : enum AttributesTranslation
133 : {
134 : eAtributesPreserve,
135 : eAtributesSkip
136 : };
137 :
138 : void SetAttributesTranslation( AttributesTranslation type );
139 :
140 : private:
141 :
142 : //
143 : // Private data members
144 : //
145 : char* pszName_;
146 : char* pszGeoData_;
147 : OGRGeoJSONLayer** papoLayers_;
148 : int nLayers_;
149 : FILE* fpOut_;
150 :
151 : //
152 : // Translation/Creation control flags
153 : //
154 : GeometryTranslation flTransGeom_;
155 : AttributesTranslation flTransAttrs_;
156 :
157 : //
158 : // Priavte utility functions
159 : //
160 : void Clear();
161 : int ReadFromFile( const char* pszSource );
162 : int ReadFromService( const char* pszSource );
163 : OGRGeoJSONLayer* LoadLayer();
164 : };
165 :
166 :
167 : /************************************************************************/
168 : /* OGRGeoJSONDriver */
169 : /************************************************************************/
170 :
171 : class OGRGeoJSONDriver : public OGRSFDriver
172 : {
173 : public:
174 :
175 : OGRGeoJSONDriver();
176 : ~OGRGeoJSONDriver();
177 :
178 : //
179 : // OGRSFDriver Interface
180 : //
181 : const char* GetName();
182 : OGRDataSource* Open( const char* pszName, int bUpdate );
183 : OGRDataSource* CreateDataSource( const char* pszName, char** papszOptions );
184 : OGRErr DeleteDataSource( const char* pszName );
185 : int TestCapability( const char* pszCap );
186 :
187 : //
188 : // OGRGeoJSONDriver Interface
189 : //
190 : // NOTE: New version of Open() based on Andrey's RCF 10.
191 : OGRDataSource* Open( const char* pszName, int bUpdate,
192 : char** papszOptions );
193 :
194 : };
195 :
196 : #endif /* OGR_GEOJSON_H_INCLUDED */
197 :
|