OTB  9.0.0
Orfeo Toolbox
otbCoordinateToName.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 #ifndef otbCoordinateToName_h
22 #define otbCoordinateToName_h
23 
24 #include "itkPoint.h"
25 #include "itkMultiThreader.h"
26 #include "otbCurlHelperInterface.h"
27 #include "OTBCartoExport.h"
28 #include <string>
29 
30 namespace otb
31 {
32 
44 class OTBCarto_EXPORT CoordinateToName : public itk::Object
45 {
46 public:
49  typedef itk::SmartPointer<Self> Pointer;
50  typedef itk::SmartPointer<const Self> ConstPointer;
51 
52  typedef itk::Object Superclass;
53 
54  itkTypeMacro(CoordinateToName, itk::Object);
56  itkNewMacro(Self);
57 
58  typedef itk::Point<double, 2> PointType;
59 
60  itkGetMacro(Lon, double);
61  itkGetMacro(Lat, double);
62 
63  itkSetMacro(Lon, double);
64  itkSetMacro(Lat, double);
65 
70  bool SetLonLat(PointType point)
71  {
72  if ((std::abs(point[0] - m_Lon) > m_UpdateDistance) || (std::abs(point[1] - m_Lat) > m_UpdateDistance))
73  {
74  // std::cout << "Update lon/lat " << m_Lon << ", " << m_Lat << " -> " << point << std::endl;
75  m_Lon = point[0];
76  m_Lat = point[1];
77  // TODO Check whether it is better to have something imprecise or nothing at all
78  m_IsValid = false;
79  return true;
80  }
81  else
82  {
83  // std::cout << "Keeping lon/lat" << std::endl;
84  return false;
85  }
86  }
88 
89  std::string GetPlaceName() const
90  {
91  if (m_IsValid)
92  {
93  return m_PlaceName;
94  }
95  else
96  {
97  return "";
98  }
99  }
100 
101  std::string GetCountryName() const
102  {
103  if (m_IsValid)
104  {
105  return m_CountryName;
106  }
107  else
108  {
109  return "";
110  }
111  }
112 
113  itkGetMacro(Multithread, bool);
114  itkSetMacro(Multithread, bool);
115  itkBooleanMacro(Multithread);
116 
117  itkSetObjectMacro(Curl, CurlHelperInterface);
118 
119  virtual bool Evaluate();
120 
121 protected:
123  ~CoordinateToName() override
124  {
125  }
126  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
127  void ParseXMLGeonames(std::string& placeName, std::string& countryName) const;
128 
129  virtual void DoEvaluate();
130 
131  static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
132 
133 private:
134  CoordinateToName(const Self&) = delete;
135  void operator=(const Self&) = delete;
136 
137  double m_Lon;
138  double m_Lat;
139 
141  bool m_IsValid;
142 
143  // Minimum distance to trigger an update of the coordinates
144  // specified in degrees
146 
147  std::string m_PlaceName;
148  std::string m_CountryName;
149  std::string m_CurlOutput;
150 
152 
153  itk::MultiThreader::Pointer m_Threader;
154 };
155 
156 } // namespace otb
157 
158 #endif
otb::CurlHelperInterface::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbCurlHelperInterface.h:47
otb::CoordinateToName::m_PlaceName
std::string m_PlaceName
Definition: otbCoordinateToName.h:147
otb::CoordinateToName::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbCoordinateToName.h:49
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::CoordinateToName::SetLonLat
bool SetLonLat(PointType point)
Definition: otbCoordinateToName.h:70
otb::CoordinateToName::m_CountryName
std::string m_CountryName
Definition: otbCoordinateToName.h:148
otb::CoordinateToName::m_Lat
double m_Lat
Definition: otbCoordinateToName.h:138
otb::CoordinateToName::m_Curl
CurlHelperInterface::Pointer m_Curl
Definition: otbCoordinateToName.h:151
otb::CoordinateToName::GetCountryName
std::string GetCountryName() const
Definition: otbCoordinateToName.h:101
otb::CoordinateToName::Self
CoordinateToName Self
Definition: otbCoordinateToName.h:48
otb::CoordinateToName::m_CurlOutput
std::string m_CurlOutput
Definition: otbCoordinateToName.h:149
otb::CoordinateToName::GetPlaceName
std::string GetPlaceName() const
Definition: otbCoordinateToName.h:89
otb::CoordinateToName::PointType
itk::Point< double, 2 > PointType
Definition: otbCoordinateToName.h:56
otb::CoordinateToName::m_UpdateDistance
double m_UpdateDistance
Definition: otbCoordinateToName.h:145
otb::CoordinateToName::m_IsValid
bool m_IsValid
Definition: otbCoordinateToName.h:141
otb::CoordinateToName::Superclass
itk::Object Superclass
Definition: otbCoordinateToName.h:52
otbCurlHelperInterface.h
otb::CoordinateToName::~CoordinateToName
~CoordinateToName() override
Definition: otbCoordinateToName.h:123
otb::CoordinateToName::m_Multithread
bool m_Multithread
Definition: otbCoordinateToName.h:140
otb::CurlHelperInterface
Class to use the curl capabilities from OTB.
Definition: otbCurlHelperInterface.h:41
otb::CoordinateToName::m_Threader
itk::MultiThreader::Pointer m_Threader
Definition: otbCoordinateToName.h:153
otb::CoordinateToName
Retrieve geographical information for longitude and latitude coordinates.
Definition: otbCoordinateToName.h:44
otb::CoordinateToName::m_Lon
double m_Lon
Definition: otbCoordinateToName.h:137
otb::CoordinateToName::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbCoordinateToName.h:50