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 OGR Envelope to TerraLib Envelope.
95 
96  \param env A valid OGR Envelope.
97 
98  \return A valid TerraLib Envelope.
99 
100  \note The caller of this function will take the ownership of the returned TerraLib Envelope.
101  */
102  TEOGREXPORT te::gm::Envelope* Convert2TerraLib(const OGREnvelope* env);
103 
104  /*!
105  \brief It converts the TerraLib Envelope to OGR Envelope.
106 
107  \param env A valid TerraLib Envelope.
108 
109  \return A valid OGR Envelope.
110 
111  \note The caller of this function will take the ownership of the returned OGR Envelope.
112  */
113  TEOGREXPORT OGREnvelope* Convert2OGR(const te::gm::Envelope* env);
114 
115  /*!
116  \brief It converts the OGR Projection to TerraLib Projection.
117 
118  \param osrs A valid OGR Projection.
119 
120  \return An SRS id recognized by TerraLib or an indication of unknown SRS (TE_UNKNOWN_SRS)
121  */
122  TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference* osrs);
123 
124  /*!
125  \brief It converts the TerraLib Projection to OGR Projection.
126 
127  \param srid A valid TerraLib Projection id.
128 
129  \return A valid OGR Spatial Reference System.
130 
131  \exception Exception It throws an exception if the SRS can not be imported using OGR.
132 
133  \note The caller of this function will take the ownership of the returned OGR Spatial Reference System.
134  */
135  TEOGREXPORT OGRSpatialReference* Convert2OGRProjection(int srid);
136 
137  /*!
138  \brief It inserts a OGR Feature Definition to TerraLib DataSet Type
139 
140  \param featDef A valid OGR Feature Definition.
141  \param dt Pointer to a TerraLib dataset type previously created. Do not pass NULL.
142  \param srs Optional parameter to set the SRS of geometry fields.
143 
144  \exception Exception It throws an exception if the feature definition can not be converted.
145 
146  \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
147  \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
148  */
149  TEOGREXPORT void Convert2TerraLib(OGRFeatureDefn* featDef, te::da::DataSetType* dt, int srs=TE_UNKNOWN_SRS);
150 
151  /*!
152  \brief It converts the OGR Feature Definition to TerraLib DataSet Type
153 
154  \param featDef A valid OGR Feature Definition.
155  \param srs Optional parameter to set the SRS of geometry fields.
156 
157  \return A valid TerraLib DataSet Type.
158 
159  \exception Exception It throws an exception if the feature definition can not be converted.
160 
161  \note It uses the method that converts a OGR Field Definition to TerraLib Property Type.
162  \note It uses the method that converts a OGR Geometry Type to TerraLib Geometry Type.
163  \note The caller of this function will take the ownership of the returned TerraLib DataSet Type.
164  */
165  TEOGREXPORT te::da::DataSetType* Convert2TerraLib(OGRFeatureDefn* featDef, int srs=TE_UNKNOWN_SRS);
166 
167  /*!
168  \brief It converts the TerraLib DataSet Type to OGR Feature Definition
169 
170  \param dt A valid TerraLib DataSet Type.
171 
172  \return A valid OGR Feature Definition.
173 
174  \exception Exception It throws an exception if the data set type can not be converted.
175 
176  \note It uses the method that converts a TerraLib Property Type to OGR Field Definition.
177  \note The caller of this function will take the ownership of the returned OGR Feature Definition.
178  */
179  TEOGREXPORT OGRFeatureDefn* Convert2OGR(te::da::DataSetType* dt);
180 
181  /*!
182  \brief It converts the OGR Field Definition to TerraLib Property Type
183 
184  \param fieldDef A valid OGR Field Definition.
185 
186  \return A valid TerraLib Property Type.
187 
188  \exception Exception It throws an exception if the data type is not supported by TerraLib.
189 
190  \note The caller of this function will take the ownership of the returned TerraLib Property Type.
191  */
192  TEOGREXPORT te::dt::Property* Convert2TerraLib(OGRFieldDefn* fieldDef);
193 
194  /*!
195  \brief It converts the TerraLib Property Type to OGR Field Definition
196 
197  \param pt A valid TerraLib Property Type.
198 
199  \return A valid OGR Field Definition.
200 
201  \exception Exception It throws an exception if the data type is not supported by OGR.
202  */
203  TEOGREXPORT OGRFieldDefn* Convert2OGR(te::dt::Property* p);
204 
205  /*!
206  \brief It converts the OGR Geometry Type element to TerraLib Geometry Type
207 
208  \param ogrGeomType A valid OGR Geometry Type element.
209 
210  \return A valid TerraLib Geometry Type
211  */
212  TEOGREXPORT te::gm::GeomType Convert2TerraLib(OGRwkbGeometryType ogrGeomType);
213 
214  /*!
215  \brief It converts the TerraLib Geometry Type element to OGR Geometry Type
216 
217  \param geomType A valid TerraLib Geometry Type.
218 
219  \return A valid OGR Geometry Type element
220 
221  \exception Exception It throws an exception if the geometry type is not supported by OGR.
222  */
223  TEOGREXPORT OGRwkbGeometryType Convert2OGR(te::gm::GeomType geomType);
224 
225  /*!
226  \brief It tries extract the driver name used by OGR Library based on the given path.
227 
228  \param path The path that will be consulted.
229 
230  \return The driver name used by OGR Library or an empty string if not possible extract the driver name.
231  */
232  std::string GetDriverName(const std::string& path);
233 
234  /*!
235  \brief It returns the list of OGR Drivers available.
236 
237  \param filterCreate Set TRUE to indicate to retrieve only the drivers with the capacity to create datasources.
238 
239  \return A list of OGR Drivers.
240  */
241  TEOGREXPORT std::vector<std::string> GetOGRDrivers(bool filterCreate = false);
242 
243  TEOGREXPORT std::string GetOGRConnectionInfo(const std::map<std::string, std::string>& connInfo);
244 
245  TEOGREXPORT std::string RemoveSpatialSql(const std::string& sql);
246 
247  /*!
248  \brief Returns a reference to a static mutex initialized when this module is initialized.
249  \return Returns a reference to a static mutex initialized when this module is initialized.
250  */
251  TEOGREXPORT boost::mutex& getStaticMutex();
252 
253  void OGRErrorHandler(CPLErr eErrClass, int errNo, const char* msg);
254  } // end namespace ogr
255 } // end namespace te
256 
257 #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)