OTB  10.0.0
Orfeo Toolbox
otbOSMDataToVectorDataGenerator.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 
22 #ifndef otbOSMDataToVectorDataGenerator_h
23 #define otbOSMDataToVectorDataGenerator_h
24 
25 // store the nodes (points) coordinates
26 #include <map>
27 #include <string>
28 
29 #include "OTBCartoExport.h"
30 #include "itkMacro.h"
31 #include "otbVectorData.h"
32 #include "otbVectorDataSource.h"
33 
34 #include "otbCurlHelper.h"
35 
36 namespace otb
37 {
38 
79 class OTBCarto_EXPORT OSMDataToVectorDataGenerator : public VectorDataSource<otb::VectorData<>>
80 {
81 public:
85  typedef itk::SmartPointer<Self> Pointer;
86  typedef itk::SmartPointer<const Self> ConstPointer;
87 
93 
94  // typedefs for objects to store results
95  typedef std::map<int, VertexType> ContainerType;
96 
97  // Vector to store <Key, value>
98  typedef std::pair<std::string, std::string> ElementPairType;
99 
100  // Coordinates of the nodes
101  typedef std::vector<VertexType> PointTypeList;
102  typedef std::pair<ElementPairType, PointTypeList> VectorDataElementType;
103  typedef std::vector<VectorDataElementType> VectorDataElementListType;
104 
105  // Map to store all the keys found and their relative types
106  typedef std::vector<std::string> StringVectorType;
107  typedef std::map<std::string, StringVectorType> KeyMapType;
108 
111 
113  itkNewMacro(Self);
114 
116  itkSetStringMacro(FileName);
117  itkGetStringMacro(FileName);
119 
121  itkSetMacro(North, double);
122  itkSetMacro(South, double);
123  itkSetMacro(East, double);
124  itkSetMacro(West, double);
126 
127  itkGetMacro(North, double);
128  itkGetMacro(South, double);
129  itkGetMacro(East, double);
130  itkGetMacro(West, double);
131 
133  itkGetConstMacro(ClassKey, std::string);
134  itkSetMacro(ClassKey, std::string);
136 
138  itkGetConstMacro(ClassKeyValue, int);
139  itkSetMacro(ClassKeyValue, int);
141 
142  /* flag to choose between requesting the url using curl or a file
143  in the disk */
144  itkSetMacro(UseUrl, bool);
145 
147  void AddKey(const std::string& key)
148  {
149  if (!this->IsKeyPresent(key))
150  m_KeyList.push_back(key);
151  }
152 
156  const KeyMapType GetKeysMap() const
157  {
158  return m_KeysMap;
159  }
160 
164  const VectorDataType* GetVectorDataByName(const std::string& key);
165 
169  const VectorDataType* GetVectorDataByName(const std::string& key, const std::string& value);
170 
171 protected:
173  void GenerateData() override;
174 
179  void ParseXmlFile();
180 
184  void ProcessVectorData(const std::string& key, const std::string& value);
185 
189  bool IsKeyPresent(const std::string& key);
190 
191 
194 
195 private:
197  void operator=(const Self&) = delete;
198 
199  // Private method to add the key, type to the map
200  void AddKeyTypeToMap(const std::string& key, const std::string& value);
201 
202  // Extent of the region to get from OSM
203  double m_North;
204  double m_South;
205  double m_East;
206  double m_West;
207 
209  std::string m_Url;
210  bool m_UseUrl;
211 
213  std::vector<std::string> m_KeyList;
214 
216  std::string m_FileName;
219 
222 
225 
228 
230  std::string m_ClassKey;
232 
233 }; // end of class
234 
235 } // end of namespace otb
236 
237 #endif
itk::SmartPointer< Self > Pointer
Definition: otbCurlHelper.h:46
This class represents a node of data in a vector data hierarchy.
Definition: otbDataNode.h:74
Request OSM Server using the OSM API 0.6 to get the xml file storing the vector elements available.
bool IsKeyPresent(const std::string &key)
void operator=(const Self &)=delete
Superclass::OutputVectorDataType VectorDataType
OSMDataToVectorDataGenerator(const Self &)=delete
const VectorDataType * GetVectorDataByName(const std::string &key, const std::string &value)
std::map< std::string, StringVectorType > KeyMapType
const VectorDataType * GetVectorDataByName(const std::string &key)
itk::SmartPointer< const Self > ConstPointer
std::vector< VectorDataElementType > VectorDataElementListType
VectorDataSource< otb::VectorData<> > Superclass
void AddKeyTypeToMap(const std::string &key, const std::string &value)
void ProcessVectorData(const std::string &key, const std::string &value)
std::pair< ElementPairType, PointTypeList > VectorDataElementType
std::pair< std::string, std::string > ElementPairType
This class implement a PolyLineParametricPath for which a value can be set. The value is stored in th...
This class represent a 2D polygon.
Definition: otbPolygon.h:45
Filter hierarchy for generating VectorData.
This class represents a hierarchy of vector data.
Definition: otbVectorData.h:62
itk::SmartPointer< Self > Pointer
Definition: otbVectorData.h:67
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.