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 GeoVectorValue.hpp 00034 \brief Header of ... 00035 00036 \author Aline LIBRES <libres@supagro.inra.fr> 00037 */ 00038 00039 #ifndef __GEOVECTORVALUE_HPP__ 00040 #define __GEOVECTORVALUE_HPP__ 00041 00042 #include <openfluid/core/GeoValue.hpp> 00043 #include <openfluid/dllexport.hpp> 00044 00045 #include <ogrsf_frmts.h> 00046 00047 namespace openfluid { 00048 namespace core { 00049 00050 /** 00051 * @brief Container class for geospatial vector data, 00052 * represented by an OGR datasource. 00053 */ 00054 class DLLEXPORT GeoVectorValue: public openfluid::core::GeoValue 00055 { 00056 protected: 00057 00058 /** 00059 * @brief The OGRDataSource associated to this GeoVectorValue. 00060 */ 00061 OGRDataSource* mp_Data; 00062 00063 /** 00064 * @brief Open the OGRDataSource of this GeoVectorValue. 00065 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00066 * 00067 */ 00068 void tryToOpenSource(); 00069 00070 /** 00071 * @brief Destroy the OGRDataSource. 00072 */ 00073 void destroyDataSource(); 00074 00075 public: 00076 00077 /** 00078 * @brief Creates a new value. 00079 * 00080 * For ESRI Shapefile, the <tt>FileName</tt> may be the name of a .shp, .shx or .dbf file, 00081 * or a path to a directory containing proper shape files. 00082 * 00083 * It doesn't open the associated OGR datasource. 00084 * 00085 * @param FilePath The path of the file(s). 00086 * @param FileName The name or the relative path of the file to open. 00087 */ 00088 GeoVectorValue(std::string FilePath, std::string FileName); 00089 00090 /** 00091 * @brief Closes the opened OGR datasource. 00092 */ 00093 ~GeoVectorValue(); 00094 00095 /** 00096 * @brief Returns the type of this GeoVectorValue. 00097 */ 00098 openfluid::core::UnstructuredValue::UnstructuredType getType() const; 00099 00100 /** 00101 * @brief Gets the associated opened OGR datasource in read-only access. 00102 * 00103 * If the datasource is not already opened, tries to open it first. 00104 * 00105 * @return The opened OGR datasource. 00106 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00107 */ 00108 OGRDataSource* get(); 00109 00110 /** 00111 * @brief Gets a layer of the shape. 00112 * 00113 * @param LayerIndex The index of the asked layer, default 0. 00114 * @return The layer indexed LayerIndex. 00115 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00116 */ 00117 OGRLayer* getLayer(unsigned int LayerIndex = 0); 00118 00119 /** 00120 * @brief Gets the Feature definition of a layer. 00121 * 00122 * @param LayerIndex The index of the asked layer definition, default 0. 00123 * @return The OGR Feature definition of the LayerIndex layer. 00124 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00125 */ 00126 OGRFeatureDefn* getLayerDef(unsigned int LayerIndex = 0); 00127 00128 /** 00129 * @brief Returns true if the GeoVectorValue is line type, false otherwise. 00130 * @param LayerIndex The index of the layer to compare the type, default 0. 00131 * @return True if the type of the layer LayerIndex is wkbLineString, false otherwise. 00132 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00133 */ 00134 bool isLineType(unsigned int LayerIndex = 0); 00135 00136 /** 00137 * @brief Returns true if the GeoVectorValue is polygon type, false otherwise. 00138 * @param LayerIndex The index of the layer to compare the type, default 0. 00139 * @return True if the type of the layer LayerIndex is wkbPolygon, false otherwise. 00140 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00141 */ 00142 bool isPolygonType(unsigned int LayerIndex = 0); 00143 00144 /** 00145 * @brief Returns true if a field exists in the LayerIndex layer. 00146 * 00147 * @param FieldName The name of the field to query. 00148 * @param LayerIndex The index of the layer to query, default 0. 00149 * @return True if the field FieldName exists, False otherwise. 00150 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00151 */ 00152 bool containsField(std::string FieldName, unsigned int LayerIndex = 0); 00153 00154 /** 00155 * @brief Gets the index of a field in the LayerIndex layer. 00156 * 00157 * @param LayerIndex The index of the layer to query, default 0. 00158 * @param FieldName The name of the field to query. 00159 * @return The index of FieldName or -1 if field FieldName doesn't exist. 00160 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00161 */ 00162 int getFieldIndex(std::string FieldName, unsigned int LayerIndex = 0); 00163 00164 /** 00165 * @brief Returns true if a field is of the type FieldType in the LayerIndex layer. 00166 * 00167 * @param FieldName The name of the field to query. 00168 * @param FieldType The type of the field to query. 00169 * @param LayerIndex The index of the layer to query, default 0. 00170 * @return True if the field FieldName is type FieldType. 00171 * @throw openfluid::base::OFException if the field doesn't exist. 00172 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00173 */ 00174 bool isFieldOfType(std::string FieldName, OGRFieldType FieldType, 00175 unsigned int LayerIndex = 0); 00176 00177 /** 00178 * @brief Returns true if the GeoVectorValue is point type, false otherwise. 00179 * @param LayerIndex The index of the layer to compare the type, default 0. 00180 * @return True if the type of the layer LayerIndex is wkbPoint, false otherwise. 00181 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00182 */ 00183 bool isPointType(unsigned int LayerIndex = 0); 00184 00185 /** 00186 * @brief Returns true if the GeoVectorValue is MultiPolygon type, false otherwise. 00187 * @param LayerIndex The index of the layer to compare the type, default 0. 00188 * @return True if the type of the layer LayerIndex is wkbMultiPolygon, false otherwise. 00189 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00190 */ 00191 bool isMultiPolygonType(unsigned int LayerIndex = 0); 00192 00193 /** 00194 * @brief Returns true if the GeoVectorValue is MultiLine type, false otherwise. 00195 * @param LayerIndex The index of the layer to compare the type, default 0. 00196 * @return True if the type of the layer LayerIndex is wkbMultiLineString, false otherwise. 00197 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00198 */ 00199 bool isMultiLineType(unsigned int LayerIndex = 0); 00200 00201 /** 00202 * @brief Returns true if the GeoVectorValue is MultiPoint type, false otherwise. 00203 * @param LayerIndex The index of the layer to compare the type, default 0. 00204 * @return True if the type of the layer LayerIndex is wkbMultiPoint, false otherwise. 00205 * @throw openfluid::base::OFException if OGR doesn't succeed to open the datasource. 00206 */ 00207 bool isMultiPointType(unsigned int LayerIndex = 0); 00208 00209 00210 00211 00212 }; 00213 00214 } 00215 } // namespaces 00216 00217 #endif /* __GEOVECTORVALUE_HPP__ */