landr/VectorDataset.hpp
Go to the documentation of this file.
00001 /*
00002 
00003   This file is part of OpenFLUID software
00004   Copyright(c) 2007, INRA - Montpellier SupAgro
00005 
00006 
00007  == GNU General Public License Usage ==
00008 
00009   OpenFLUID is free software: you can redistribute it and/or modify
00010   it under the terms of the GNU General Public License as published by
00011   the Free Software Foundation, either version 3 of the License, or
00012   (at your option) any later version.
00013 
00014   OpenFLUID is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017   GNU General Public License for more details.
00018 
00019   You should have received a copy of the GNU General Public License
00020   along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
00021 
00022 
00023  == Other Usage ==
00024 
00025   Other Usage means a use of OpenFLUID that is inconsistent with the GPL
00026   license, and requires a written agreement between You and INRA.
00027   Licensees for Other Usage of OpenFLUID may use this file in accordance
00028   with the terms contained in the written agreement between You and INRA.
00029   
00030 */
00031 
00032 /**
00033  \file VectorDataset.hpp
00034  \brief Header of ...
00035 
00036  \author Aline LIBRES <aline.libres@gmail.com>
00037  */
00038 
00039 #ifndef VECTORDATASET_HPP_
00040 #define VECTORDATASET_HPP_
00041 
00042 #include <string>
00043 #include <map>
00044 #include <list>
00045 #include <ogrsf_frmts.h>
00046 #include <openfluid/dllexport.hpp>
00047 
00048 
00049 namespace geos {
00050 namespace geom {
00051 class Geometry;
00052 }
00053 }
00054 
00055 namespace openfluid {
00056 
00057 namespace core {
00058 class GeoVectorValue;
00059 }
00060 
00061 namespace landr {
00062 /**
00063  * @brief Interface for managing Vector Data format.
00064  *
00065  */
00066 
00067 class DLLEXPORT VectorDataset
00068 {
00069   public:
00070 
00071     /**
00072      * @brief A list of pair of OGRFeature and geos::geom::Geometry related to this VectorDataset entities.
00073      */
00074     typedef std::list<std::pair<OGRFeature*, geos::geom::Geometry*> > FeaturesList_t;
00075 
00076   private:
00077 
00078     /**
00079      * @brief The OGRDataSource related to this VectorDataset.
00080      */
00081     OGRDataSource* mp_DataSource;
00082 
00083     /**
00084      * @brief A list of all features of layers of this VectorDataset, indexed by layer index.
00085      */
00086     std::map<unsigned int, FeaturesList_t> m_Features;
00087 
00088     /**
00089      * @brief A map of geos::geom::Geometry representing a collection of all the geometries of the layers of this VectorDataset, indexed by layer index.
00090      */
00091     std::map<unsigned int, geos::geom::Geometry*> m_Geometries;
00092 
00093     /**
00094      * @brief Returns the path of this VectorDataset associated with time.
00095      */
00096     std::string getTimestampedPath(const std::string& OriginalFileName);
00097 
00098     /**
00099      * @brief Returns the path of this VectorDataset.
00100      */
00101     std::string getInitializedTmpPath();
00102 
00103     /**
00104      * @brief Returns true if this VectorDataset exists.
00105      * @param Path The pathname to this VectorDataset.
00106      * @return True if already exists, false otherwise.
00107      */
00108     bool isAlreadyExisting(const std::string& Path);
00109 
00110     /**
00111      * @brief Parse the geometry of this VectorDataset.
00112      * @param LayerIndex The index layer.
00113      */
00114     void parse(unsigned int LayerIndex);
00115 
00116   public:
00117 
00118     /**
00119      * @brief Creates a new empty OGRDatasource in the openfluid temp directory, with filename suffixes with timestamp.
00120      * @param FileName The name of the file to create.
00121      * @throw openfluid::base::OFException if fails.
00122      */
00123     VectorDataset(const std::string& FileName);
00124 
00125     /**
00126      * @brief Creates in the openfluid temp directory a copy of Value OGRDatasource,
00127      * using Value filename suffixed with timestamp as filename.
00128      * @param Value The GeoVectorValue to copy
00129      * @throw openfluid::base::OFException if fails.
00130      */
00131     VectorDataset(openfluid::core::GeoVectorValue& Value);
00132 
00133     /**
00134      * @brief Copy constructor.
00135      * @throw openfluid::base::OFException if fails.
00136      */
00137     VectorDataset(const VectorDataset& Other);
00138 
00139     /**
00140      * @brief Delete the OGRDatasource and relative files in openfluid temp directory.
00141      */
00142     ~VectorDataset();
00143 
00144     /**
00145      * @brief Returns the OGRDataSource associated to this VectorDataset.
00146      */
00147     OGRDataSource* getDataSource();
00148 
00149     /**
00150      * @brief Returns the const OGRDataSource associated to this VectorDataset.
00151      */
00152     OGRDataSource* getDataSource() const;
00153 
00154     /**
00155      * @brief Write to disk a copy of the OGRDataSource.
00156      * @param FilePath The path to the directory where writing, will be created if needed.
00157      * @param FileName The name of the file to write.
00158      * @param ReplaceIfExists If true and the file FilePath/FileName already exists, overwrite it.
00159      */
00160     void copyToDisk(const std::string& FilePath, const std::string& FileName,
00161                     bool ReplaceIfExists);
00162 
00163     /**
00164      * @brief Add to DataSource an empty new layer.
00165      *
00166      * @param LayerName The name of the layer to create.
00167      * @param LayerType The type of the layer to create, default wkbUnknown.
00168      * @param SpatialRef The coordinate system to use for the new layer, or NULL (default) if no coordinate system is available.
00169      * @throw openfluid::base::OFException if the creation of layer failed.
00170      */
00171     void addALayer(std::string LayerName = "", OGRwkbGeometryType LayerType =
00172         wkbUnknown,
00173                    OGRSpatialReference* SpatialRef = NULL);
00174 
00175     /**
00176      * @brief Get a layer of the shape.
00177      *
00178      * @param LayerIndex The index of the asked layer, default 0.
00179      * @return The layer indexed LayerIndex.
00180      */
00181     OGRLayer* getLayer(unsigned int LayerIndex = 0);
00182 
00183     /**
00184      * @brief Get the Feature definition of a layer.
00185      *
00186      * @param LayerIndex The index of the asked layer definition, default 0.
00187      * @return The OGR Feature definition of the LayerIndex layer.
00188      */
00189     OGRFeatureDefn* getLayerDef(unsigned int LayerIndex = 0);
00190 
00191     /**
00192      * @brief Add a field to a layer.
00193      *
00194      * @param FieldName The name of the field to add.
00195      * @param FieldType The type of the field to add (default OFTString).
00196      * @param LayerIndex The index of the layer to add the field, default 0.
00197      * @throw openfluid::base::OFException if creating field failed.
00198      */
00199     void addAField(const std::string& FieldName, OGRFieldType FieldType = OFTString,
00200                    unsigned int LayerIndex = 0);
00201 
00202     /**
00203      * @brief Returns true if the VectorDataset is line type.
00204      * @param LayerIndex The index of the layer to compare the type, default 0.
00205      * @return True if the type of the layer LayerIndex is wkbLineString, false otherwise.
00206      */
00207     bool isLineType(unsigned int LayerIndex = 0);
00208 
00209     /**
00210      * @brief Returns true if the VectorDataset is polygon type.
00211      * @param LayerIndex The index of the layer to compare the type, default 0.
00212      * @return True if the type of the layer LayerIndex is wkbPolygon, false otherwise.
00213      */
00214     bool isPolygonType(unsigned int LayerIndex = 0);
00215 
00216     /**
00217      * @brief Returns true if a field exists in the LayerIndex layer.
00218      *
00219      * @param FieldName The name of the field to query.
00220      * @param LayerIndex The index of the layer to query, default 0.
00221      * @return True if the field FieldName exists, False otherwise.
00222      */
00223     bool containsField(const std::string& FieldName, unsigned int LayerIndex = 0);
00224 
00225     /**
00226      * @brief Get the index of a field in the LayerIndex layer.
00227      *
00228      * @param LayerIndex The index of the layer to query, default 0.
00229      * @param FieldName The name of the field to query.
00230      * @return The index of FieldName or -1 if field FieldName doesn't exist.
00231      */
00232     int getFieldIndex(const std::string& FieldName, unsigned int LayerIndex = 0);
00233 
00234     /**
00235      * @brief Returns true if a field is of the type FieldType in the LayerIndex layer.
00236      *
00237      * @param FieldName The name of the field to query.
00238      * @param FieldType The type of the field to query.
00239      * @param LayerIndex The index of the layer to query, default 0.
00240      * @return True if the field FieldName is type FieldType.
00241      * @throw openfluid::base::OFException if the field doesn't exist.
00242      */
00243     bool isFieldOfType(const std::string& FieldName, OGRFieldType FieldType,
00244                        unsigned int LayerIndex = 0);
00245 
00246     /**
00247      * @brief Returns true if a field has the value Value in the LayerIndex layer.
00248      *
00249      * @param FieldName The name of the field to query.
00250      * @param Value The value to query.
00251      * @param LayerIndex The index of the layer to query, default 0.
00252      * @return True if the field has at least a feature containing the value Value, False otherwise.
00253      */
00254     bool isIntValueSet(const std::string& FieldName, int Value,
00255                        unsigned int LayerIndex = 0);
00256 
00257     /**
00258      * @brief Gets the list of all features of a layer of this GeoVectorValue.
00259      *
00260      * @param LayerIndex The index of the layer to query, default 0.
00261      * @return A list of OGRFeature and geos::geom::Geometry of this VectorDataset.
00262      */
00263     FeaturesList_t getFeatures(unsigned int LayerIndex = 0);
00264 
00265     /**
00266      *@brief Gets a geos::geom::Geometry representing a collection of all the geometries of the layer LayerIndex of this GeoVectorValue.
00267      *
00268      * @param LayerIndex The index of the layer to query, default 0.
00269      * @return A geos::geom::Geometry.
00270      */
00271     geos::geom::Geometry* getGeometries(unsigned int LayerIndex = 0);
00272 
00273 };
00274 
00275 }
00276 } // namespaces
00277 
00278 #endif /* VECTORDATASET_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines