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