otbVectorDataKeywordlist.h 4.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20

21 22
#ifndef otbVectorDataKeywordlist_h
#define otbVectorDataKeywordlist_h
23

24 25 26
#include <iosfwd>
#include <vector>

27 28
#include "itkLightObject.h"
#include "itkObjectFactory.h"
29
#if defined(__GNUC__) || defined(__clang__)
30 31
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow"
32
#include "ogr_feature.h"
33
#pragma GCC diagnostic pop
34 35 36
#else
#include "ogr_feature.h"
#endif
37 38 39

namespace otb
{
40
/** \class VectorDataKeywordlist
41 42 43 44 45 46
 * \brief this class handle the metadata of vector data.
 *
 * This class is used internaly to handle the information associated with
 * a vector object. This information is retrieved from the input file (a
 * shapefile for example) and propagated along the pipeline with the object.
 *
47
 * This is the equivalent of the otbImageKeywordlist class but for OGR information.
48 49 50
 *
 * \todo add the accessor to enable modifying/updating the data.
 *
51 52
 *
 * \ingroup OTBVectorDataBase
53
 */
54
#include "OTBVectorDataBaseExport.h"
55

56
class OTBVectorDataBase_EXPORT VectorDataKeywordlist
57
{
OTB Bot's avatar
OTB Bot committed
58 59
public:
  /** Smart pointer typedef support. */
60
  typedef VectorDataKeywordlist Self;
61

OTB Bot's avatar
OTB Bot committed
62 63
  typedef std::pair<OGRFieldDefn*, OGRField> FieldType;
  typedef std::vector<FieldType>             FieldListType;
64

65 66 67
  virtual const char *GetNameOfClass() const
  {return "VectorDataKeywordlist"; }

OTB Bot's avatar
OTB Bot committed
68
  void AddField(OGRFieldDefn* fieldDefn, OGRField* field);
69

OTB Bot's avatar
OTB Bot committed
70 71 72 73
  /**
    * \param key The name of the field.
    * \param value The value of the field.
    */
74
  void AddField(const std::string& key, const std::string& value);
75

76 77 78
  /**
    * Returns the value associated with a field name.
    * \param key The name of the field.
Emmanuel Christophe's avatar
Emmanuel Christophe committed
79
    * \return The value of the field. A default value is returned if the key was not found.
80
    */
81
  std::string GetFieldAsString(const std::string& key) const;
82 83 84 85 86

  /**
    * \return True if the node contains the field named after the given key.
    * \param key The name of the field.
    */
87
  bool HasField(const std::string& key) const;
88

OTB Bot's avatar
OTB Bot committed
89 90 91 92
  /**
    * \param key The name of the field.
    * \param value The value of the field.
    */
93
  void SetFieldAsString(const std::string& key, const std::string& value);
94

95 96 97 98 99
  /**
    * Returns the value associated with a field name.
    * \param key The name of the field.
    * \return The value of the field. A default value is returned if the key was not found.
    */
100
  double GetFieldAsDouble(const std::string& key) const;
101 102 103 104 105

  /**
    * \param key The name of the field.
    * \param value The value of the field.
    */
106
  void SetFieldAsDouble(const std::string& key, double value);
107

108 109 110 111 112
   /**
    * Set the field as an integer
    * \param key The name of the field.
    * \param value The value of the field.
    */
113
  void SetFieldAsInt(const std::string& key, int value);
114

115 116 117 118 119
  /**
    * Returns the value associated with a field name.
    * \param key The name of the field.
    * \return The value of the field. A default value is returned if the key was not found.
    */
120
  int GetFieldAsInt(const std::string& key) const;
121

122
  /**
OTB Bot's avatar
OTB Bot committed
123
    * \return the nth field of the node as a std::pair of (key, value).
124 125
    * \param index the index of the field to return.
    */
OTB Bot's avatar
OTB Bot committed
126
  FieldType GetNthField(unsigned int index) const;
127 128 129 130

  /**
    * \return the number of fields in the node.
    */
OTB Bot's avatar
OTB Bot committed
131
  unsigned int GetNumberOfFields() const;
132

133 134 135 136 137
  /**
    * \return the name of fields in the node.
    */
  std::vector<std::string> GetFieldList() const;

138 139 140 141 142
  /**
    * Copy all the fields from another kwl
    */
  void CopyFieldList(const Self& kwl);

OTB Bot's avatar
OTB Bot committed
143 144 145 146
  /**
   * Print the keyword list
   */
  virtual void Print(std::ostream& os, itk::Indent indent = 0) const;
147

OTB Bot's avatar
OTB Bot committed
148 149
  /** Constructor */
  VectorDataKeywordlist();
150

OTB Bot's avatar
OTB Bot committed
151
  /** Destructor */
152
  ~VectorDataKeywordlist();
153

OTB Bot's avatar
OTB Bot committed
154
  /** Constructor by copy (deep copy)*/
155
  VectorDataKeywordlist(const Self& other);
156

OTB Bot's avatar
OTB Bot committed
157 158
  /** Deep copy operator*/
  void operator =(const Self&);
159

OTB Bot's avatar
OTB Bot committed
160
protected:
161

OTB Bot's avatar
OTB Bot committed
162
  virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
163

OTB Bot's avatar
OTB Bot committed
164
private:
165

OTB Bot's avatar
OTB Bot committed
166 167 168
  std::string PrintField(FieldType field) const;
  FieldType CopyOgrField(FieldType field);
  FieldListType m_FieldList;
169 170

};
171
OTBVectorDataBase_EXPORT
OTB Bot's avatar
OTB Bot committed
172
extern std::ostream & operator <<(std::ostream& os, const VectorDataKeywordlist& kwl);
173

174 175 176
}

#endif