61 transform( str.begin(), str.end(), std::back_inserter(lower_url), ::tolower );
63 if ( str.size() < 9 ) {
65 std::string msg =
"Invalid identifier for remote raster (1).\n";
70 size_t prot_i = str.find(
"://");
72 if ( prot_i == string::npos ) {
74 std::string msg =
"Missing protocol in remote raster identifier.\n";
79 size_t path_i = str.find(
"/", prot_i+3);
81 if ( path_i == string::npos ) {
84 std::string msg =
"Invalid identifier for remote raster (2).\n";
89 host = lower_url.substr( prot_i+3, path_i - (prot_i+3) );
91 size_t port_i = host.find(
":");
93 if ( port_i != string::npos ) {
96 host = host.substr( 0, port_i );
101 for(
unsigned int i = 0; i < accepted_sources.size(); i++ ) {
104 if ( accepted_sources[i].compare(
"*") == 0 ) {
109 size_t pos = host.find( accepted_sources[i] );
111 if ( pos == string::npos ) {
116 if ( pos == host.size() - accepted_sources[i].size() ) {
155 Log::instance()->
debug(
"WCS proxy raster %s already present in local cache (%s)\n", str.c_str(), cache_id.c_str() );
159 Log::instance()->
debug(
"Setting up WCS proxy for %s (%s)\n", str.c_str(), cache_id.c_str() );
162 vector<string> tokens;
163 stringstream ss(str);
165 while ( getline(ss, token,
'>') ) {
167 tokens.push_back(token);
170 if ( tokens.size() != 3 ) {
172 std::string msg =
"Invalid WCS identifier. Make sure it has 3 parts separated by \">\".\n";
179 std::string msg =
"Untrusted source for WCS raster. Aborting operation.\n";
185 ostringstream oss (ostringstream::out);
186 oss<<
"<WCS_GDAL>"<<std::endl;
187 oss<<
"<ServiceURL>"<<tokens[1]<<
"</ServiceURL>"<<std::endl;
188 oss<<
"<CoverageName>"<<tokens[2]<<
"</CoverageName>"<<std::endl;
200 Log::instance()->
debug(
"openModeller configured to work with local copies of WCS rasters\n" );
202 std::string clone_id( cache_id );
203 clone_id.append(
".img");
205 std::string clone_ref( cached_ref );
206 clone_ref.append(
".img");
209 std::string lock_file = cache_id;
210 lock_file.append(
".lock");
228 std::string retries_file = cache_id;
229 retries_file.append(
".tries");
238 fin.open( retries_fullpath.c_str(), ios::in );
240 if ( fin.is_open() ) {
245 getline( fin, line );
249 num_retries = atoi( oss.str().c_str() );
255 throw RasterException(
"Could not determine number of previous download retries." );
258 if ( num_retries > 3 ) {
262 throw RasterException(
"Too many attempts to fetch raster. Aborting." );
276 ostringstream oss (ostringstream::out);
281 p_file = fopen( retries_fullpath.c_str(),
"w" );
283 if ( p_file == NULL ) {
286 throw RasterException(
"Could not store number of download retries." );
292 sprintf( buffer,
"%d", num_retries );
293 fputs( buffer, p_file );
303 GDALDatasetH hDataset = GDALOpen( cached_ref.c_str(), GA_ReadOnly );
304 if ( hDataset == NULL ) {
306 std::string msg =
"Failed to open WCS raster!\n";
311 GDALDriverH hDriver = GDALGetDriverByName(
"HFA" );
312 if ( hDriver == NULL ) {
314 GDALClose( hDataset );
315 GDALDestroyDriverManager();
317 std::string msg =
"Could not find GDAL HFA driver!\n";
323 GDALDatasetH hOutDS = GDALCreateCopy( hDriver, clone_ref.c_str(), hDataset, FALSE, NULL, NULL, NULL );
325 if ( hOutDS == NULL ) {
327 GDALClose( hDataset );
328 GDALDestroyDriverManager();
330 std::string msg =
"Could not clone WCS raster!\n";
336 GDALClose( hDataset );
366 Log::instance()->
debug(
"openModeller configured to work with remote WCS rasters\n" );
376 std::string msg =
"Method createRaster() not available to create writable WCS rasters.\n";
385 std::string msg =
"Method createRaster() not available to create writable WCS rasters.\n";
396 std::string msg =
"Method put() not available for WCS rasters.\n";
406 std::string msg =
"Method put() not available for WCS rasters.\n";
416 std::string msg =
"Method finish() not available for WCS rasters.\n";
426 std::string msg =
"Method deleteRaster() not available for WCS rasters.\n";
static std::vector< std::string > getAll(const std::string &key)
bool isFromRejectedSource(const std::string &str)
void warn(const char *format,...)
'Warn' level.
static std::string getContentIdMd5(const std::string id)
static bool isCached(const std::string id, const std::string subdir="")
static void cache(const std::string id, const std::ostringstream &content, const std::string subdir="")
static void cacheMd5(const std::string id, const std::ostringstream &content, const std::string subdir="")
double Scalar
Type of map values.
static Log * instance()
Returns the instance pointer, creating the object on the first call.
void createRaster(const std::string &str, int categ=0)
A common interface to rasters.
static std::string getContentLocation(const std::string id, const std::string subdir="")
#define OM_WCS_PROXY_SUBDIR
int put(Coord x, Coord y, Scalar val)
static std::string get(const std::string &key)
static int eraseCache(const std::string id, const std::string subdir="")
void error(const char *format,...)
'Error' level.
static bool isCachedMd5(const std::string id, const std::string subdir="")
static Raster * CreateRasterCallback()
static int count(const std::string &key)
void createRaster(const std::string &file, int categ=0)
double Coord
Type of map coordinates.
static std::string getContentLocationMd5(const std::string id, const std::string subdir="")
void debug(const char *format,...)
'Debug' level.