osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/arcgis_map_cache/ReaderWriterArcGISMapCache.cpp

Go to the documentation of this file.
00001 /* -*-c++-*- */
00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
00003  * Copyright 2008-2010 Pelican Mapping
00004  * http://osgearth.org
00005  *
00006  * osgEarth is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program.  If not, see <http://www.gnu.org/licenses/>
00018  */
00019 
00020 #include <osgEarth/TileSource>
00021 #include <osgEarth/Registry>
00022 #include <osg/Notify>
00023 #include <osgDB/FileNameUtils>
00024 #include <osgDB/FileUtils>
00025 #include <osgDB/Registry>
00026 #include <osgDB/ReadFile>
00027 #include <osgDB/WriteFile>
00028 
00029 #include <sstream>
00030 #include <iomanip>
00031 
00032 using namespace osgEarth;
00033 
00034 #define PROPERTY_URL        "url"
00035 #define PROPERTY_MAP        "map"
00036 #define PROPERTY_LAYER      "layer"
00037 #define PROPERTY_FORMAT     "format"
00038 
00039 class AGSMapCacheSource : public TileSource
00040 {
00041 public:
00042     AGSMapCacheSource( const TileSourceOptions& options ) :
00043       TileSource( options )
00044     {
00045         const Config& conf = options.getConfig();
00046 
00047         // this is the AGS virtual directory pointing to the map cache
00048         _url = conf.value( PROPERTY_URL );
00049 
00050         // the name of the map service cache
00051         _map = conf.value( PROPERTY_MAP );
00052 
00053         // the layer, or null to use the fused "_alllayers" cache
00054         _layer = conf.value( PROPERTY_LAYER );
00055 
00056         // the image format (defaults to "png")
00057         // TODO: read this from the XML tile schema file
00058         _format = conf.value( PROPERTY_FORMAT );
00059 
00060         // validate dataset
00061         if ( _layer.empty() )
00062             _layer = "_alllayers"; // default to the AGS "fused view"
00063 
00064         if ( _format.empty() )
00065             _format = "png";
00066     }
00067 
00068     void initialize( const std::string& referenceURI, const Profile* overrideProfile)
00069     {
00070         //Set the profile to global geodetic.
00071         setProfile(osgEarth::Registry::instance()->getGlobalGeodeticProfile());
00072     }
00073 
00074     // override
00075     osg::Image* createImage( const TileKey& key, ProgressCallback* progress)
00076     {
00077         //If we are given a PlateCarreTileKey, use the MercatorTileConverter to create the image
00078         //if ( dynamic_cast<const PlateCarreTileKey&>( key ) )
00079         //{
00080         //    MercatorTileConverter converter( this );
00081         //    return converter.createImage( static_cast<const PlateCarreTileKey&>( key ) );
00082         //}
00083 
00084         std::stringstream buf;
00085 
00086         //int level = key.getLevelOfDetail();
00087         int level = key.getLevelOfDetail()-1;
00088 
00089         unsigned int tile_x, tile_y;
00090         key.getTileXY( tile_x, tile_y );
00091 
00092         buf << _url << "/" << _map 
00093             << "/Layers/" << _layer
00094             << "/L" << std::hex << std::setw(2) << std::setfill('0') << level
00095             << "/R" << std::hex << std::setw(8) << std::setfill('0') << tile_y
00096             << "/C" << std::hex << std::setw(8) << std::setfill('0') << tile_x << "." << _format;
00097 
00098         //OE_NOTICE << "Key = " << key.str() << ", URL = " << buf.str() << std::endl;
00099         //return osgDB::readImageFile( buf.str(), getOptions() );
00100         //return HTTPClient::readImageFile( buf.str(), getOptions(), progress);
00101         
00102         osg::ref_ptr<osg::Image> image;
00103                 std::string bufStr;
00104                 bufStr = buf.str();
00105         HTTPClient::readImageFile( bufStr, image, 0L, progress ); //getOptions(), progress );
00106         return image.release();
00107     }
00108 
00109     // override
00110     osg::HeightField* createHeightField( const TileKey& key,
00111                                          ProgressCallback* progress)
00112     {
00113         //TODO
00114         return NULL;
00115     }
00116 
00117     // override
00118     virtual std::string getExtension()  const 
00119     {
00120         return _format;
00121     }
00122 
00123 private:
00124     std::string _url;
00125     std::string _map;
00126     std::string _layer;
00127     std::string _format;
00128 };
00129 
00130 
00131 class ReaderWriterAGSMapCache : public TileSourceDriver
00132 {
00133     public:
00134         ReaderWriterAGSMapCache()
00135         {
00136             supportsExtension( "osgearth_arcgis_map_cache", "ArcGIS Server Map Service Cache" );
00137         }
00138 
00139         virtual const char* className()
00140         {
00141             return "ArcGIS Server Map Service Cache Imagery ReaderWriter";
00142         }
00143 
00144         virtual ReadResult readObject(const std::string& file_name, const Options* options) const
00145         {
00146             if ( !acceptsExtension(osgDB::getLowerCaseFileExtension( file_name )))
00147                 return ReadResult::FILE_NOT_HANDLED;
00148 
00149             return new AGSMapCacheSource( getTileSourceOptions(options) );
00150         }
00151 };
00152 
00153 REGISTER_OSGPLUGIN(osgearth_arcgis_map_cache, ReaderWriterAGSMapCache)
00154 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines