Commit 2ff3c668 authored by Emmanuel Christophe's avatar Emmanuel Christophe

ENH: Adding example to placename

parent f67ef40b
......@@ -49,11 +49,11 @@ public:
itkGetMacro( Lon, double );
itkGetMacro( Lat, double );
itkGetMacro( PlaceName, string );
itkGetMacro( PlaceName, std::string );
itkSetMacro( Lon, double );
itkSetMacro( Lat, double );
itkSetMacro( PlaceName, string );
itkSetMacro( PlaceName, std::string );
virtual bool Evaluate();
......@@ -71,7 +71,7 @@ private:
double m_Lon;
double m_Lat;
string m_PlaceName;
std::string m_PlaceName;
};
......
......@@ -54,8 +54,8 @@ PlaceNameToLonLat
bool PlaceNameToLonLat::Evaluate()
{
string::size_type loc = m_PlaceName.find(" ", 0 );
while (loc != string::npos)
std::string::size_type loc = m_PlaceName.find(" ", 0 );
while (loc != std::string::npos)
{
m_PlaceName.replace(loc, 1, "+");
loc = m_PlaceName.find(" ", loc);
......@@ -100,6 +100,21 @@ bool PlaceNameToLonLat::Evaluate()
return true;
}
static size_t
curlHandlerWriteMemoryCallback(void *ptr, size_t size, size_t nmemb,
void *data)
{
register int realsize = (int)(size * nmemb);
std::vector<char> *vec
= static_cast<std::vector<char>*>(data);
const char* chPtr = static_cast<char*>(ptr);
vec->insert(vec->end(), chPtr, chPtr + realsize);
return realsize;
}
void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
{
......@@ -109,7 +124,7 @@ void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
FILE* output_file = fopen("out.xml","w");
curl = curl_easy_init();
std::cout << "URL data " << urlStream.str().data() << std::endl;
// std::cout << "URL data " << urlStream.str().data() << std::endl;
char url[256];
......@@ -117,7 +132,13 @@ void PlaceNameToLonLat::RetrieveXML(std::ostringstream& urlStream)
// std::cout << url << std::endl;
if(curl) {
std::vector<char> chunk;
curl_easy_setopt(curl, CURLOPT_URL, url);
/*
//Step needed to handle curl without temporary file
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,this->curlHandlerWriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_FILE, (void *)&chunk);
*/
curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
res = curl_easy_perform(curl);
......
......@@ -18,6 +18,10 @@ TARGET_LINK_LIBRARIES(SensorModelExample OTBProjections OTBCommon OTBIO ITKCommo
ADD_EXECUTABLE(OrthoRectificationExample OrthoRectificationExample.cxx )
TARGET_LINK_LIBRARIES(OrthoRectificationExample OTBProjections OTBCommon OTBIO ITKCommon ITKIO)
IF( OTB_USE_CURL )
ADD_EXECUTABLE(PlaceNameToLonLat PlaceNameToLonLat.cxx )
TARGET_LINK_LIBRARIES(PlaceNameToLonLat OTBProjections OTBCommon OTBIO ITKCommon ITKIO ${CURL_LIBRARY} tinyXML)
ENDIF( OTB_USE_CURL )
IF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
......
/*=========================================================================
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.
=========================================================================*/
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#include "otbPlaceNameToLonLat.h"
int main( int argc, char* argv[] )
{
if(argc!=2)
{
std::cout << argv[0] <<" <place name> "
<< std::endl;
return EXIT_FAILURE;
}
otb::PlaceNameToLonLat::Pointer pn2LL = otb::PlaceNameToLonLat::New();
pn2LL->SetPlaceName(std::string(argv[1]));
pn2LL->Evaluate();
double lon = pn2LL->GetLon();
double lat = pn2LL->GetLat();
std::cout << "Latitude: " << lat << std::endl;
std::cout << "Longitude: " << lon << std::endl;
return EXIT_SUCCESS;
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment