Skip to content
Snippets Groups Projects
Commit 721b37c2 authored by Julien Michel's avatar Julien Michel
Browse files

MRG

parents 9df9f2df 529a4919
Branches
Tags
No related merge requests found
......@@ -24,6 +24,8 @@
#include <cstring>
#endif
#include <cstdio>
namespace otb
{
......@@ -35,13 +37,9 @@ int CurlHelper::TestUrlAvailability(const std::string& url) const
CURLcode res = CURL_LAST;
curl = curl_easy_init();
// Set up the browser
std::string browser =
"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11";
if (curl)
{
curl_easy_setopt(curl, CURLOPT_USERAGENT, browser.data());
curl_easy_setopt(curl, CURLOPT_USERAGENT, m_Browser.data());
curl_easy_setopt(curl, CURLOPT_URL, url.data());
// Set the dummy write function
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::curlDummyWriteFunction);
......@@ -69,26 +67,32 @@ int CurlHelper::RetrieveFile(const std::string& urlString, std::string filename)
CURLcode res = CURL_LAST;
FILE* output_file = fopen(filename.c_str(), "w");
curl = curl_easy_init();
char url[256];
strcpy(url, urlString.data());
strcpy(url, urlString.c_str());
// std::cout << url << std::endl;
if (curl)
{
std::vector<char> chunk;
curl_easy_setopt(curl, CURLOPT_URL, url);
// Set 5s timeout
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 5);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, output_file);
// Use our writing static function to avoid file descriptor
// pointer crash on windows
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &Self::write_data);
// Say the file where to write the received data
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void*)output_file);
res = curl_easy_perform(curl);
fclose(output_file);
/* always cleanup */
curl_easy_cleanup(curl);
fclose(output_file);
}
return res;
#else
......@@ -105,7 +109,6 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
#ifdef OTB_USE_CURL
#ifdef OTB_CURL_MULTI_AVAILABLE
otbMsgDevMacro(<< "Using curl multi");
std::string m_Browser = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11";
CURLM * multiHandle;
std::vector<CURL *> listCurlHandles;
......@@ -155,7 +158,8 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
// Param easy handle
curl_easy_setopt(lEasyHandle, CURLOPT_USERAGENT, m_Browser.data());
curl_easy_setopt(lEasyHandle, CURLOPT_URL, (*url).data());
curl_easy_setopt(lEasyHandle, CURLOPT_WRITEDATA, *file);
curl_easy_setopt(lEasyHandle, CURLOPT_WRITEFUNCTION, &Self::write_data);
curl_easy_setopt(lEasyHandle, CURLOPT_WRITEDATA, (void*)(*file));
// Add easy handle to multi handle
curl_multi_add_handle(multiHandle, lEasyHandle);
......@@ -166,7 +170,7 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
++file;
}
//fetch tiles
//fetch tiles
// Configure multi handle - set the maximum connections
curl_multi_setopt(multiHandle, CURLMOPT_MAXCONNECTS, maxConnect);
curl_multi_setopt(multiHandle, CURLMOPT_PIPELINING, 0);
......@@ -275,4 +279,15 @@ int CurlHelper::RetrieveFileMulti(const std::vector<std::string>& listURLs,
#endif
}
size_t CurlHelper::write_data(void* ptr, size_t size, size_t nmemb, void* data)
{
size_t written;
FILE * fDescriptor = (FILE *)(data);
written = fwrite(ptr,size,nmemb,fDescriptor);
return written;
}
}
......@@ -28,6 +28,10 @@ namespace otb
* \class CurlHelper
* \brief Class to use the curl capabilities from OTB
*
* This class is responsible for behaving properly when curl is
* not available, i.e. the compilation should pass, the runtime should
* not segfault but of course, the behaviour will be different.
*
*/
class ITK_EXPORT CurlHelper : public itk::Object
{
......@@ -49,7 +53,10 @@ public:
const std::vector<std::string>& listFiles,
int maxConnect) const;
protected:
CurlHelper() {}
CurlHelper() :
m_Browser("Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.8.1.11) "
"Gecko/20071127 Firefox/2.0.0.11")
{}
~CurlHelper() {}
......@@ -61,7 +68,14 @@ private:
{
return nmemb;
}
// Need to use our writing function to handle windows segfaults
// Need to be static cause the CURL_OPT is expecting a pure C
// function or a static c++ method.
static size_t write_data(void* ptr, size_t size, size_t nmemb, void* data);
// Browser Agent used
std::string m_Browser;
};
}
#endif
......@@ -602,6 +602,13 @@ void GDALImageIO::InternalReadImageInformation()
m_Origin[1] = VadfGeoTransform[3];
m_Spacing[0] = VadfGeoTransform[1];
m_Spacing[1] = VadfGeoTransform[5];
//In this case, we are in a geographic projection
// FIXME is there any way to know if we are in WGS 84 ???
std::string projRef =
"GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]]";
itk::EncapsulateMetaData<std::string>(dict, MetaDataKey::ProjectionRefKey, projRef);
}
/* -------------------------------------------------------------------- */
......
......@@ -391,7 +391,10 @@ ImageFileReader<TOutputImage>
//we need to pass the depth information which in on the IO to the projection
//to be handle throught the kwl
typename TileMapImageIO::Pointer imageIO = dynamic_cast<TileMapImageIO*>(this->GetImageIO());
dynamic_cast<ossimTileMapModel*>(projection)->setDepth(imageIO->GetDepth());
if(imageIO.IsNotNull())
{
dynamic_cast<ossimTileMapModel*>(projection)->setDepth(imageIO->GetDepth());
}
}
hasMetaData = projection->saveState(geom_kwl);
// delete projection; //FIXME find out where this should occur
......
......@@ -163,17 +163,20 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
{
OSRDestroySpatialReference(hSRS);
firstTransformGiveGeo = false;
otbMsgDevMacro(<< "- Considering that the first transform does not give geo (WKT)")
}
else if (static_cast<OGRSpatialReference *>(hSRS)->IsGeographic())
{
OSRDestroySpatialReference(hSRS);
firstTransformGiveGeo = true;
otbMsgDevMacro(<< "- Considering that the first transform gives geo")
}
else
{
OSRDestroySpatialReference(hSRS);
firstTransformGiveGeo = false;
otbMsgDevMacro(<< "- Considering that the first transform does not give geo (fallback)")
}
otbMsgDevMacro(<< "Input projection set to identity")
......@@ -237,12 +240,17 @@ GenericRSTransform<TScalarType, NInputDimensions, NOutputDimensions>
m_Transform->SetFirstTransform(m_InputTransform);
m_Transform->SetSecondTransform(m_OutputTransform);
m_TransformUpToDate = true;
//The acurracy information is a simplistic model for now and should be refined
//The accuracy information is a simplistic model for now and should be refined
if ((inputTransformIsSensor || outputTransformIsSensor) && (m_DEMDirectory.empty()))
{
//Sensor model without DEM
m_TransformAccuracy = Projection::ESTIMATE;
}
else if (firstTransformGiveGeo && !outputTransformIsSensor && !outputTransformIsMap)
{
//The original image was in lon/lat and we did not change anything
m_TransformAccuracy = Projection::PRECISE;
}
else if (!inputTransformIsSensor && !outputTransformIsSensor && !inputTransformIsMap && !outputTransformIsMap)
{
//no transform
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment