Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file terralib/ogr/Utils.h
22
23 \brief Utility functions for OGR support.
24*/
25
26#ifndef __TERRALIB_OGR_INTERNAL_UTILS_H
27#define __TERRALIB_OGR_INTERNAL_UTILS_H
28
29// TerraLib
30#include "Config.h"
31#include "../srs/Config.h"
32
33// BOOST
34#include <boost/thread/mutex.hpp>
35
36// OGR
37#include <ogr_core.h>
38#include <ogr_feature.h>
39#include <cpl_error.h>
40
41// Forward declarations
42class GDALDataset;
43class OGRGeometry;
44class OGREnvelope;
45class OGRSpatialReference;
46class OGRFeatureDefn;
47class OGRFieldDefn;
48class OGRLayer;
49
50namespace te
51{
52 namespace da
53 {
54 class DataSetType;
55 class FieldNameValidator;
56 }
57
58 namespace gm
59 {
60 class Envelope;
61 class Geometry;
62 }
63}
64
65namespace te
66{
67 namespace ogr
68 {
69 /*!
70 \brief It converts the OGR Geometry to TerraLib Geometry.
71
72 \param ogrGeom A valid OGR Geometry.
73
74 \return A valid TerraLib Geometry.
75
76 \exception Exception It throws an exception if the OGR geometry can not be converted.
77
78 \note It uses the WKB to create the TerraLib Geometry
79 \note The caller of this function will take the ownership of the returned TerraLib Geometry.
80 */
82
83 /*!
84 \brief It converts the TerraLib Geometry to OGR Geometry.
85
86 \param teGeom A valid TerraLib Geometry.
87
88 \return A valid TerraLib geometry.
89
90 \exception Exception It throws an exception if the TerraLib geometry can not be converted.
91
92 \note It uses the WKB to create the TerraLib Geometry
93 \note The caller of this function will take the ownership of the returned OGR Geometry.
94 */
95 TEOGREXPORT OGRGeometry* Convert2OGR(const te::gm::Geometry* teGeom);
96
97 /*!
98 \brief It converts the TerraLib Geometry to OGR Geometry.
99
100 \param teGeom A valid TerraLib Geometry.
101
102 \param srs OGR srs information. It must not be const so it can be shared with the created geometry without the need of copying it.
103
104 \return A valid TerraLib geometry.
105
106 \exception Exception It throws an exception if the TerraLib geometry can not be converted.
107
108 \note It uses the WKB to create the TerraLib Geometry
109 \note The caller of this function will take the ownership of the returned OGR Geometry.
110 */
111 TEOGREXPORT OGRGeometry* Convert2OGR(const te::gm::Geometry* teGeom, OGRSpatialReference* srs);
112
113 /*!
114 \brief It converts the OGR Envelope to TerraLib Envelope.
115
116 \param env A valid OGR Envelope.
117
118 \return A valid TerraLib Envelope.
119
120 \note The caller of this function will take the ownership of the returned TerraLib Envelope.
121 */
123
124 /*!
125 \brief It converts the TerraLib Envelope to OGR Envelope.
126
127 \param env A valid TerraLib Envelope.
128
129 \return A valid OGR Envelope.
130
131 \note The caller of this function will take the ownership of the returned OGR Envelope.
132 */
133 TEOGREXPORT OGREnvelope* Convert2OGR(const te::gm::Envelope* env);
134
135 /*!
136 \brief It converts the OGR Projection to TerraLib Projection.
137
138 \param osrs A valid OGR Projection.
139
140 \return An SRS id recognized by TerraLib or an indication of unknown SRS (TE_UNKNOWN_SRS)
141 */
142 TEOGREXPORT int Convert2TerraLibProjection( const OGRSpatialReference& osrs );
143
144 /*!
145 \brief It converts the OGR Projection to TerraLib Projection.
146
147 \param osrs A valid OGR Projection.
148
149 \return An SRS id recognized by TerraLib or an indication of unknown SRS (TE_UNKNOWN_SRS)
150 */
151 TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference* osrs);
152
153 /*!
154 \brief It converts the TerraLib Projection to OGR Projection.
155
156 \param srid A valid TerraLib Projection id.
157
158 \return A valid OGR Spatial Reference System.
159
160 \exception Exception It throws an exception if the SRS can not be imported using OGR.
161
162 \note The caller of this function will take the ownership of the returned OGR Spatial Reference System.
163 */
164 TEOGREXPORT OGRSpatialReference* Convert2OGRProjection(int srid);
165
166 /*!
167 \brief It inserts a OGR Feature Definition to TerraLib DataSet Type
168
169 \param featDef A valid OGR Feature Definition.
170 \param dt Pointer to a TerraLib dataset type previously created. Do not pass NULL.
171 \param srs Optional parameter to set the SRS of geometry fields.
172 \param geometryPropertyName A geomtry property name to force or an empty string to automatically find this value.
173
174 \exception Exception It throws an exception if the feature definition can not be converted.
175
176 \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
177 \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
178 */
179 TEOGREXPORT void Convert2TerraLib(OGRFeatureDefn* featDef, te::da::DataSetType* dt, const std::string& geometryPropertyName, int srs=TE_UNKNOWN_SRS);
180
181 /*!
182 \brief It converts the OGR Feature Definition to TerraLib DataSet Type
183
184 \param featDef A valid OGR Feature Definition.
185 \param srs Optional parameter to set the SRS of geometry fields.
186 \param geometryPropertyName A geomtry property name to force or an empty string to automatically find this value.
187
188 \return A valid TerraLib DataSet Type.
189
190 \exception Exception It throws an exception if the feature definition can not be converted.
191
192 \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
193 \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
194 \note The caller of this function will take the ownership of the returned TerraLib DataSet Type.
195 */
196 TEOGREXPORT te::da::DataSetType* Convert2TerraLib(OGRFeatureDefn* featDef, const std::string& geometryPropertyName, int srs=TE_UNKNOWN_SRS);
197
198 /*!
199 \brief It converts the OGR Feature Definition to TerraLib DataSet Type. It also handles FID and Geometry property issues
200
201 \param ogrLayer A valid OGR Layer.
202 \param srs Optional parameter to set the SRS of geometry fields.
203
204 \return A valid TerraLib DataSet Type.
205
206 \exception Exception It throws an exception if the feature definition can not be converted.
207
208 \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
209 \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
210 \note The caller of this function will take the ownership of the returned TerraLib DataSet Type.
211 */
212 TEOGREXPORT te::da::DataSetType* GetDataSetType(GDALDataset* gdalDataSet, OGRLayer* ogrLayer, int srs = TE_UNKNOWN_SRS);
213
214 /*!
215 \brief It converts the TerraLib DataSet Type to OGR Feature Definition
216
217 \param dt A valid TerraLib DataSet Type.
218
219 \return A valid OGR Feature Definition.
220
221 \exception Exception It throws an exception if the data set type can not be converted.
222
223 \note It uses the method that converts a TerraLib Property Type to OGR Field Definition.
224 \note The caller of this function will take the ownership of the returned OGR Feature Definition.
225 */
227
228 /*!
229 \brief It converts the OGR Field Definition to TerraLib Property Type
230
231 \param fieldDef A valid OGR Field Definition.
232
233 \return A valid TerraLib Property Type.
234
235 \exception Exception It throws an exception if the data type is not supported by TerraLib.
236
237 \note The caller of this function will take the ownership of the returned TerraLib Property Type.
238 */
240
241 /*!
242 \brief It converts the TerraLib Property Type to OGR Field Definition
243
244 \param pt A valid TerraLib Property Type.
245
246 \return A valid OGR Field Definition.
247
248 \exception Exception It throws an exception if the data type is not supported by OGR.
249 */
251
252 /*!
253 \brief It converts the TerraLib Geometric Property Type to OGR Geometric Field Definition
254
255 \param pt A valid TerraLib Geometric Property Type.
256
257 \return A valid OGR Geometric Field Definition.
258
259 \exception Exception It throws an exception if the data type is not supported by OGR.
260 */
262
263 /*!
264 \brief It converts the OGR Geometry Type element to TerraLib Geometry Type
265
266 \param ogrGeomType A valid OGR Geometry Type element.
267
268 \return A valid TerraLib Geometry Type
269 */
270 TEOGREXPORT te::gm::GeomType Convert2TerraLib(OGRwkbGeometryType ogrGeomType);
271
272 /*!
273 \brief It converts the TerraLib Geometry Type element to OGR Geometry Type
274
275 \param geomType A valid TerraLib Geometry Type.
276
277 \return A valid OGR Geometry Type element
278
279 \exception Exception It throws an exception if the geometry type is not supported by OGR.
280 */
281 TEOGREXPORT OGRwkbGeometryType Convert2OGR(te::gm::GeomType geomType);
282
283 /*!
284 \brief It tries extract the driver name used by OGR Library based on the given path.
285
286 \param path The path that will be consulted.
287
288 \return The driver name used by OGR Library or an empty string if not possible extract the driver name.
289 */
290 std::string GetDriverName(const std::string& path);
291
292 /*!
293 \brief It returns the list of OGR Drivers available.
294
295 \param filterCreate Set TRUE to indicate to retrieve only the drivers with the capacity to create datasources.
296
297 \return A list of OGR Drivers.
298 */
299 TEOGREXPORT std::vector<std::string> GetOGRDrivers(bool filterCreate = false);
300
301 TEOGREXPORT std::string GetOGRConnectionInfo(const std::map<std::string, std::string>& connInfo);
302
303 TEOGREXPORT std::string RemoveSpatialSql(const std::string& sql);
304
305 /*!
306 \brief Returns a reference to a static mutex initialized when this module is initialized.
307 \return Returns a reference to a static mutex initialized when this module is initialized.
308 */
310
311 void OGRErrorHandler(CPLErr eErrClass, int errNo, const char* msg);
312
313 /*!
314 \brief Creates a GDALDataSet based on the given fileName and open flags. The main purpose of this function is to ensure that known files with extensions will be open if the correct drivers
315 */
316 TEOGREXPORT GDALDataset* CreateGDALDataSet(const std::string& pszFilename, unsigned int nOpenFlags);
317
318 /*!
319 \brief Executes the given query in the given dataSet. Throws exception in case of error. It also handles FID for specific drivers
320 */
321 TEOGREXPORT OGRLayer* ExecuteSQL(GDALDataset* gdalDataSet, const std::string& query);
322
323 //!< Initialized the validator from the given layer definition
324 bool InitValidator(te::da::FieldNameValidator& validator, OGRFeatureDefn* ogrFeatureDefinition);
325
326 } // end namespace ogr
327} // end namespace te
328
329#endif // __TERRALIB_OGR_INTERNAL_UTILS_H
A class that models the description of a dataset.
Definition DataSetType.h:73
This class is responsible for validating field names. It can handle size limits, fix special characte...
It models a property definition.
Definition Property.h:60
An Envelope defines a 2D rectangular region.
Definition Envelope.h:52
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition Geometry.h:78
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition Enums.h:42
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
TEOGREXPORT OGRGeomFieldDefn * Convert2OGRGeom(te::dt::Property *p)
It converts the TerraLib Geometric Property Type to OGR Geometric Field Definition.
TEOGREXPORT te::da::DataSetType * GetDataSetType(GDALDataset *gdalDataSet, OGRLayer *ogrLayer, int srs=TE_UNKNOWN_SRS)
It converts the OGR Feature Definition to TerraLib DataSet Type. It also handles FID and Geometry pro...
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
TEOGREXPORT std::string GetOGRConnectionInfo(const std::map< std::string, std::string > &connInfo)
TEOGREXPORT OGRSpatialReference * Convert2OGRProjection(int srid)
It converts the TerraLib Projection to OGR Projection.
bool InitValidator(te::da::FieldNameValidator &validator, OGRFeatureDefn *ogrFeatureDefinition)
TEOGREXPORT boost::mutex & getStaticMutex()
Returns a reference to a static mutex initialized when this module is initialized.
TEOGREXPORT OGRLayer * ExecuteSQL(GDALDataset *gdalDataSet, const std::string &query)
Executes the given query in the given dataSet. Throws exception in case of error. It also handles FID...
TEOGREXPORT GDALDataset * CreateGDALDataSet(const std::string &pszFilename, unsigned int nOpenFlags)
Creates a GDALDataSet based on the given fileName and open flags. The main purpose of this function i...
TEOGREXPORT std::string RemoveSpatialSql(const std::string &sql)
void OGRErrorHandler(CPLErr eErrClass, int errNo, const char *msg)
TEOGREXPORT int Convert2TerraLibProjection(const OGRSpatialReference &osrs)
It converts the OGR Projection to TerraLib Projection.
std::string GetDriverName(const std::string &path)
It tries extract the driver name used by OGR Library based on the given path.
TEOGREXPORT std::vector< std::string > GetOGRDrivers(bool filterCreate=false)
It returns the list of OGR Drivers available.
TerraLib.
#define TEOGREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition Config.h:79
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition Config.h:43
Proxy configuration file for TerraView (see terraview_config.h).