OTB  10.0.0
Orfeo Toolbox
otbVectorDataKeywordlist.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbVectorDataKeywordlist_h
22 #define otbVectorDataKeywordlist_h
23 
24 #include <iosfwd>
25 #include <vector>
26 #include <string>
27 
28 #include "itkLightObject.h"
29 #include "itkObjectFactory.h"
30 #if defined(__GNUC__) || defined(__clang__)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wshadow"
33 #include "ogr_feature.h"
34 #pragma GCC diagnostic pop
35 #else
36 #include "ogr_feature.h"
37 #endif
38 
39 namespace otb
40 {
55 #include "OTBVectorDataBaseExport.h"
56 
57 class OTBVectorDataBase_EXPORT VectorDataKeywordlist
58 {
59 public:
62 
63  typedef std::pair<OGRFieldDefn*, OGRField> FieldType;
64  typedef std::vector<FieldType> FieldListType;
65 
66  virtual const char* GetNameOfClass() const
67  {
68  return "VectorDataKeywordlist";
69  }
70 
71  void AddField(OGRFieldDefn* fieldDefn, OGRField* field);
72 
77  void AddField(const std::string& key, const std::string& value);
78 
84  std::string GetFieldAsString(const std::string& key) const;
85 
90  bool HasField(const std::string& key) const;
91 
96  void SetFieldAsString(const std::string& key, const std::string& value);
97 
103  double GetFieldAsDouble(const std::string& key) const;
104 
109  void SetFieldAsDouble(const std::string& key, double value);
110 
116  void SetFieldAsInt(const std::string& key, int value);
117 
123  int GetFieldAsInt(const std::string& key) const;
124 
129  FieldType GetNthField(unsigned int index) const;
130 
134  unsigned int GetNumberOfFields() const;
135 
139  std::vector<std::string> GetFieldList() const;
140 
144  void CopyFieldList(const Self& kwl);
145 
149  virtual void Print(std::ostream& os, itk::Indent indent = 0) const;
150 
153 
156 
159 
161  void operator=(const Self&);
162 
163  friend bool operator==(const Self &lhs, const Self &rhs)
164  {
165  unsigned int equalfields = 0;
166  if(lhs.GetNumberOfFields()==rhs.GetNumberOfFields())
167  {
168  for(unsigned int i = 0; i < lhs.m_FieldList.size(); ++i)
169  {
170  if(lhs.HasField((rhs.m_FieldList[i].first)->GetNameRef()))
171  {
172  equalfields++;
173  }
174  }
175  }
176  if (equalfields == lhs.GetNumberOfFields())
177  {
178  return true;
179  }
180  return false;
181  };
182 
183 protected:
184  virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
185 
186 private:
187  std::string PrintField(FieldType field) const;
190 };
191 OTBVectorDataBase_EXPORT extern std::ostream& operator<<(std::ostream& os, const VectorDataKeywordlist& kwl);
192 }
193 
194 #endif
this class handle the metadata of vector data.
int GetFieldAsInt(const std::string &key) const
bool HasField(const std::string &key) const
friend bool operator==(const Self &lhs, const Self &rhs)
std::string GetFieldAsString(const std::string &key) const
void operator=(const Self &)
void SetFieldAsString(const std::string &key, const std::string &value)
void AddField(OGRFieldDefn *fieldDefn, OGRField *field)
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
std::string PrintField(FieldType field) const
void CopyFieldList(const Self &kwl)
virtual const char * GetNameOfClass() const
void AddField(const std::string &key, const std::string &value)
FieldType GetNthField(unsigned int index) const
std::pair< OGRFieldDefn *, OGRField > FieldType
double GetFieldAsDouble(const std::string &key) const
VectorDataKeywordlist(const Self &other)
virtual void Print(std::ostream &os, itk::Indent indent=0) const
FieldType CopyOgrField(FieldType field)
std::vector< std::string > GetFieldList() const
void SetFieldAsInt(const std::string &key, int value)
std::vector< FieldType > FieldListType
void SetFieldAsDouble(const std::string &key, double value)
unsigned int GetNumberOfFields() const
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
OTBCommon_EXPORT std::ostream & operator<<(std::ostream &os, const otb::StringToHTML &str)