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 { namespace geom { 00050 class Geometry; 00051 } } 00052 00053 namespace openfluid { 00054 00055 namespace core { 00056 class GeoVectorValue; 00057 } 00058 00059 namespace landr { 00060 /** 00061 @brief Interface for managing Vector Data format. 00062 * 00063 */ 00064 00065 class DLLEXPORT VectorDataset 00066 { 00067 public: 00068 00069 /** 00070 @brief A list of pair of OGRFeature and geos::geom::Geometry related to this VectorDataset entities. 00071 */ 00072 typedef std::list<std::pair<OGRFeature*, geos::geom::Geometry*> > FeaturesList_t; 00073 00074 private: 00075 00076 /** 00077 @brief The OGRDataSource related to this VectorDataset. 00078 */ 00079 OGRDataSource* mp_DataSource; 00080 00081 /** 00082 @brief A list of all features of layers of this VectorDataset, indexed by layer index. 00083 */ 00084 std::map<unsigned int, FeaturesList_t> m_Features; 00085 00086 /** 00087 @brief A map of geos::geom::Geometry representing a collection of all the geometries of the layers of this VectorDataset, indexed by layer index. 00088 */ 00089 std::map<unsigned int, geos::geom::Geometry*> m_Geometries; 00090 00091 /** 00092 @brief Returns the path of this VectorDataset associated with time. 00093 */ 00094 std::string getTimestampedPath(const std::string& OriginalFileName); 00095 00096 /** 00097 @brief Returns the path of this VectorDataset. 00098 */ 00099 std::string getInitializedTmpPath(); 00100 00101 /** 00102 @brief Returns true if this VectorDataset exists. 00103 @param Path The pathname to this VectorDataset. 00104 @return True if already exists, false otherwise. 00105 */ 00106 bool isAlreadyExisting(const std::string& Path); 00107 00108 /** 00109 @brief Parse the geometry of this VectorDataset. 00110 @param LayerIndex The index layer. 00111 */ 00112 void parse(unsigned int LayerIndex); 00113 00114 public: 00115 00116 /** 00117 @brief Creates a new empty OGRDatasource in the openfluid temp directory, with filename suffixes with timestamp. 00118 @param FileName The name of the file to create. 00119 @throw openfluid::base::OFException if fails. 00120 */ 00121 VectorDataset(const std::string& FileName); 00122 00123 /** 00124 @brief Creates in the openfluid temp directory a copy of Value OGRDatasource, 00125 using Value filename suffixed with timestamp as filename. 00126 @param Value The GeoVectorValue to copy 00127 @throw openfluid::base::OFException if fails. 00128 */ 00129 VectorDataset(openfluid::core::GeoVectorValue& Value); 00130 00131 /** 00132 @brief Copy constructor. 00133 @throw openfluid::base::OFException if fails. 00134 */ 00135 VectorDataset(const VectorDataset& Other); 00136 00137 /** 00138 @brief Delete the OGRDatasource and relative files in openfluid temp directory. 00139 */ 00140 ~VectorDataset(); 00141 00142 /** 00143 @brief Returns the OGRDataSource associated to this VectorDataset. 00144 */ 00145 OGRDataSource* getDataSource(); 00146 00147 /** 00148 @brief Returns the const OGRDataSource associated to this VectorDataset. 00149 */ 00150 OGRDataSource* getDataSource() const; 00151 00152 /** 00153 @brief Write to disk a copy of the OGRDataSource. 00154 @param FilePath The path to the directory where writing, will be created if needed. 00155 @param FileName The name of the file to write. 00156 @param ReplaceIfExists If true and the file FilePath/FileName already exists, overwrite it. 00157 */ 00158 void copyToDisk(const std::string& FilePath, 00159 const std::string& FileName, 00160 bool ReplaceIfExists); 00161 00162 /** 00163 @brief Add to DataSource an empty new layer. 00164 * 00165 @param LayerName The name of the layer to create. 00166 @param LayerType The type of the layer to create, default wkbUnknown. 00167 @param SpatialRef The coordinate system to use for the new layer, or NULL (default) if no coordinate system is available. 00168 @throw openfluid::base::OFException if the creation of layer failed. 00169 */ 00170 void addALayer(std::string LayerName = "", 00171 OGRwkbGeometryType LayerType = wkbUnknown, 00172 OGRSpatialReference* SpatialRef = NULL); 00173 00174 /** 00175 @brief Get a layer of the shape. 00176 @param LayerIndex The index of the asked layer, default 0. 00177 @return The layer indexed LayerIndex. 00178 */ 00179 OGRLayer* getLayer(unsigned int LayerIndex = 0); 00180 00181 /** 00182 @brief Get the Feature definition of a layer. 00183 @param LayerIndex The index of the asked layer definition, default 0. 00184 @return The OGR Feature definition of the LayerIndex layer. 00185 */ 00186 OGRFeatureDefn* getLayerDef(unsigned int LayerIndex = 0); 00187 00188 /** 00189 @brief Add a field to a layer. 00190 @param FieldName The name of the field to add. 00191 @param FieldType The type of the field to add (default OFTString). 00192 @param LayerIndex The index of the layer to add the field, default 0. 00193 @throw openfluid::base::OFException if creating field failed. 00194 */ 00195 void addAField(const std::string& FieldName, 00196 OGRFieldType FieldType = OFTString, 00197 unsigned int LayerIndex = 0); 00198 00199 /** 00200 @brief Returns true if the VectorDataset is line type. 00201 @param LayerIndex The index of the layer to compare the type, default 0. 00202 @return True if the type of the layer LayerIndex is wkbLineString, false otherwise. 00203 */ 00204 bool isLineType(unsigned int LayerIndex = 0); 00205 00206 /** 00207 @brief Returns true if the VectorDataset is polygon type. 00208 @param LayerIndex The index of the layer to compare the type, default 0. 00209 @return True if the type of the layer LayerIndex is wkbPolygon, false otherwise. 00210 */ 00211 bool isPolygonType(unsigned int LayerIndex = 0); 00212 00213 /** 00214 @brief Returns true if a field exists in the LayerIndex layer. 00215 @param FieldName The name of the field to query. 00216 @param LayerIndex The index of the layer to query, default 0. 00217 @return True if the field FieldName exists, False otherwise. 00218 */ 00219 bool containsField(const std::string& FieldName, 00220 unsigned int LayerIndex = 0); 00221 00222 /** 00223 @brief Get the index of a field in the LayerIndex layer. 00224 @param LayerIndex The index of the layer to query, default 0. 00225 @param FieldName The name of the field to query. 00226 @return The index of FieldName or -1 if field FieldName doesn't exist. 00227 */ 00228 int getFieldIndex(const std::string& FieldName, 00229 unsigned int LayerIndex = 0); 00230 00231 /** 00232 @brief Returns true if a field is of the type FieldType in the LayerIndex layer. 00233 @param FieldName The name of the field to query. 00234 @param FieldType The type of the field to query. 00235 @param LayerIndex The index of the layer to query, default 0. 00236 @return True if the field FieldName is type FieldType. 00237 @throw openfluid::base::OFException if the field doesn't exist. 00238 */ 00239 bool isFieldOfType(const std::string& FieldName, 00240 OGRFieldType FieldType, 00241 unsigned int LayerIndex = 0); 00242 00243 /** 00244 @brief Returns true if a field has the value Value in the LayerIndex layer. 00245 @param FieldName The name of the field to query. 00246 @param Value The value to query. 00247 @param LayerIndex The index of the layer to query, default 0. 00248 @return True if the field has at least a feature containing the value Value, False otherwise. 00249 */ 00250 bool isIntValueSet(const std::string& FieldName, 00251 int Value, 00252 unsigned int LayerIndex = 0); 00253 00254 /** 00255 @brief Gets the list of all features of a layer of this GeoVectorValue. 00256 @param LayerIndex The index of the layer to query, default 0. 00257 @return A list of OGRFeature and geos::geom::Geometry of this VectorDataset. 00258 */ 00259 FeaturesList_t getFeatures(unsigned int LayerIndex = 0); 00260 00261 /** 00262 @brief Gets a geos::geom::Geometry representing a collection of all the geometries of the layer LayerIndex of this GeoVectorValue. 00263 @param LayerIndex The index of the layer to query, default 0. 00264 @return A geos::geom::Geometry. 00265 */ 00266 geos::geom::Geometry* getGeometries(unsigned int LayerIndex = 0); 00267 00268 /** 00269 @brief Returns true if the VectorDataset is point type. 00270 @param LayerIndex The index of the layer to compare the type, default 0. 00271 @return True if the type of the layer LayerIndex is wkbPoint, false otherwise. 00272 */ 00273 bool isPointType(unsigned int LayerIndex = 0); 00274 00275 00276 00277 }; 00278 00279 } } // namespaces openfluid, landr 00280 00281 00282 #endif /* VECTORDATASET_HPP_ */