OTB  9.0.0
Orfeo Toolbox
otbOSMDataToVectorDataGenerator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 "otbVectorData.h"
31 #include "otbVectorDataSource.h"
32 
33 #include "otbCurlHelper.h"
34 
35 namespace otb
36 {
37 
78 class OTBCarto_EXPORT OSMDataToVectorDataGenerator : public VectorDataSource<otb::VectorData<>>
79 {
80 public:
84  typedef itk::SmartPointer<Self> Pointer;
85  typedef itk::SmartPointer<const Self> ConstPointer;
86 
88  typedef VectorDataType::DataNodeType DataNodeType;
89  typedef DataNodeType::LineType LineType;
90  typedef DataNodeType::PolygonType PolygonType;
91  typedef LineType::VertexType VertexType;
92 
93  // typedefs for objects to store results
94  typedef std::map<int, VertexType> ContainerType;
95 
96  // Vector to store <Key, value>
97  typedef std::pair<std::string, std::string> ElementPairType;
98 
99  // Coordinates of the nodes
100  typedef std::vector<VertexType> PointTypeList;
101  typedef std::pair<ElementPairType, PointTypeList> VectorDataElementType;
102  typedef std::vector<VectorDataElementType> VectorDataElementListType;
103 
104  // Map to store all the keys found and their relative types
105  typedef std::vector<std::string> StringVectorType;
106  typedef std::map<std::string, StringVectorType> KeyMapType;
107 
110 
112  itkNewMacro(Self);
113 
115  itkSetStringMacro(FileName);
116  itkGetStringMacro(FileName);
118 
120  itkSetMacro(North, double);
121  itkSetMacro(South, double);
122  itkSetMacro(East, double);
123  itkSetMacro(West, double);
125 
126  itkGetMacro(North, double);
127  itkGetMacro(South, double);
128  itkGetMacro(East, double);
129  itkGetMacro(West, double);
130 
132  itkGetConstMacro(ClassKey, std::string);
133  itkSetMacro(ClassKey, std::string);
135 
137  itkGetConstMacro(ClassKeyValue, int);
138  itkSetMacro(ClassKeyValue, int);
140 
141  /* flag to choose between requesting the url using curl or a file
142  in the disk */
143  itkSetMacro(UseUrl, bool);
144 
146  void AddKey(const std::string& key)
147  {
148  if (!this->IsKeyPresent(key))
149  m_KeyList.push_back(key);
150  }
151 
155  const KeyMapType GetKeysMap() const
156  {
157  return m_KeysMap;
158  }
159 
163  const VectorDataType* GetVectorDataByName(const std::string& key);
164 
168  const VectorDataType* GetVectorDataByName(const std::string& key, const std::string& value);
169 
170 protected:
172  void GenerateData() override;
173 
178  void ParseXmlFile();
179 
183  void ProcessVectorData(const std::string& key, const std::string& value);
184 
188  bool IsKeyPresent(const std::string& key);
189 
190 
192  ~OSMDataToVectorDataGenerator() override;
193 
194 private:
195  OSMDataToVectorDataGenerator(const Self&) = delete;
196  void operator=(const Self&) = delete;
197 
198  // Private method to add the key, type to the map
199  void AddKeyTypeToMap(const std::string& key, const std::string& value);
200 
201  // Extent of the region to get from OSM
202  double m_North;
203  double m_South;
204  double m_East;
205  double m_West;
206 
208  std::string m_Url;
209  bool m_UseUrl;
210 
212  std::vector<std::string> m_KeyList;
213 
215  std::string m_FileName;
218 
221 
224 
227 
229  std::string m_ClassKey;
231 
232 }; // end of class
233 
234 } // end of namespace otb
235 
236 #endif
otb::OSMDataToVectorDataGenerator::ContainerType
std::map< int, VertexType > ContainerType
Definition: otbOSMDataToVectorDataGenerator.h:94
otb::OSMDataToVectorDataGenerator::m_OutputVectorData
VectorDataType::Pointer m_OutputVectorData
Definition: otbOSMDataToVectorDataGenerator.h:223
otb::OSMDataToVectorDataGenerator::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbOSMDataToVectorDataGenerator.h:85
otb::OSMDataToVectorDataGenerator::PolygonType
DataNodeType::PolygonType PolygonType
Definition: otbOSMDataToVectorDataGenerator.h:90
otb::OSMDataToVectorDataGenerator::m_ClassKeyValue
int m_ClassKeyValue
Definition: otbOSMDataToVectorDataGenerator.h:230
otb::OSMDataToVectorDataGenerator::m_East
double m_East
Definition: otbOSMDataToVectorDataGenerator.h:204
otb::VectorData::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbVectorData.h:64
otb::OSMDataToVectorDataGenerator::VectorDataElementListType
std::vector< VectorDataElementType > VectorDataElementListType
Definition: otbOSMDataToVectorDataGenerator.h:102
otb::VectorData
This class represents a hierarchy of vector data.
Definition: otbVectorData.h:58
otb::OSMDataToVectorDataGenerator::m_Curl
CurlHelper::Pointer m_Curl
Definition: otbOSMDataToVectorDataGenerator.h:220
otb::OSMDataToVectorDataGenerator::GetKeysMap
const KeyMapType GetKeysMap() const
Definition: otbOSMDataToVectorDataGenerator.h:155
otb::OSMDataToVectorDataGenerator::DataNodeType
VectorDataType::DataNodeType DataNodeType
Definition: otbOSMDataToVectorDataGenerator.h:88
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::OSMDataToVectorDataGenerator::m_VectorDataElementList
VectorDataElementListType m_VectorDataElementList
Definition: otbOSMDataToVectorDataGenerator.h:217
otb::OSMDataToVectorDataGenerator::VertexType
LineType::VertexType VertexType
Definition: otbOSMDataToVectorDataGenerator.h:91
otb::OSMDataToVectorDataGenerator::m_KeyList
std::vector< std::string > m_KeyList
Definition: otbOSMDataToVectorDataGenerator.h:212
otb::OSMDataToVectorDataGenerator::Self
OSMDataToVectorDataGenerator Self
Definition: otbOSMDataToVectorDataGenerator.h:82
otb::OSMDataToVectorDataGenerator::m_South
double m_South
Definition: otbOSMDataToVectorDataGenerator.h:203
otb::OSMDataToVectorDataGenerator::VectorDataElementType
std::pair< ElementPairType, PointTypeList > VectorDataElementType
Definition: otbOSMDataToVectorDataGenerator.h:101
otbVectorDataSource.h
otb::CurlHelper::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbCurlHelper.h:46
otb::OSMDataToVectorDataGenerator::StringVectorType
std::vector< std::string > StringVectorType
Definition: otbOSMDataToVectorDataGenerator.h:105
otb::OSMDataToVectorDataGenerator::LineType
DataNodeType::LineType LineType
Definition: otbOSMDataToVectorDataGenerator.h:89
otb::OSMDataToVectorDataGenerator::VectorDataType
Superclass::OutputVectorDataType VectorDataType
Definition: otbOSMDataToVectorDataGenerator.h:87
otb::OSMDataToVectorDataGenerator::m_West
double m_West
Definition: otbOSMDataToVectorDataGenerator.h:205
otb::OSMDataToVectorDataGenerator::ElementPairType
std::pair< std::string, std::string > ElementPairType
Definition: otbOSMDataToVectorDataGenerator.h:97
otbVectorData.h
otb::OSMDataToVectorDataGenerator::m_Url
std::string m_Url
Definition: otbOSMDataToVectorDataGenerator.h:208
otb::OSMDataToVectorDataGenerator::KeyMapType
std::map< std::string, StringVectorType > KeyMapType
Definition: otbOSMDataToVectorDataGenerator.h:106
otb::OSMDataToVectorDataGenerator::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbOSMDataToVectorDataGenerator.h:84
otb::OSMDataToVectorDataGenerator::m_KeysMap
KeyMapType m_KeysMap
Definition: otbOSMDataToVectorDataGenerator.h:226
otb::OSMDataToVectorDataGenerator::PointTypeList
std::vector< VertexType > PointTypeList
Definition: otbOSMDataToVectorDataGenerator.h:100
otb::OSMDataToVectorDataGenerator::m_GeoPointContainer
ContainerType m_GeoPointContainer
Definition: otbOSMDataToVectorDataGenerator.h:216
otb::OSMDataToVectorDataGenerator::m_North
double m_North
Definition: otbOSMDataToVectorDataGenerator.h:202
otb::OSMDataToVectorDataGenerator::m_UseUrl
bool m_UseUrl
Definition: otbOSMDataToVectorDataGenerator.h:209
otb::VectorDataSource
Filter hierarchy for generating VectorData.
Definition: otbVectorDataSource.h:42
otbCurlHelper.h
otb::OSMDataToVectorDataGenerator::m_ClassKey
std::string m_ClassKey
Definition: otbOSMDataToVectorDataGenerator.h:229
otb::OSMDataToVectorDataGenerator::AddKey
void AddKey(const std::string &key)
Definition: otbOSMDataToVectorDataGenerator.h:146
otb::Wrapper::VectorDataType
otb::VectorData< VectorDataCoordinatePrecisionType, 2, VectorDataValuePrecisionType > VectorDataType
Definition: otbWrapperTypes.h:174
otb::OSMDataToVectorDataGenerator
Request OSM Server using the OSM API 0.6 to get the xml file storing the vector elements available.
Definition: otbOSMDataToVectorDataGenerator.h:78
otb::OSMDataToVectorDataGenerator::m_FileName
std::string m_FileName
Definition: otbOSMDataToVectorDataGenerator.h:215
otb::OSMDataToVectorDataGenerator::Superclass
VectorDataSource< otb::VectorData<> > Superclass
Definition: otbOSMDataToVectorDataGenerator.h:83