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