<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "otbPlaceNameToLonLat.h"
#include "tinyxml.h"
#include "otbCurlHelper.h"

namespace otb
{

PlaceNameToLonLat::PlaceNameToLonLat() :
      m_Lon(-1000.0), m_Lat(-1000.0),
      m_PlaceName("Where everything started"),
      m_RequestSucceed(false)
{
  m_Curl = CurlHelper::New();
}

void
PlaceNameToLonLat
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << " m_Lon "  << m_Lon << std::endl;
  os << indent << " m_Lat "  << m_Lat << std::endl;
  os << indent << " m_PlaceName "  << m_PlaceName << std::endl;
}

bool PlaceNameToLonLat::Evaluate()
{
  std::string::size_type loc = m_PlaceName.find(" ", 0);
  while (loc != std::string::npos)
    {
    m_PlaceName.replace(loc, 1, "+");
    loc = m_PlaceName.find(" ", loc);
    }

  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    {
    std::ostringstream urlStream;
    urlStream << "http://maps.google.com/maps?q=";
    urlStream << m_PlaceName;
    urlStream << "&sll=38.9594, -95.2655&sspn=119.526, 360&output=kml&ie=utf-8&v=2.2&cv=4.2.0180.1134&hl=en";
    RetrieveXML(urlStream);
    if ( m_RequestSucceed )
      ParseXMLGoogle();
    }

  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    {
    std::ostringstream urlStream;
    urlStream << "http://api.local.yahoo.com/MapsService/V1/geocode?appid=com.sun.blueprints.ui.geocoder&location=";
    urlStream << m_PlaceName;
    RetrieveXML(urlStream);
    if ( m_RequestSucceed )
      ParseXMLYahoo();
    }

  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    {
    std::cout << "Search Error: fallback on the origin" << std::endl;
    m_Lat = 43.560204;
    m_Lon = 1.480736;
    return false;
    }
  return true;<commit_msg>ENH: comment yahoo api place finder and correct google url to work proprely<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "otbPlaceNameToLonLat.h"
#include "tinyxml.h"
#include "otbCurlHelper.h"

namespace otb
{

PlaceNameToLonLat::PlaceNameToLonLat() :
      m_Lon(-1000.0), m_Lat(-1000.0),
      m_PlaceName("Where everything started"),
      m_RequestSucceed(false)
{
  m_Curl = CurlHelper::New();
}

void
PlaceNameToLonLat
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << " m_Lon "  << m_Lon << std::endl;
  os << indent << " m_Lat "  << m_Lat << std::endl;
  os << indent << " m_PlaceName "  << m_PlaceName << std::endl;
}

bool PlaceNameToLonLat::Evaluate()
{
  std::string::size_type loc = m_PlaceName.find(" ", 0);
  while (loc != std::string::npos)
    {
    m_PlaceName.replace(loc, 1, "+");
    loc = m_PlaceName.find(" ", loc);
    }

  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    {
    std::ostringstream urlStream;
    urlStream << "http://maps.google.com/maps?q=";
    urlStream << m_PlaceName;
    urlStream << "&sll=38.9594,-95.2655&sspn=119.526,360&output=kml&ie=utf-8&v=2.2&cv=4.2.0180.1134&hl=en";
    RetrieveXML(urlStream);
    if ( m_RequestSucceed )
      ParseXMLGoogle();
    }

  // Yahoo new PlaceFinder API need an application ID to be able 
  // to use it
  // if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
  //   {
  //   std::ostringstream urlStream;
  //   urlStream << "http://api.local.yahoo.com/MapsService/V1/geocode?appid=com.sun.blueprints.ui.geocoder&location=";
  //   urlStream << m_PlaceName;
  //   RetrieveXML(urlStream);
  //   if ( m_RequestSucceed )
  //     ParseXMLYahoo();
  //   }

  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    {
    std::cout << "Search Error: fallback on the origin" << std::endl;
    m_Lat = 43.560204;
    m_Lon = 1.480736;
    return false;
    }
  return true;
{'fraction_non_alphanumeric': 0.2093855218855219, 'fraction_numerical': 0.03872053872053872, 'mean_word_length': 3.5658021133525457, 'pattern_counts': {'":': 0, '<': 79, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624366', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1664, 'n_words': 345}