1 : /******************************************************************************
2 : * $Id: ogr_kml.h 16908 2009-05-02 14:53:26Z 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 : private:
76 : OGRKMLDataSource* poDS_;
77 : OGRSpatialReference* poSRS_;
78 : OGRCoordinateTransformation *poCT_;
79 :
80 : OGRFeatureDefn* poFeatureDefn_;
81 :
82 : int iNextKMLId_;
83 : int nTotalKMLCount_;
84 : int bWriter_;
85 : int nLayerNumber_;
86 : int nWroteFeatureCount_;
87 : char* pszName_;
88 :
89 : int nLastAsked;
90 : int nLastCount;
91 : };
92 :
93 : /************************************************************************/
94 : /* OGRKMLDataSource */
95 : /************************************************************************/
96 :
97 : class OGRKMLDataSource : public OGRDataSource
98 : {
99 : public:
100 : OGRKMLDataSource();
101 : ~OGRKMLDataSource();
102 :
103 : //
104 : // OGRDataSource Interface
105 : //
106 : int Open( const char* pszName, int bTestOpen );
107 4 : const char* GetName() { return pszName_; }
108 26 : int GetLayerCount() { return nLayers_; }
109 : OGRLayer* GetLayer( int nLayer );
110 : OGRLayer* CreateLayer( const char* pszName,
111 : OGRSpatialReference* poSRS = NULL,
112 : OGRwkbGeometryType eGType = wkbUnknown,
113 : char** papszOptions = NULL );
114 : int TestCapability( const char* pszCap );
115 :
116 : //
117 : // OGRKMLDataSource Interface
118 : //
119 : int Create( const char* pszName, char** papszOptions );
120 11 : const char* GetNameField() const { return pszNameField_; }
121 11 : const char* GetDescriptionField() const { return pszDescriptionField_; }
122 9 : const char* GetAltitudeMode() { return pszAltitudeMode_; }
123 9 : FILE* GetOutputFP() { return fpOutput_; }
124 : void GrowExtents( OGREnvelope *psGeomBounds );
125 : #ifdef HAVE_EXPAT
126 33 : KML* GetKMLFile() { return poKMLFile_; };
127 : #endif
128 :
129 0 : bool IsFirstCTError() { return !bIssuedCTError_; }
130 0 : void IssuedFirstCTError() { bIssuedCTError_ = true; }
131 :
132 : private:
133 :
134 : #ifdef HAVE_EXPAT
135 : KML* poKMLFile_;
136 : #endif
137 :
138 : char* pszName_;
139 :
140 : OGRKMLLayer** papoLayers_;
141 : int nLayers_;
142 :
143 : //The name of the field to use for the KML name element
144 : char* pszNameField_;
145 : char* pszDescriptionField_;
146 :
147 : //The KML altitude mode to use
148 : char* pszAltitudeMode_;
149 :
150 : char** papszCreateOptions_;
151 :
152 : // output related parameters
153 : FILE* fpOutput_;
154 :
155 : OGREnvelope oEnvelope_;
156 : int nSchemaInsertLocation_;
157 :
158 : //Have we issued a coordinate transformation already for this datasource
159 : bool bIssuedCTError_;
160 : };
161 :
162 : /************************************************************************/
163 : /* OGRKMLDriver */
164 : /************************************************************************/
165 :
166 : class OGRKMLDriver : public OGRSFDriver
167 64 : {
168 : public:
169 : ~OGRKMLDriver();
170 :
171 : //
172 : // OGRSFDriver Interface
173 : //
174 : const char* GetName();
175 : OGRDataSource* Open( const char * pszName_, int bUpdate );
176 : OGRDataSource* CreateDataSource( const char *pszName_, char** papszOptions );
177 : int TestCapability( const char* pszCap );
178 : };
179 :
180 : #endif /* OGR_KML_H_INCLUDED */
181 :
|