OTB  6.7.0
Orfeo Toolbox
otbOSMDataToVectorDataGenerator.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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 
77 class OTBCarto_EXPORT OSMDataToVectorDataGenerator :
78  public VectorDataSource< otb::VectorData<> >
79 {
80 public:
86 
87  typedef Superclass::OutputVectorDataType VectorDataType;
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 
223  VectorDataType::Pointer m_OutputVectorData;
224 
227 
229  std::string m_ClassKey;
231 
232 }; // end of class
233 
234 } // end of namespace otb
235 
236 #endif
std::pair< ElementPairType, PointTypeList > VectorDataElementType
otb::VectorData< VectorDataCoordinatePrecisionType, 2, VectorDataValuePrecisionType > VectorDataType
std::pair< std::string, std::string > ElementPairType
VectorDataSource< otb::VectorData<> > Superclass
Superclass::OutputVectorDataType VectorDataType
std::map< std::string, StringVectorType > KeyMapType
Filter hierarchy for generating VectorData.
Request OSM Server using the OSM API 0.6 to get the xml file storing the vector elements available...
std::vector< VectorDataElementType > VectorDataElementListType
itk::SmartPointer< const Self > ConstPointer