ENH: txx to cxx
authorEmmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org>
Thu Jul 02 17:45:27 2009 +0800 (14 months ago)
changeset 586838ff65becdca
parent 5867 b4b2fcdc50fa
child 5871 4c270ec17acc
ENH: txx to cxx
Code/Projections/CMakeLists.txt
Code/Projections/otbCoordinateToName.cxx
Code/Projections/otbPlaceNameToLonLat.cxx
Code/Projections/otbPlaceNameToLonLat.h
Code/Projections/otbPlaceNameToLonLat.txx
     1.1 --- a/Code/Projections/CMakeLists.txt	Thu Jul 02 17:41:46 2009 +0800
     1.2 +++ b/Code/Projections/CMakeLists.txt	Thu Jul 02 17:45:27 2009 +0800
     1.3 @@ -1,6 +1,7 @@
     1.4  FILE(GLOB OTBProjections_SRCS "*.cxx" )
     1.5  
     1.6  IF( NOT OTB_USE_CURL )
     1.7 +    LIST(REMOVE_ITEM OTBProjections_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbPlaceNameToLonLat.cxx" )
     1.8      LIST(REMOVE_ITEM OTBProjections_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/otbCoordinateToName.cxx" )
     1.9  ENDIF( NOT OTB_USE_CURL )
    1.10  
    1.11 @@ -26,7 +27,7 @@
    1.12    FILE(GLOB __files2 "${CMAKE_CURRENT_SOURCE_DIR}/*.txx")
    1.13    IF( NOT OTB_USE_CURL )
    1.14      LIST(REMOVE_ITEM __files1 "${CMAKE_CURRENT_SOURCE_DIR}/otbPlaceNameToLonLat.h" )
    1.15 -    LIST(REMOVE_ITEM __files2 "${CMAKE_CURRENT_SOURCE_DIR}/otbPlaceNameToLonLat.txx" )
    1.16 +    LIST(REMOVE_ITEM __files2 "${CMAKE_CURRENT_SOURCE_DIR}/otbCoordinateToName.h" )
    1.17    ENDIF( NOT OTB_USE_CURL )
    1.18    INSTALL(FILES ${__files1} ${__files2}
    1.19      DESTINATION ${OTB_INSTALL_INCLUDE_DIR_CM24}/Projections
     2.1 --- a/Code/Projections/otbCoordinateToName.cxx	Thu Jul 02 17:41:46 2009 +0800
     2.2 +++ b/Code/Projections/otbCoordinateToName.cxx	Thu Jul 02 17:45:27 2009 +0800
     2.3 @@ -15,8 +15,6 @@
     2.4       PURPOSE.  See the above copyright notices for more information.
     2.5  
     2.6  =========================================================================*/
     2.7 -#ifndef __otbCoordinateToName_txx
     2.8 -#define __otbCoordinateToName_txx
     2.9  
    2.10  #include "otbCoordinateToName.h"
    2.11  #include "tinyxml.h"
    2.12 @@ -143,4 +141,3 @@
    2.13  
    2.14  } // namespace otb
    2.15  
    2.16 -#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/Code/Projections/otbPlaceNameToLonLat.cxx	Thu Jul 02 17:45:27 2009 +0800
     3.3 @@ -0,0 +1,188 @@
     3.4 +/*=========================================================================
     3.5 +
     3.6 +  Program:   ORFEO Toolbox
     3.7 +  Language:  C++
     3.8 +  Date:      $Date$
     3.9 +  Version:   $Revision$
    3.10 +
    3.11 +
    3.12 +  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
    3.13 +  See OTBCopyright.txt for details.
    3.14 +
    3.15 +
    3.16 +     This software is distributed WITHOUT ANY WARRANTY; without even
    3.17 +     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    3.18 +     PURPOSE.  See the above copyright notices for more information.
    3.19 +
    3.20 +=========================================================================*/
    3.21 +
    3.22 +#include "otbPlaceNameToLonLat.h"
    3.23 +#include "tinyxml.h"
    3.24 +#include <curl/curl.h>
    3.25 +
    3.26 +
    3.27 +namespace otb
    3.28 +{
    3.29 +
    3.30 +/**
    3.31 +   * Constructor
    3.32 +   */
    3.33 +
    3.34 +PlaceNameToLonLat::PlaceNameToLonLat()
    3.35 +{
    3.36 +  m_Lon = -1000.0;
    3.37 +  m_Lat = -1000.0;
    3.38 +  m_PlaceName = "Where everything started";
    3.39 +}
    3.40 +
    3.41 +/**
    3.42 +   *
    3.43 +   */
    3.44 +
    3.45 +void
    3.46 +PlaceNameToLonLat
    3.47 +::PrintSelf(std::ostream& os, itk::Indent indent) const
    3.48 +{
    3.49 +  this->Superclass::PrintSelf(os,indent);
    3.50 +  os << indent << " m_Lon "  << m_Lon << std::endl;
    3.51 +  os << indent << " m_Lat "  << m_Lat << std::endl;
    3.52 +  os << indent << " m_PlaceName "  << m_PlaceName << std::endl;
    3.53 +}
    3.54 +
    3.55 +
    3.56 +bool PlaceNameToLonLat::Evaluate()
    3.57 +{
    3.58 +  std::string::size_type loc = m_PlaceName.find(" ", 0 );
    3.59 +  while (loc != std::string::npos)
    3.60 +  {
    3.61 +    m_PlaceName.replace(loc, 1, "+");
    3.62 +    loc = m_PlaceName.find(" ", loc);
    3.63 +  }
    3.64 +
    3.65 +  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    3.66 +  {
    3.67 +    std::ostringstream urlStream;
    3.68 +    urlStream << "http://maps.google.com/maps?q=";
    3.69 +    urlStream << m_PlaceName;
    3.70 +    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";
    3.71 +    RetrieveXML(urlStream);
    3.72 +    ParseXMLGoogle();
    3.73 +  }
    3.74 +
    3.75 +  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    3.76 +  {
    3.77 +    std::ostringstream urlStream;
    3.78 +    urlStream << "http://api.local.yahoo.com/MapsService/V1/geocode?appid=com.sun.blueprints.ui.geocoder&location=";
    3.79 +    urlStream << m_PlaceName;
    3.80 +    RetrieveXML(urlStream);
    3.81 +    ParseXMLYahoo();
    3.82 +  }
    3.83 +
    3.84 +  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    3.85 +  {
    3.86 +    std::cout << "Search Error: fallback on the origin" << std::endl;
    3.87 +    m_Lat = 43.560204;
    3.88 +    m_Lon = 1.480736;
    3.89 +    return false;
    3.90 +  }
    3.91 +  return true;
    3.92 +}
    3.93 +
    3.94 +/*
    3.95 +//This method will be necessary to process the file directly in memory
    3.96 +//without writing it to the disk. Waiting for the xml lib to handle that
    3.97 +//also
    3.98 +static size_t
    3.99 +curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
   3.100 +  void *data)
   3.101 +{
   3.102 +  register int realsize = (int)(size * nmemb);
   3.103 +
   3.104 +  std::vector<char> *vec
   3.105 +    = static_cast<std::vector<char>*>(data);
   3.106 +  const char* chPtr = static_cast<char*>(ptr);
   3.107 +  vec->insert(vec->end(), chPtr, chPtr + realsize);
   3.108 +
   3.109 +  return realsize;
   3.110 +}
   3.111 +*/
   3.112 +
   3.113 +void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
   3.114 +{
   3.115 +
   3.116 +  CURL *curl;
   3.117 +  CURLcode res;
   3.118 +
   3.119 +  FILE* output_file = fopen("out.xml","w");
   3.120 +  curl = curl_easy_init();
   3.121 +
   3.122 +//   std::cout << "URL data " << urlStream.str().data() << std::endl;
   3.123 +
   3.124 +
   3.125 +  char url[256];
   3.126 +  strcpy(url,urlStream.str().data());
   3.127 +
   3.128 +//   std::cout << url << std::endl;
   3.129 +  if (curl)
   3.130 +  {
   3.131 +    std::vector<char> chunk;
   3.132 +    curl_easy_setopt(curl, CURLOPT_URL, url);
   3.133 +    /*
   3.134 +    //Step needed to handle curl without temporary file
   3.135 +    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,this->curlHandlerWriteMemoryCallback);
   3.136 +    curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
   3.137 +    */
   3.138 +    curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
   3.139 +    res = curl_easy_perform(curl);
   3.140 +
   3.141 +    fclose(output_file);
   3.142 +    /* always cleanup */
   3.143 +    curl_easy_cleanup(curl);
   3.144 +  }
   3.145 +
   3.146 +}
   3.147 +
   3.148 +
   3.149 +void PlaceNameToLonLat::ParseXMLYahoo()
   3.150 +{
   3.151 +  TiXmlDocument doc( "out.xml" );
   3.152 +  doc.LoadFile();
   3.153 +  TiXmlHandle docHandle( &doc );
   3.154 +
   3.155 +  TiXmlElement* childLat = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Latitude" ).Element();
   3.156 +  if ( childLat )
   3.157 +  {
   3.158 +    m_Lat=atof(childLat->GetText());
   3.159 +  }
   3.160 +  TiXmlElement* childLon = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Longitude" ).Element();
   3.161 +  if ( childLon )
   3.162 +  {
   3.163 +    m_Lon=atof(childLon->GetText());
   3.164 +  }
   3.165 +
   3.166 +}
   3.167 +
   3.168 +void PlaceNameToLonLat::ParseXMLGoogle()
   3.169 +{
   3.170 +  TiXmlDocument doc( "out.xml" );
   3.171 +  doc.LoadFile();
   3.172 +  TiXmlHandle docHandle( &doc );
   3.173 +
   3.174 +  TiXmlElement* childLat = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "latitude" ).Element();
   3.175 +  if ( childLat )
   3.176 +  {
   3.177 +    m_Lat=atof(childLat->GetText());
   3.178 +  }
   3.179 +  TiXmlElement* childLon = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "longitude" ).Element();
   3.180 +  if ( childLon )
   3.181 +  {
   3.182 +    m_Lon=atof(childLon->GetText());
   3.183 +  }
   3.184 +
   3.185 +}
   3.186 +void PlaceNameToLonLat::ParseXMLGeonames()
   3.187 +{
   3.188 +
   3.189 +}
   3.190 +
   3.191 +} // namespace otb
     4.1 --- a/Code/Projections/otbPlaceNameToLonLat.h	Thu Jul 02 17:41:46 2009 +0800
     4.2 +++ b/Code/Projections/otbPlaceNameToLonLat.h	Thu Jul 02 17:45:27 2009 +0800
     4.3 @@ -80,8 +80,5 @@
     4.4  
     4.5  } // namespace otb
     4.6  
     4.7 -#ifndef OTB_MANUAL_INSTANTIATION
     4.8 -#include "otbPlaceNameToLonLat.txx"
     4.9 -#endif
    4.10  
    4.11  #endif
     5.1 --- a/Code/Projections/otbPlaceNameToLonLat.txx	Thu Jul 02 17:41:46 2009 +0800
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,192 +0,0 @@
     5.4 -/*=========================================================================
     5.5 -
     5.6 -  Program:   ORFEO Toolbox
     5.7 -  Language:  C++
     5.8 -  Date:      $Date$
     5.9 -  Version:   $Revision$
    5.10 -
    5.11 -
    5.12 -  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
    5.13 -  See OTBCopyright.txt for details.
    5.14 -
    5.15 -
    5.16 -     This software is distributed WITHOUT ANY WARRANTY; without even
    5.17 -     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    5.18 -     PURPOSE.  See the above copyright notices for more information.
    5.19 -
    5.20 -=========================================================================*/
    5.21 -#ifndef __otbPlaceNameToLonLat_txx
    5.22 -#define __otbPlaceNameToLonLat_txx
    5.23 -
    5.24 -#include "otbPlaceNameToLonLat.h"
    5.25 -#include "tinyxml.h"
    5.26 -#include <curl/curl.h>
    5.27 -
    5.28 -
    5.29 -namespace otb
    5.30 -{
    5.31 -
    5.32 -/**
    5.33 -   * Constructor
    5.34 -   */
    5.35 -
    5.36 -PlaceNameToLonLat::PlaceNameToLonLat()
    5.37 -{
    5.38 -  m_Lon = -1000.0;
    5.39 -  m_Lat = -1000.0;
    5.40 -  m_PlaceName = "Where everything started";
    5.41 -}
    5.42 -
    5.43 -/**
    5.44 -   *
    5.45 -   */
    5.46 -
    5.47 -void
    5.48 -PlaceNameToLonLat
    5.49 -::PrintSelf(std::ostream& os, itk::Indent indent) const
    5.50 -{
    5.51 -  this->Superclass::PrintSelf(os,indent);
    5.52 -  os << indent << " m_Lon "  << m_Lon << std::endl;
    5.53 -  os << indent << " m_Lat "  << m_Lat << std::endl;
    5.54 -  os << indent << " m_PlaceName "  << m_PlaceName << std::endl;
    5.55 -}
    5.56 -
    5.57 -
    5.58 -bool PlaceNameToLonLat::Evaluate()
    5.59 -{
    5.60 -  std::string::size_type loc = m_PlaceName.find(" ", 0 );
    5.61 -  while (loc != std::string::npos)
    5.62 -  {
    5.63 -    m_PlaceName.replace(loc, 1, "+");
    5.64 -    loc = m_PlaceName.find(" ", loc);
    5.65 -  }
    5.66 -
    5.67 -  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    5.68 -  {
    5.69 -    std::ostringstream urlStream;
    5.70 -    urlStream << "http://maps.google.com/maps?q=";
    5.71 -    urlStream << m_PlaceName;
    5.72 -    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";
    5.73 -    RetrieveXML(urlStream);
    5.74 -    ParseXMLGoogle();
    5.75 -  }
    5.76 -
    5.77 -  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    5.78 -  {
    5.79 -    std::ostringstream urlStream;
    5.80 -    urlStream << "http://api.local.yahoo.com/MapsService/V1/geocode?appid=com.sun.blueprints.ui.geocoder&location=";
    5.81 -    urlStream << m_PlaceName;
    5.82 -    RetrieveXML(urlStream);
    5.83 -    ParseXMLYahoo();
    5.84 -  }
    5.85 -
    5.86 -  if ((m_Lat == -1000.0) && (m_Lon == -1000.0))
    5.87 -  {
    5.88 -    std::cout << "Search Error: fallback on the origin" << std::endl;
    5.89 -    m_Lat = 43.560204;
    5.90 -    m_Lon = 1.480736;
    5.91 -    return false;
    5.92 -  }
    5.93 -  return true;
    5.94 -}
    5.95 -
    5.96 -/*
    5.97 -//This method will be necessary to process the file directly in memory
    5.98 -//without writing it to the disk. Waiting for the xml lib to handle that
    5.99 -//also
   5.100 -static size_t
   5.101 -curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
   5.102 -  void *data)
   5.103 -{
   5.104 -  register int realsize = (int)(size * nmemb);
   5.105 -
   5.106 -  std::vector<char> *vec
   5.107 -    = static_cast<std::vector<char>*>(data);
   5.108 -  const char* chPtr = static_cast<char*>(ptr);
   5.109 -  vec->insert(vec->end(), chPtr, chPtr + realsize);
   5.110 -
   5.111 -  return realsize;
   5.112 -}
   5.113 -*/
   5.114 -
   5.115 -void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
   5.116 -{
   5.117 -
   5.118 -  CURL *curl;
   5.119 -  CURLcode res;
   5.120 -
   5.121 -  FILE* output_file = fopen("out.xml","w");
   5.122 -  curl = curl_easy_init();
   5.123 -
   5.124 -//   std::cout << "URL data " << urlStream.str().data() << std::endl;
   5.125 -
   5.126 -
   5.127 -  char url[256];
   5.128 -  strcpy(url,urlStream.str().data());
   5.129 -
   5.130 -//   std::cout << url << std::endl;
   5.131 -  if (curl)
   5.132 -  {
   5.133 -    std::vector<char> chunk;
   5.134 -    curl_easy_setopt(curl, CURLOPT_URL, url);
   5.135 -    /*
   5.136 -    //Step needed to handle curl without temporary file
   5.137 -    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,this->curlHandlerWriteMemoryCallback);
   5.138 -    curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
   5.139 -    */
   5.140 -    curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
   5.141 -    res = curl_easy_perform(curl);
   5.142 -
   5.143 -    fclose(output_file);
   5.144 -    /* always cleanup */
   5.145 -    curl_easy_cleanup(curl);
   5.146 -  }
   5.147 -
   5.148 -}
   5.149 -
   5.150 -
   5.151 -void PlaceNameToLonLat::ParseXMLYahoo()
   5.152 -{
   5.153 -  TiXmlDocument doc( "out.xml" );
   5.154 -  doc.LoadFile();
   5.155 -  TiXmlHandle docHandle( &doc );
   5.156 -
   5.157 -  TiXmlElement* childLat = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Latitude" ).Element();
   5.158 -  if ( childLat )
   5.159 -  {
   5.160 -    m_Lat=atof(childLat->GetText());
   5.161 -  }
   5.162 -  TiXmlElement* childLon = docHandle.FirstChild( "ResultSet" ).FirstChild( "Result" ).FirstChild( "Longitude" ).Element();
   5.163 -  if ( childLon )
   5.164 -  {
   5.165 -    m_Lon=atof(childLon->GetText());
   5.166 -  }
   5.167 -
   5.168 -}
   5.169 -
   5.170 -void PlaceNameToLonLat::ParseXMLGoogle()
   5.171 -{
   5.172 -  TiXmlDocument doc( "out.xml" );
   5.173 -  doc.LoadFile();
   5.174 -  TiXmlHandle docHandle( &doc );
   5.175 -
   5.176 -  TiXmlElement* childLat = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "latitude" ).Element();
   5.177 -  if ( childLat )
   5.178 -  {
   5.179 -    m_Lat=atof(childLat->GetText());
   5.180 -  }
   5.181 -  TiXmlElement* childLon = docHandle.FirstChild( "kml" ).FirstChild( "Placemark" ).FirstChild( "LookAt" ).FirstChild( "longitude" ).Element();
   5.182 -  if ( childLon )
   5.183 -  {
   5.184 -    m_Lon=atof(childLon->GetText());
   5.185 -  }
   5.186 -
   5.187 -}
   5.188 -void PlaceNameToLonLat::ParseXMLGeonames()
   5.189 -{
   5.190 -
   5.191 -}
   5.192 -
   5.193 -} // namespace otb
   5.194 -
   5.195 -#endif