Skip to content
Snippets Groups Projects
Commit feba1bfc authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

ENH: validate lon/lat before sending request

parent 8217ef04
No related branches found
No related tags found
No related merge requests found
......@@ -93,19 +93,28 @@ CoordinateToName::ThreadFunction(void *arg)
void CoordinateToName::DoEvaluate()
{
std::ostringstream urlStream;
urlStream << "http://ws.geonames.org/findNearbyPlaceName?lat=";
urlStream << m_Lat;
urlStream << "&lng=";
urlStream << m_Lon;
otbMsgDevMacro("CoordinateToName: retrieve url " << urlStream.str());
RetrieveXML(urlStream);
std::string placeName = "";
std::string countryName = "";
ParseXMLGeonames(placeName, countryName);
m_PlaceName = placeName;
m_CountryName = countryName;
m_IsValid = true;
if (IsLonLatValid())
{
std::ostringstream urlStream;
urlStream << "http://ws.geonames.org/findNearbyPlaceName?lat=";
urlStream << m_Lat;
urlStream << "&lng=";
urlStream << m_Lon;
otbMsgDevMacro("CoordinateToName: retrieve url " << urlStream.str());
RetrieveXML(urlStream);
std::string placeName = "";
std::string countryName = "";
ParseXMLGeonames(placeName, countryName);
m_PlaceName = placeName;
m_CountryName = countryName;
m_IsValid = true;
}
else
{
m_PlaceName = "";
m_CountryName = "";
m_IsValid = false;
}
}
void CoordinateToName::RetrieveXML(const std::ostringstream& urlStream) const
......@@ -138,4 +147,13 @@ void CoordinateToName::ParseXMLGeonames(std::string& placeName, std::string& cou
}
}
bool CoordinateToName::IsLonLatValid() const
{
if (m_Lon < -180.0) return false;
if (m_Lon > 180.0) return false;
if (m_Lat < -90.0) return false;
if (m_Lat > 90.0) return false;
return true;
}
} // namespace otb
......@@ -118,6 +118,8 @@ protected:
virtual void DoEvaluate();
bool IsLonLatValid() const;
static ITK_THREAD_RETURN_TYPE ThreadFunction(void*);
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment