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