openModeller
Version 1.4.0
|
00001 00030 #include <openmodeller/env_io/RasterFactory.hh> 00031 #include <openmodeller/MapFormat.hh> 00032 00033 #include <algorithm> 00034 #include <string> 00035 using std::string; 00036 00037 bool RasterFactory::_initiated; 00038 00039 /****************/ 00040 /*** instance ***/ 00041 RasterFactory& 00042 RasterFactory::instance() 00043 { 00044 static RasterFactory _instance; 00045 00046 if ( ! _initiated ) { 00047 00048 #ifdef TERRALIB_FOUND 00049 _instance.registerDriver( "terralib", &TerralibRaster::CreateRasterCallback ); 00050 #endif 00051 00052 _instance.registerDriver( "wcs", &WcsProxyRaster::CreateRasterCallback ); 00053 00054 _initiated = true; 00055 } 00056 00057 return _instance; 00058 } 00059 00060 /***********************/ 00061 /*** register driver ***/ 00062 bool 00063 RasterFactory::registerDriver( const string& driverId, CreateRasterCallback builder ) 00064 { 00065 return _drivers.insert( DriversMap::value_type( driverId, builder ) ).second; 00066 } 00067 00068 /*************************/ 00069 /*** unregister driver ***/ 00070 bool 00071 RasterFactory::unregisterDriver( const string& driverId ) 00072 { 00073 return _drivers.erase( driverId ) != 0; 00074 } 00075 00076 /**************/ 00077 /*** create ***/ 00078 Raster* 00079 RasterFactory::create( const string& source, int categ ) 00080 { 00081 // Another Raster Lib 00082 int i = source.find( ">" ); 00083 00084 if ( i != -1 ) { 00085 00086 string driver_id = source.substr( 0, i ); 00087 00088 DriversMap::const_iterator i = _drivers.find( driver_id ); 00089 00090 if ( i != _drivers.end() ) { 00091 00092 Raster* r = (i->second)(); 00093 r->createRaster( source, categ ); 00094 return r; 00095 } 00096 } 00097 00098 #ifdef CURL_FOUND 00099 // Check if name starts with http://, https:// or ftp:// 00100 if ( source.size() > 6 ) { 00101 00102 string lower_source; 00103 transform( source.begin(), source.end(), std::back_inserter(lower_source), ::tolower ); 00104 00105 if ( lower_source.compare( 0, 7, "http://" ) == 0 || 00106 lower_source.compare( 0, 8, "https://" ) == 0 || 00107 lower_source.compare( 0, 6, "ftp://" ) == 0 ) { 00108 00109 Raster* r = new RemoteRaster(); 00110 r->createRaster( source, categ ); 00111 return r; 00112 } 00113 } 00114 #endif 00115 00116 // Default: GDAL Raster Lib 00117 Raster* r = new GdalRaster(); 00118 r->createRaster( source, categ ); 00119 return r; 00120 } 00121 00122 00123 #ifdef MPI_FOUND 00124 /**************/ 00125 /*** create ***/ 00126 Raster* 00127 RasterFactory::create( const string& output_file_source, const string& source, const MapFormat& format ) 00128 { 00129 // Another Raster Lib 00130 int i = source.find( ">" ); 00131 00132 if ( i != -1 ) { 00133 00134 string driver_id = source.substr( 0, i ); 00135 00136 DriversMap::const_iterator i = _drivers.find( driver_id ); 00137 00138 if ( i != _drivers.end() ) { 00139 00140 Raster* r = (i->second)(); 00141 r->createRaster( output_file_source, source, format ); 00142 return r; 00143 } 00144 } 00145 00146 #ifdef CURL_FOUND 00147 // Check if name starts with http://, https:// or ftp:// 00148 if ( source.size() > 6 ) { 00149 00150 string lower_source; 00151 transform( source.begin(), source.end(), std::back_inserter(lower_source), ::tolower ); 00152 00153 if ( lower_source.compare( 0, 7, "http://" ) == 0 || 00154 lower_source.compare( 0, 8, "https://" ) == 0 || 00155 lower_source.compare( 0, 6, "ftp://" ) == 0 ) { 00156 00157 Raster* r = new RemoteRaster(); 00158 r->createRaster( output_file_source, source, format ); 00159 return r; 00160 } 00161 } 00162 #endif 00163 00164 // Default: GDAL Raster Lib 00165 Raster* r = new GdalRaster(); 00166 r->createRaster( output_file_source, source, format ); 00167 return r; 00168 } 00169 #else 00170 /**************/ 00171 /*** create ***/ 00172 Raster* 00173 RasterFactory::create( const string& source, const MapFormat& format ) 00174 { 00175 // Another Raster Lib 00176 int i = source.find( ">" ); 00177 00178 if ( i != -1 ) { 00179 00180 string driver_id = source.substr( 0, i ); 00181 00182 DriversMap::const_iterator i = _drivers.find( driver_id ); 00183 00184 if ( i != _drivers.end() ) { 00185 00186 Raster* r = (i->second)(); 00187 r->createRaster( source, format ); 00188 return r; 00189 } 00190 } 00191 00192 #ifdef CURL_FOUND 00193 // Check if name starts with http://, https:// or ftp:// 00194 if ( source.size() > 6 ) { 00195 00196 string lower_source; 00197 transform( source.begin(), source.end(), std::back_inserter(lower_source), ::tolower ); 00198 00199 if ( lower_source.compare( 0, 7, "http://" ) == 0 || 00200 lower_source.compare( 0, 8, "https://" ) == 0 || 00201 lower_source.compare( 0, 6, "ftp://" ) == 0 ) { 00202 00203 Raster* r = new RemoteRaster(); 00204 r->createRaster( source, format ); 00205 return r; 00206 } 00207 } 00208 #endif 00209 00210 // Default: GDAL Raster Lib 00211 Raster* r = new GdalRaster(); 00212 r->createRaster( source, format ); 00213 return r; 00214 } 00215 #endif