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 <cpl_error.h>
39 
40 // Forward declarations
41 class OGRGeometry;
42 class OGREnvelope;
43 class OGRSpatialReference;
44 class OGRFeatureDefn;
45 class OGRFieldDefn;
46 
47 namespace te
48 {
49  namespace da
50  {
51  class DataSetType;
52  }
53 
54  namespace gm
55  {
56  class Envelope;
57  class Geometry;
58  }
59 }
60 
61 namespace te
62 {
63  namespace ogr
64  {
65  /*!
66  \brief It converts the OGR Geometry to TerraLib Geometry.
67 
68  \param ogrGeom A valid OGR Geometry.
69 
70  \return A valid TerraLib Geometry.
71 
72  \exception Exception It throws an exception if the OGR geometry can not be converted.
73 
74  \note It uses the WKB to create the TerraLib Geometry
75  \note The caller of this function will take the ownership of the returned TerraLib Geometry.
76  */
77  TEOGREXPORT te::gm::Geometry* Convert2TerraLib(OGRGeometry* ogrGeom);
78 
79  /*!
80  \brief It converts the TerraLib Geometry to OGR Geometry.
81 
82  \param teGeom A valid TerraLib Geometry.
83 
84  \return A valid TerraLib geometry.
85 
86  \exception Exception It throws an exception if the TerraLib geometry can not be converted.
87 
88  \note It uses the WKB to create the TerraLib Geometry
89  \note The caller of this function will take the ownership of the returned OGR Geometry.
90  */
91  TEOGREXPORT OGRGeometry* Convert2OGR(const te::gm::Geometry* teGeom);
92 
93  /*!
94  \brief It converts the TerraLib Geometry to OGR Geometry.
95 
96  \param teGeom A valid TerraLib Geometry.
97 
98  \param srs OGR srs information..
99 
100  \return A valid TerraLib geometry.
101 
102  \exception Exception It throws an exception if the TerraLib geometry can not be converted.
103 
104  \note It uses the WKB to create the TerraLib Geometry
105  \note The caller of this function will take the ownership of the returned OGR Geometry.
106  */
107  TEOGREXPORT OGRGeometry* Convert2OGR(const te::gm::Geometry* teGeom, const OGRSpatialReference* srs);
108 
109  /*!
110  \brief It converts the OGR Envelope to TerraLib Envelope.
111 
112  \param env A valid OGR Envelope.
113 
114  \return A valid TerraLib Envelope.
115 
116  \note The caller of this function will take the ownership of the returned TerraLib Envelope.
117  */
118  TEOGREXPORT te::gm::Envelope* Convert2TerraLib(const OGREnvelope* env);
119 
120  /*!
121  \brief It converts the TerraLib Envelope to OGR Envelope.
122 
123  \param env A valid TerraLib Envelope.
124 
125  \return A valid OGR Envelope.
126 
127  \note The caller of this function will take the ownership of the returned OGR Envelope.
128  */
129  TEOGREXPORT OGREnvelope* Convert2OGR(const te::gm::Envelope* env);
130 
131  /*!
132  \brief It converts the OGR Projection to TerraLib Projection.
133 
134  \param osrs A valid OGR Projection.
135 
136  \return An SRS id recognized by TerraLib or an indication of unknown SRS (TE_UNKNOWN_SRS)
137  */
138  TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference* osrs);
139 
140  /*!
141  \brief It converts the TerraLib Projection to OGR Projection.
142 
143  \param srid A valid TerraLib Projection id.
144 
145  \return A valid OGR Spatial Reference System.
146 
147  \exception Exception It throws an exception if the SRS can not be imported using OGR.
148 
149  \note The caller of this function will take the ownership of the returned OGR Spatial Reference System.
150  */
151  TEOGREXPORT OGRSpatialReference* Convert2OGRProjection(int srid);
152 
153  /*!
154  \brief It inserts a OGR Feature Definition to TerraLib DataSet Type
155 
156  \param featDef A valid OGR Feature Definition.
157  \param dt Pointer to a TerraLib dataset type previously created. Do not pass NULL.
158  \param srs Optional parameter to set the SRS of geometry fields.
159 
160  \exception Exception It throws an exception if the feature definition can not be converted.
161 
162  \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
163  \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
164  */
165  TEOGREXPORT void Convert2TerraLib(OGRFeatureDefn* featDef, te::da::DataSetType* dt, int srs=TE_UNKNOWN_SRS);
166 
167  /*!
168  \brief It converts the OGR Feature Definition to TerraLib DataSet Type
169 
170  \param featDef A valid OGR Feature Definition.
171  \param srs Optional parameter to set the SRS of geometry fields.
172 
173  \return A valid TerraLib DataSet Type.
174 
175  \exception Exception It throws an exception if the feature definition can not be converted.
176 
177  \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
178  \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
179  \note The caller of this function will take the ownership of the returned TerraLib DataSet Type.
180  */
181  TEOGREXPORT te::da::DataSetType* Convert2TerraLib(OGRFeatureDefn* featDef, int srs=TE_UNKNOWN_SRS);
182 
183  /*!
184  \brief It converts the TerraLib DataSet Type to OGR Feature Definition
185 
186  \param dt A valid TerraLib DataSet Type.
187 
188  \return A valid OGR Feature Definition.
189 
190  \exception Exception It throws an exception if the data set type can not be converted.
191 
192  \note It uses the method that converts a TerraLib Property Type to OGR Field Definition.
193  \note The caller of this function will take the ownership of the returned OGR Feature Definition.
194  */
195  TEOGREXPORT OGRFeatureDefn* Convert2OGR(te::da::DataSetType* dt);
196 
197  /*!
198  \brief It converts the OGR Field Definition to TerraLib Property Type
199 
200  \param fieldDef A valid OGR Field Definition.
201 
202  \return A valid TerraLib Property Type.
203 
204  \exception Exception It throws an exception if the data type is not supported by TerraLib.
205 
206  \note The caller of this function will take the ownership of the returned TerraLib Property Type.
207  */
208  TEOGREXPORT te::dt::Property* Convert2TerraLib(OGRFieldDefn* fieldDef);
209 
210  /*!
211  \brief It converts the TerraLib Property Type to OGR Field Definition
212 
213  \param pt A valid TerraLib Property Type.
214 
215  \return A valid OGR Field Definition.
216 
217  \exception Exception It throws an exception if the data type is not supported by OGR.
218  */
219  TEOGREXPORT OGRFieldDefn* Convert2OGR(te::dt::Property* p);
220 
221  /*!
222  \brief It converts the OGR Geometry Type element to TerraLib Geometry Type
223 
224  \param ogrGeomType A valid OGR Geometry Type element.
225 
226  \return A valid TerraLib Geometry Type
227  */
228  TEOGREXPORT te::gm::GeomType Convert2TerraLib(OGRwkbGeometryType ogrGeomType);
229 
230  /*!
231  \brief It converts the TerraLib Geometry Type element to OGR Geometry Type
232 
233  \param geomType A valid TerraLib Geometry Type.
234 
235  \return A valid OGR Geometry Type element
236 
237  \exception Exception It throws an exception if the geometry type is not supported by OGR.
238  */
239  TEOGREXPORT OGRwkbGeometryType Convert2OGR(te::gm::GeomType geomType);
240 
241  /*!
242  \brief It tries extract the driver name used by OGR Library based on the given path.
243 
244  \param path The path that will be consulted.
245 
246  \return The driver name used by OGR Library or an empty string if not possible extract the driver name.
247  */
248  std::string GetDriverName(const std::string& path);
249 
250  /*!
251  \brief It returns the list of OGR Drivers available.
252 
253  \param filterCreate Set TRUE to indicate to retrieve only the drivers with the capacity to create datasources.
254 
255  \return A list of OGR Drivers.
256  */
257  TEOGREXPORT std::vector<std::string> GetOGRDrivers(bool filterCreate = false);
258 
259  TEOGREXPORT std::string GetOGRConnectionInfo(const std::map<std::string, std::string>& connInfo);
260 
261  TEOGREXPORT std::string RemoveSpatialSql(const std::string& sql);
262 
263  /*!
264  \brief Returns a reference to a static mutex initialized when this module is initialized.
265  \return Returns a reference to a static mutex initialized when this module is initialized.
266  */
267  TEOGREXPORT boost::mutex& getStaticMutex();
268 
269  void OGRErrorHandler(CPLErr eErrClass, int errNo, const char* msg);
270  } // end namespace ogr
271 } // end namespace te
272 
273 #endif // __TERRALIB_OGR_INTERNAL_UTILS_H
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
A class that models the description of a dataset.
Definition: DataSetType.h:72
#define TEOGREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:79
It models a property definition.
Definition: Property.h:59
std::string GetDriverName(const std::string &path)
It tries extract the driver name used by OGR Library based on the given path.
TEOGREXPORT std::string GetOGRConnectionInfo(const std::map< std::string, std::string > &connInfo)
TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:41
URI C++ Library.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Definition: Geometry.h:74
Configuration flags for the OGR Driver Implementation of TerraLib.
TEOGREXPORT boost::mutex & getStaticMutex()
Returns a reference to a static mutex initialized when this module is initialized.
void OGRErrorHandler(CPLErr eErrClass, int errNo, const char *msg)
TEOGREXPORT std::vector< std::string > GetOGRDrivers(bool filterCreate=false)
It returns the list of OGR Drivers available.
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
TEOGREXPORT OGRSpatialReference * Convert2OGRProjection(int srid)
It converts the TerraLib Projection to OGR Projection.
TEOGREXPORT std::string RemoveSpatialSql(const std::string &sql)