All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GeoVectorValue.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 /**
33  \file GeoVectorValue.hpp
34  \brief Header of ...
35 
36  \author Aline LIBRES <libres@supagro.inra.fr>
37  */
38 
39 #ifndef __GEOVECTORVALUE_HPP__
40 #define __GEOVECTORVALUE_HPP__
41 
43 #include <openfluid/dllexport.hpp>
44 
45 #include <ogrsf_frmts.h>
46 
47 namespace openfluid {
48 namespace core {
49 
50 /**
51  * @brief Container class for geospatial vector data,
52  * represented by an OGR datasource.
53  */
55 {
56  protected:
57 
58  /**
59  * @brief The OGRDataSource associated to this GeoVectorValue.
60  */
61  OGRDataSource* mp_Data;
62 
63  /**
64  * @brief Open the OGRDataSource of this GeoVectorValue.
65  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
66  *
67  */
68  void tryToOpenSource();
69 
70  /**
71  * @brief Destroy the OGRDataSource.
72  */
73  void destroyDataSource();
74 
75  public:
76 
77  /**
78  * @brief Creates a new value.
79  *
80  * For ESRI Shapefile, the <tt>FileName</tt> may be the name of a .shp, .shx or .dbf file,
81  * or a path to a directory containing proper shape files.
82  *
83  * It doesn't open the associated OGR datasource.
84  *
85  * @param FilePath The path of the file(s).
86  * @param FileName The name or the relative path of the file to open.
87  */
88  GeoVectorValue(std::string FilePath, std::string FileName);
89 
90  /**
91  * @brief Closes the opened OGR datasource.
92  */
93  ~GeoVectorValue();
94 
95  /**
96  * @brief Returns the type of this GeoVectorValue.
97  */
99 
100  /**
101  * @brief Gets the associated opened OGR datasource in read-only access.
102  *
103  * If the datasource is not already opened, tries to open it first.
104  *
105  * @return The opened OGR datasource.
106  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
107  */
108  OGRDataSource* get();
109 
110  /**
111  * @brief Gets a layer of the shape.
112  *
113  * @param LayerIndex The index of the asked layer, default 0.
114  * @return The layer indexed LayerIndex.
115  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
116  */
117  OGRLayer* getLayer(unsigned int LayerIndex = 0);
118 
119  /**
120  * @brief Gets the Feature definition of a layer.
121  *
122  * @param LayerIndex The index of the asked layer definition, default 0.
123  * @return The OGR Feature definition of the LayerIndex layer.
124  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
125  */
126  OGRFeatureDefn* getLayerDef(unsigned int LayerIndex = 0);
127 
128  /**
129  * @brief Returns true if the GeoVectorValue is line type, false otherwise.
130  * @param LayerIndex The index of the layer to compare the type, default 0.
131  * @return True if the type of the layer LayerIndex is wkbLineString, false otherwise.
132  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
133  */
134  bool isLineType(unsigned int LayerIndex = 0);
135 
136  /**
137  * @brief Returns true if the GeoVectorValue is polygon type, false otherwise.
138  * @param LayerIndex The index of the layer to compare the type, default 0.
139  * @return True if the type of the layer LayerIndex is wkbPolygon, false otherwise.
140  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
141  */
142  bool isPolygonType(unsigned int LayerIndex = 0);
143 
144  /**
145  * @brief Returns true if a field exists in the LayerIndex layer.
146  *
147  * @param FieldName The name of the field to query.
148  * @param LayerIndex The index of the layer to query, default 0.
149  * @return True if the field FieldName exists, False otherwise.
150  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
151  */
152  bool containsField(std::string FieldName, unsigned int LayerIndex = 0);
153 
154  /**
155  * @brief Gets the index of a field in the LayerIndex layer.
156  *
157  * @param LayerIndex The index of the layer to query, default 0.
158  * @param FieldName The name of the field to query.
159  * @return The index of FieldName or -1 if field FieldName doesn't exist.
160  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
161  */
162  int getFieldIndex(std::string FieldName, unsigned int LayerIndex = 0);
163 
164  /**
165  * @brief Returns true if a field is of the type FieldType in the LayerIndex layer.
166  *
167  * @param FieldName The name of the field to query.
168  * @param FieldType The type of the field to query.
169  * @param LayerIndex The index of the layer to query, default 0.
170  * @return True if the field FieldName is type FieldType.
171  * @throw openfluid::base::OFException if the field doesn't exist.
172  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
173  */
174  bool isFieldOfType(std::string FieldName, OGRFieldType FieldType,
175  unsigned int LayerIndex = 0);
176 
177  /**
178  * @brief Returns true if the GeoVectorValue is point type, false otherwise.
179  * @param LayerIndex The index of the layer to compare the type, default 0.
180  * @return True if the type of the layer LayerIndex is wkbPoint, false otherwise.
181  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
182  */
183  bool isPointType(unsigned int LayerIndex = 0);
184 
185  /**
186  * @brief Returns true if the GeoVectorValue is MultiPolygon type, false otherwise.
187  * @param LayerIndex The index of the layer to compare the type, default 0.
188  * @return True if the type of the layer LayerIndex is wkbMultiPolygon, false otherwise.
189  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
190  */
191  bool isMultiPolygonType(unsigned int LayerIndex = 0);
192 
193  /**
194  * @brief Returns true if the GeoVectorValue is MultiLine type, false otherwise.
195  * @param LayerIndex The index of the layer to compare the type, default 0.
196  * @return True if the type of the layer LayerIndex is wkbMultiLineString, false otherwise.
197  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
198  */
199  bool isMultiLineType(unsigned int LayerIndex = 0);
200 
201  /**
202  * @brief Returns true if the GeoVectorValue is MultiPoint type, false otherwise.
203  * @param LayerIndex The index of the layer to compare the type, default 0.
204  * @return True if the type of the layer LayerIndex is wkbMultiPoint, false otherwise.
205  * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource.
206  */
207  bool isMultiPointType(unsigned int LayerIndex = 0);
208 
209 
210 
211 
212 };
213 
214 }
215 } // namespaces
216 
217 #endif /* __GEOVECTORVALUE_HPP__ */
Abstract class for geospatial data.
Definition: GeoValue.hpp:51
Header of ...
OGRDataSource * mp_Data
The OGRDataSource associated to this GeoVectorValue.
Definition: GeoVectorValue.hpp:61
UnstructuredType
Definition: UnstructuredValue.hpp:53
Container class for geospatial vector data, represented by an OGR datasource.
Definition: GeoVectorValue.hpp:54
#define DLLEXPORT
Definition: dllexport.hpp:51