1 : /******************************************************************************
2 : * $Id: ogr_kml.h 23022 2011-09-01 19:10:17Z rouault $
3 : *
4 : * Project: KML Driver
5 : * Purpose: Declarations for OGR wrapper classes for KML, and OGR->KML
6 : * translation of geometry.
7 : * Author: Christopher Condit, condit@sdsc.edu;
8 : * Jens Oberender, j.obi@troja.net
9 : *
10 : ******************************************************************************
11 : * Copyright (c) 2006, Christopher Condit
12 : * 2007, Jens Oberender
13 : *
14 : * Permission is hereby granted, free of charge, to any person obtaining a
15 : * copy of this software and associated documentation files (the "Software"),
16 : * to deal in the Software without restriction, including without limitation
17 : * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 : * and/or sell copies of the Software, and to permit persons to whom the
19 : * Software is furnished to do so, subject to the following conditions:
20 : *
21 : * The above copyright notice and this permission notice shall be included
22 : * in all copies or substantial portions of the Software.
23 : *
24 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 : * DEALINGS IN THE SOFTWARE.
31 : ****************************************************************************/
32 : #ifndef OGR_KML_H_INCLUDED
33 : #define OGR_KML_H_INCLUDED
34 :
35 : #include "ogrsf_frmts.h"
36 :
37 : #ifdef HAVE_EXPAT
38 : # include "kmlvector.h"
39 : #endif
40 :
41 : class OGRKMLDataSource;
42 :
43 : /************************************************************************/
44 : /* OGRKMLLayer */
45 : /************************************************************************/
46 :
47 : class OGRKMLLayer : public OGRLayer
48 : {
49 : public:
50 :
51 : OGRKMLLayer( const char* pszName_,
52 : OGRSpatialReference* poSRS,
53 : int bWriter,
54 : OGRwkbGeometryType eType,
55 : OGRKMLDataSource* poDS );
56 : ~OGRKMLLayer();
57 :
58 : //
59 : // OGRLayer Interface
60 : //
61 : OGRFeatureDefn* GetLayerDefn();
62 : OGRSpatialReference* GetSpatialRef();
63 : OGRErr CreateFeature( OGRFeature* poFeature );
64 : OGRErr CreateField( OGRFieldDefn* poField, int bApproxOK = TRUE );
65 : void ResetReading();
66 : OGRFeature* GetNextFeature();
67 : int GetFeatureCount( int bForce = TRUE );
68 : int TestCapability( const char* pszCap );
69 :
70 : //
71 : // OGRKMLLayer Interface
72 : //
73 : void SetLayerNumber( int nLayer );
74 :
75 4 : void SetClosedForWriting() { bClosedForWriting = TRUE; }
76 :
77 : private:
78 : OGRKMLDataSource* poDS_;
79 : OGRSpatialReference* poSRS_;
80 : OGRCoordinateTransformation *poCT_;
81 :
82 : OGRFeatureDefn* poFeatureDefn_;
83 :
84 : int iNextKMLId_;
85 : int nTotalKMLCount_;
86 : int bWriter_;
87 : int nLayerNumber_;
88 : int nWroteFeatureCount_;
89 : int bClosedForWriting;
90 : char* pszName_;
91 :
92 : int nLastAsked;
93 : int nLastCount;
94 : };
95 :
96 : /************************************************************************/
97 : /* OGRKMLDataSource */
98 : /************************************************************************/
99 :
100 : class OGRKMLDataSource : public OGRDataSource
101 : {
102 : public:
103 : OGRKMLDataSource();
104 : ~OGRKMLDataSource();
105 :
106 : //
107 : // OGRDataSource Interface
108 : //
109 : int Open( const char* pszName, int bTestOpen );
110 20 : const char* GetName() { return pszName_; }
111 200 : int GetLayerCount() { return nLayers_; }
112 : OGRLayer* GetLayer( int nLayer );
113 : OGRLayer* CreateLayer( const char* pszName,
114 : OGRSpatialReference* poSRS = NULL,
115 : OGRwkbGeometryType eGType = wkbUnknown,
116 : char** papszOptions = NULL );
117 : int TestCapability( const char* pszCap );
118 :
119 : //
120 : // OGRKMLDataSource Interface
121 : //
122 : int Create( const char* pszName, char** papszOptions );
123 22 : const char* GetNameField() const { return pszNameField_; }
124 22 : const char* GetDescriptionField() const { return pszDescriptionField_; }
125 18 : const char* GetAltitudeMode() { return pszAltitudeMode_; }
126 18 : VSILFILE* GetOutputFP() { return fpOutput_; }
127 : void GrowExtents( OGREnvelope *psGeomBounds );
128 : #ifdef HAVE_EXPAT
129 592 : KML* GetKMLFile() { return poKMLFile_; };
130 : #endif
131 :
132 0 : bool IsFirstCTError() { return !bIssuedCTError_; }
133 0 : void IssuedFirstCTError() { bIssuedCTError_ = true; }
134 :
135 : private:
136 :
137 : #ifdef HAVE_EXPAT
138 : KML* poKMLFile_;
139 : #endif
140 :
141 : char* pszName_;
142 :
143 : OGRKMLLayer** papoLayers_;
144 : int nLayers_;
145 :
146 : //The name of the field to use for the KML name element
147 : char* pszNameField_;
148 : char* pszDescriptionField_;
149 :
150 : //The KML altitude mode to use
151 : char* pszAltitudeMode_;
152 :
153 : char** papszCreateOptions_;
154 :
155 : // output related parameters
156 : VSILFILE* fpOutput_;
157 :
158 : OGREnvelope oEnvelope_;
159 :
160 : //Have we issued a coordinate transformation already for this datasource
161 : bool bIssuedCTError_;
162 : };
163 :
164 : /************************************************************************/
165 : /* OGRKMLDriver */
166 : /************************************************************************/
167 :
168 : class OGRKMLDriver : public OGRSFDriver
169 389 : {
170 : public:
171 : ~OGRKMLDriver();
172 :
173 : //
174 : // OGRSFDriver Interface
175 : //
176 : const char* GetName();
177 : OGRDataSource* Open( const char * pszName_, int bUpdate );
178 : OGRDataSource* CreateDataSource( const char *pszName_, char** papszOptions );
179 : int TestCapability( const char* pszCap );
180 : };
181 :
182 : #endif /* OGR_KML_H_INCLUDED */
183 :
|