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 
35  @author Aline LIBRES <libres@supagro.inra.fr>
36  @author Jean-Christophe Fabre <jean-christophe.fabre@supagro.inra.fr>
37  */
38 
39 #ifndef __OPENFLUID_CORE_GEOVECTORVALUE_HPP__
40 #define __OPENFLUID_CORE_GEOVECTORVALUE_HPP__
41 
43 #include <openfluid/dllexport.hpp>
44 
45 #include <ogrsf_frmts.h>
46 
47 namespace openfluid { namespace core {
48 
49 /**
50  Container class for geospatial vector data, represented by an OGR datasource.
51 */
53 {
54  protected:
55 
56  /**
57  The OGRDataSource associated to this GeoVectorValue.
58  */
59  OGRDataSource* mp_Data;
60 
61  /**
62  Open the OGRDataSource of this GeoVectorValue.
63  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
64  */
65  void tryToOpenSource();
66 
67  /**
68  Destroy the OGRDataSource.
69  */
70  void destroyDataSource();
71 
72 
73  public:
74 
75  /**
76  Creates a new value.
77  For ESRI Shapefile, the <tt>FileName</tt> may be the name of a .shp, .shx or .dbf file,
78  or a path to a directory containing proper shape files.
79  It doesn't open the associated OGR datasource.
80  @param[in] FilePath The path of the file(s).
81  @param[in] FileName The name or the relative path of the file to open.
82  */
83  GeoVectorValue(const std::string& FilePath, const std::string& FileName);
84 
85  /**
86  Destructor. Closes the open OGR datasource.
87  */
88  ~GeoVectorValue();
89 
90  /**
91  Returns the type of this GeoVectorValue.
92  */
94 
95  /**
96  Gets the associated opened OGR datasource in read-only access.
97  If the datasource is not already opened, tries to open it first.
98  @return The opened OGR datasource.
99  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
100  */
101  OGRDataSource* data();
102 
103  /**
104  Gets a layer of the shape.
105  @param[in] LayerIndex The index of the asked layer, default 0.
106  @return The layer indexed LayerIndex.
107  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
108  */
109  OGRLayer* layer(unsigned int LayerIndex = 0);
110 
111  /**
112  Gets the Feature definition of a layer.
113  @param[in] LayerIndex The index of the asked layer definition, default 0.
114  @return The OGR Feature definition of the LayerIndex layer.
115  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
116  */
117  OGRFeatureDefn* layerDef(unsigned int LayerIndex = 0);
118 
119  /**
120  Returns true if the GeoVectorValue is line type, false otherwise.
121  @param[in] LayerIndex The index of the layer to compare the type, default 0.
122  @return True if the type of the layer LayerIndex is wkbLineString, false otherwise.
123  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
124  */
125  bool isLineType(unsigned int LayerIndex = 0);
126 
127  /**
128  Returns true if the GeoVectorValue is polygon type, false otherwise.
129  @param[in] LayerIndex The index of the layer to compare the type, default 0.
130  @return True if the type of the layer LayerIndex is wkbPolygon, false otherwise.
131  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
132  */
133  bool isPolygonType(unsigned int LayerIndex = 0);
134 
135  /**
136  Returns true if a field exists in the LayerIndex layer.
137  @param[in] FieldName The name of the field to query.
138  @param[in] LayerIndex The index of the layer to query, default 0.
139  @return True if the field FieldName exists, False otherwise.
140  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
141  */
142  bool containsField(const std::string& FieldName, unsigned int LayerIndex = 0);
143 
144  /**
145  Gets the index of a field in the LayerIndex layer.
146  @param[in] LayerIndex The index of the layer to query, default 0.
147  @param[in] FieldName The name of the field to query.
148  @return The index of FieldName or -1 if field FieldName doesn't exist.
149  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
150  */
151  int getFieldIndex(const std::string& FieldName, unsigned int LayerIndex = 0);
152 
153  /**
154  Returns true if a field is of the type FieldType in the LayerIndex layer.
155  @param[in] FieldName The name of the field to query.
156  @param[in] FieldType The type of the field to query.
157  @param[in] LayerIndex The index of the layer to query, default 0.
158  @return True if the field FieldName is type FieldType.
159  @throw openfluid::base::FrameworkException if the field doesn't exist.
160  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
161  */
162  bool isFieldOfType(const std::string& FieldName, OGRFieldType FieldType,
163  unsigned int LayerIndex = 0);
164 
165  /**
166  Returns true if the GeoVectorValue is point type, false otherwise.
167  @param[in] LayerIndex The index of the layer to compare the type, default 0.
168  @return True if the type of the layer LayerIndex is wkbPoint, false otherwise.
169  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
170  */
171  bool isPointType(unsigned int LayerIndex = 0);
172 
173  /**
174  Returns true if the GeoVectorValue is MultiPolygon type, false otherwise.
175  @param[in] LayerIndex The index of the layer to compare the type, default 0.
176  @return True if the type of the layer LayerIndex is wkbMultiPolygon, false otherwise.
177  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
178  */
179  bool isMultiPolygonType(unsigned int LayerIndex = 0);
180 
181  /**
182  Returns true if the GeoVectorValue is MultiLine type, false otherwise.
183  @param[in] LayerIndex The index of the layer to compare the type, default 0.
184  @return True if the type of the layer LayerIndex is wkbMultiLineString, false otherwise.
185  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
186  */
187  bool isMultiLineType(unsigned int LayerIndex = 0);
188 
189  /**
190  Returns true if the GeoVectorValue is MultiPoint type, false otherwise.
191  @param[in] LayerIndex The index of the layer to compare the type, default 0.
192  @return True if the type of the layer LayerIndex is wkbMultiPoint, false otherwise.
193  @throw openfluid::base::FrameworkException if OGR doesn't succeed to open the datasource.
194  */
195  bool isMultiPointType(unsigned int LayerIndex = 0);
196 
197 
198 
199 
200 };
201 
202 } } // namespaces
203 
204 
205 #endif /* __OPENFLUID_CORE_GEOVECTORVALUE_HPP__ */
UnstructuredType
Definition: UnstructuredValue.hpp:53
Definition: GeoVectorValue.hpp:52
Definition: GeoValue.hpp:52
OGRDataSource * mp_Data
Definition: GeoVectorValue.hpp:59
#define OPENFLUID_API
Definition: dllexport.hpp:87