All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VectorDataset.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 VectorDataset.hpp
34  \brief Header of ...
35 
36  \author Aline LIBRES <aline.libres@gmail.com>
37  */
38 
39 #ifndef VECTORDATASET_HPP_
40 #define VECTORDATASET_HPP_
41 
42 #include <string>
43 #include <map>
44 #include <list>
45 #include <ogrsf_frmts.h>
46 #include <openfluid/dllexport.hpp>
47 
48 
49 namespace geos { namespace geom {
50 class Geometry;
51 } }
52 
53 namespace openfluid {
54 
55 namespace core {
56 class GeoVectorValue;
57 }
58 
59 namespace landr {
60 /**
61  @brief Interface for managing Vector Data format.
62  *
63  */
64 
66 {
67  public:
68 
69  /**
70  @brief A list of pair of OGRFeature and geos::geom::Geometry related to this VectorDataset entities.
71  */
72  typedef std::list<std::pair<OGRFeature*, geos::geom::Geometry*> > FeaturesList_t;
73 
74  private:
75 
76  /**
77  @brief The OGRDataSource related to this VectorDataset.
78  */
79  OGRDataSource* mp_DataSource;
80 
81  /**
82  @brief A list of all features of layers of this VectorDataset, indexed by layer index.
83  */
84  std::map<unsigned int, FeaturesList_t> m_Features;
85 
86  /**
87  @brief A map of geos::geom::Geometry representing a collection of all the geometries of the layers of this VectorDataset, indexed by layer index.
88  */
89  std::map<unsigned int, geos::geom::Geometry*> m_Geometries;
90 
91  /**
92  @brief Returns the path of this VectorDataset associated with time.
93  */
94  std::string getTimestampedPath(const std::string& OriginalFileName);
95 
96  /**
97  @brief Returns the path of this VectorDataset.
98  */
99  std::string getInitializedTmpPath();
100 
101  /**
102  @brief Returns true if this VectorDataset exists.
103  @param Path The pathname to this VectorDataset.
104  @return True if already exists, false otherwise.
105  */
106  bool isAlreadyExisting(const std::string& Path);
107 
108  /**
109  @brief Parse the geometry of this VectorDataset.
110  @param LayerIndex The index layer.
111  */
112  void parse(unsigned int LayerIndex);
113 
114  public:
115 
116  /**
117  @brief Creates a new empty OGRDatasource in the openfluid temp directory, with filename suffixes with timestamp.
118  @param FileName The name of the file to create.
119  @throw openfluid::base::OFException if fails.
120  */
121  VectorDataset(const std::string& FileName);
122 
123  /**
124  @brief Creates in the openfluid temp directory a copy of Value OGRDatasource,
125  using Value filename suffixed with timestamp as filename.
126  @param Value The GeoVectorValue to copy
127  @throw openfluid::base::OFException if fails.
128  */
130 
131  /**
132  @brief Copy constructor.
133  @throw openfluid::base::OFException if fails.
134  */
135  VectorDataset(const VectorDataset& Other);
136 
137  /**
138  @brief Delete the OGRDatasource and relative files in openfluid temp directory.
139  */
140  ~VectorDataset();
141 
142  /**
143  @brief Returns the OGRDataSource associated to this VectorDataset.
144  */
145  OGRDataSource* getDataSource();
146 
147  /**
148  @brief Returns the const OGRDataSource associated to this VectorDataset.
149  */
150  OGRDataSource* getDataSource() const;
151 
152  /**
153  @brief Write to disk a copy of the OGRDataSource.
154  @param FilePath The path to the directory where writing, will be created if needed.
155  @param FileName The name of the file to write.
156  @param ReplaceIfExists If true and the file FilePath/FileName already exists, overwrite it.
157  */
158  void copyToDisk(const std::string& FilePath,
159  const std::string& FileName,
160  bool ReplaceIfExists);
161 
162  /**
163  @brief Add to DataSource an empty new layer.
164  *
165  @param LayerName The name of the layer to create.
166  @param LayerType The type of the layer to create, default wkbUnknown.
167  @param SpatialRef The coordinate system to use for the new layer, or NULL (default) if no coordinate system is available.
168  @throw openfluid::base::OFException if the creation of layer failed.
169  */
170  void addALayer(std::string LayerName = "",
171  OGRwkbGeometryType LayerType = wkbUnknown,
172  OGRSpatialReference* SpatialRef = NULL);
173 
174  /**
175  @brief Get a layer of the shape.
176  @param LayerIndex The index of the asked layer, default 0.
177  @return The layer indexed LayerIndex.
178  */
179  OGRLayer* getLayer(unsigned int LayerIndex = 0);
180 
181  /**
182  @brief Get the Feature definition of a layer.
183  @param LayerIndex The index of the asked layer definition, default 0.
184  @return The OGR Feature definition of the LayerIndex layer.
185  */
186  OGRFeatureDefn* getLayerDef(unsigned int LayerIndex = 0);
187 
188  /**
189  @brief Add a field to a layer.
190  @param FieldName The name of the field to add.
191  @param FieldType The type of the field to add (default OFTString).
192  @param LayerIndex The index of the layer to add the field, default 0.
193  @throw openfluid::base::OFException if creating field failed.
194  */
195  void addAField(const std::string& FieldName,
196  OGRFieldType FieldType = OFTString,
197  unsigned int LayerIndex = 0);
198 
199  /**
200  @brief Returns true if the VectorDataset is line type.
201  @param LayerIndex The index of the layer to compare the type, default 0.
202  @return True if the type of the layer LayerIndex is wkbLineString, false otherwise.
203  */
204  bool isLineType(unsigned int LayerIndex = 0);
205 
206  /**
207  @brief Returns true if the VectorDataset is polygon type.
208  @param LayerIndex The index of the layer to compare the type, default 0.
209  @return True if the type of the layer LayerIndex is wkbPolygon, false otherwise.
210  */
211  bool isPolygonType(unsigned int LayerIndex = 0);
212 
213  /**
214  @brief Returns true if a field exists in the LayerIndex layer.
215  @param FieldName The name of the field to query.
216  @param LayerIndex The index of the layer to query, default 0.
217  @return True if the field FieldName exists, False otherwise.
218  */
219  bool containsField(const std::string& FieldName,
220  unsigned int LayerIndex = 0);
221 
222  /**
223  @brief Get the index of a field in the LayerIndex layer.
224  @param LayerIndex The index of the layer to query, default 0.
225  @param FieldName The name of the field to query.
226  @return The index of FieldName or -1 if field FieldName doesn't exist.
227  */
228  int getFieldIndex(const std::string& FieldName,
229  unsigned int LayerIndex = 0);
230 
231  /**
232  @brief Returns true if a field is of the type FieldType in the LayerIndex layer.
233  @param FieldName The name of the field to query.
234  @param FieldType The type of the field to query.
235  @param LayerIndex The index of the layer to query, default 0.
236  @return True if the field FieldName is type FieldType.
237  @throw openfluid::base::OFException if the field doesn't exist.
238  */
239  bool isFieldOfType(const std::string& FieldName,
240  OGRFieldType FieldType,
241  unsigned int LayerIndex = 0);
242 
243  /**
244  @brief Returns true if a field has the value Value in the LayerIndex layer.
245  @param FieldName The name of the field to query.
246  @param Value The value to query.
247  @param LayerIndex The index of the layer to query, default 0.
248  @return True if the field has at least a feature containing the value Value, False otherwise.
249  */
250  bool isIntValueSet(const std::string& FieldName,
251  int Value,
252  unsigned int LayerIndex = 0);
253 
254  /**
255  @brief Gets the list of all features of a layer of this GeoVectorValue.
256  @param LayerIndex The index of the layer to query, default 0.
257  @return A list of OGRFeature and geos::geom::Geometry of this VectorDataset.
258  */
259  FeaturesList_t getFeatures(unsigned int LayerIndex = 0);
260 
261  /**
262  @brief Gets a geos::geom::Geometry representing a collection of all the geometries of the layer LayerIndex of this GeoVectorValue.
263  @param LayerIndex The index of the layer to query, default 0.
264  @return A geos::geom::Geometry.
265  */
266  geos::geom::Geometry* getGeometries(unsigned int LayerIndex = 0);
267 
268  /**
269  @brief Returns true if the VectorDataset is point type.
270  @param LayerIndex The index of the layer to compare the type, default 0.
271  @return True if the type of the layer LayerIndex is wkbPoint, false otherwise.
272  */
273  bool isPointType(unsigned int LayerIndex = 0);
274 
275 
276 
277 };
278 
279 } } // namespaces openfluid, landr
280 
281 
282 #endif /* VECTORDATASET_HPP_ */
Interface for managing Vector Data format.
Definition: VectorDataset.hpp:65
std::list< std::pair< OGRFeature *, geos::geom::Geometry * > > FeaturesList_t
A list of pair of OGRFeature and geos::geom::Geometry related to this VectorDataset entities...
Definition: VectorDataset.hpp:72
Container class for geospatial vector data, represented by an OGR datasource.
Definition: GeoVectorValue.hpp:54
#define DLLEXPORT
Definition: dllexport.hpp:51