osgEarth upgrade

classic Classic list List threaded Threaded
4 messages Options
raphael raphael
Reply | Threaded
Open this post in threaded view
|

osgEarth upgrade

Hi,
I used to run a previsous version of osgEarth. I would like to upgrade it, but I have troubles:
1) when using yahoo_maps.earth, I have a message "Couldn't get tile for 0_0_0_0" "Couldn't get tile for 0_0_1_0", and no data is displayed
2) I wrote a virtual earth plugin that used to work. It looks pretty much like the yahoo plugin.
In the previous version, I created a profile like this
  const Profile* createProfile( const Profile* mapProfile, const std::string& configPath )
   {
        return osgEarth::Registry::instance()->getGlobalMercatorProfile();
}
now, would it be
 setProfile( Profile::create( "spherical-mercator", 2, 2 ) ); like yahoo ???
   
Here is the code

#include <osgEarth/TileSource>
#include <osgEarth/Registry>

#include <osg/Notify>
#include <osgDB/FileNameUtils>
#include <osgDB/FileUtils>
#include <osgDB/Registry>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>

#include <sstream>

using namespace osgEarth;

#define PROPERTY_DATASET    "dataset"
#define PROPERTY_VERSION    "version"
#define PROPERTY_LANGUAGE   "language"

class VirtualEarthSource : public TileSource
{
public:
    VirtualEarthSource( const PluginOptions* options ) :
      TileSource( options )
    {
        if ( options )
        {
            if ( options->getPluginData( PROPERTY_DATASET ) )
                dataset = std::string( (const char*)options->getPluginData( PROPERTY_DATASET ) );

            if ( options->getPluginData( PROPERTY_VERSION ) )
                version = std::string( (const char*)options->getPluginData( PROPERTY_VERSION ) );

            if ( options->getPluginData( PROPERTY_LANGUAGE ) )
                language = std::string( (const char*)options->getPluginData( PROPERTY_LANGUAGE ) );
            else
                language = "en";
        }

        // validate dataset
        if ( dataset.empty() ) dataset = "aerial"; // default to the aerial view
    }

    void initialize( const std::string& referenceURI, const Profile* overrideProfile)
    {
                setProfile( Profile::create( "spherical-mercator", 2, 2 ) );
    }

    //const Profile* createProfile( const Profile* mapProfile, const std::string& configPath )
   // {
   //     return osgEarth::Registry::instance()->getGlobalMercatorProfile();
   // }

        void VirtualEarthSource::VEtileName(int x, int y, unsigned int z, char * b)
        {
                std::stringstream ss;
                int c = 23 - z;
                b[c] = '\0';
                while (z++ < 23)
                {
                        c--;
                        if (x % 2)
                        {
                                if (y % 2)
                                        b[c] = '3';
                                else
                                        b[c] = '1';
                        }
                        else
                        {
                                if (y % 2)
                                        b[c] = '2';
                                else
                                        b[c] = '0';
                        }
                        x/=2;
                        y/=2;
                }
        }

    osg::Image* createImage( const TileKey* key,
                             ProgressCallback* progress )
    {
        // If we are given a geodetic key, resample the mercator imagery. Some quality
        // loss will result

        //Return NULL if we are given a non-mercator key
        if ( !key->isMercator() ) return 0;

        std::stringstream buf;
        unsigned int tile_x, tile_y;
        key->getTileXY( tile_x, tile_y );
        int zoom = key->getLevelOfDetail();
                char cname[23];
                VEtileName(tile_x, tile_y, 23-zoom, cname);
                std::string name(cname);

        if ( dataset == "aerial" )
        {            
                        buf << "http://tiles.virtualearth.net/tiles/a"
                                << name
                                << "."
                                << "jpg"
                                << "?g=" << 15
                                << "&.jpg";
        }
        else if ( dataset == "road" )
        {
                        buf << "http://tiles.virtualearth.net/tiles/r"
                                << name
                                << "."
                                << "png"
                                << "?g=" << 15
                                << "&.png";
        }
        else if ( dataset == "hybrid" )
        {
                        buf << "http://tiles.virtualearth.net/tiles/h"
                                << name
                                << "."
                                << "jpg"
                                << "?g=" << 15
                                << "&.jpg";
        }
                std::string base;
                base = buf.str();

        osg::notify(osg::INFO) << key->str() << "=" << base << std::endl;
        osg::ref_ptr<osg::Image> image;
        HTTPClient::readImageFile( base, image, getOptions(), progress );
        return image.release();
       // return osgDB::readImageFile ( buf.str(), getOptions());
    }

    osg::HeightField* createHeightField( const TileKey* key )
    {
        //TODO
        return NULL;
    }

    virtual std::string getExtension()  const
    {
        if ( dataset == "aerial" ) return "jpg";
        else if ( dataset == "road" ) return "png";
        else if ( dataset == "hybrid" ) return "jpg";
        else return "";
    }

private:
    std::string dataset;
    std::string version;
    std::string language;
};


class ReaderWriterVirtualEarth : public osgDB::ReaderWriter
{
    public:
        ReaderWriterVirtualEarth()
        {
            supportsExtension( "osgearth_virtual_earth", "Virtual Earth maps imagery" );
        }

        virtual const char* className()
        {
            return "Virtual Earth Imagery ReaderWriter";
        }

        virtual ReadResult readObject(const std::string& file_name, const Options* options) const
        {
            if ( !acceptsExtension(osgDB::getLowerCaseFileExtension( file_name )))
                        {
                return ReadResult::FILE_NOT_HANDLED;
                        }
            return new VirtualEarthSource(static_cast<const PluginOptions*>(options));
        }
};

REGISTER_OSGPLUGIN(osgearth_virtual_earth, ReaderWriterVirtualEarth)
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: osgEarth upgrade

Hi Raphael,

The yahoo maps example seems to be working fine for me.  Make sure you
don't have any old versions of the plugins laying around.  And you are
correct, for your VE driver you will need to provide an initialize
function that sets the profile to spherical-mercator, just like Yahoo.

Thanks,

Jason

On Thu, Feb 18, 2010 at 5:07 AM, raphael [via osgEarth]
<[hidden email]> wrote:

> Hi,
> I used to run a previsous version of osgEarth. I would like to upgrade it,
> but I have troubles:
> 1) when using yahoo_maps.earth, I have a message "Couldn't get tile for
> 0_0_0_0" "Couldn't get tile for 0_0_1_0", and no data is displayed
> 2) I wrote a virtual earth plugin that used to work. It looks pretty much
> like the yahoo plugin.
> In the previous version, I created a profile like this
>   const Profile* createProfile( const Profile* mapProfile, const
> std::string& configPath )
>    {
>         return osgEarth::Registry::instance()->getGlobalMercatorProfile();
> }
> now, would it be
>  setProfile( Profile::create( "spherical-mercator", 2, 2 ) ); like yahoo ???
>
> Here is the code
>
> #include <osgEarth/TileSource>
> #include <osgEarth/Registry>
>
> #include <osg/Notify>
> #include <osgDB/FileNameUtils>
> #include <osgDB/FileUtils>
> #include <osgDB/Registry>
> #include <osgDB/ReadFile>
> #include <osgDB/WriteFile>
>
> #include <sstream>
>
> using namespace osgEarth;
>
> #define PROPERTY_DATASET    "dataset"
> #define PROPERTY_VERSION    "version"
> #define PROPERTY_LANGUAGE   "language"
>
> class VirtualEarthSource : public TileSource
> {
> public:
>     VirtualEarthSource( const PluginOptions* options ) :
>       TileSource( options )
>     {
>         if ( options )
>         {
>             if ( options->getPluginData( PROPERTY_DATASET ) )
>                 dataset = std::string( (const char*)options->getPluginData(
> PROPERTY_DATASET ) );
>
>             if ( options->getPluginData( PROPERTY_VERSION ) )
>                 version = std::string( (const char*)options->getPluginData(
> PROPERTY_VERSION ) );
>
>             if ( options->getPluginData( PROPERTY_LANGUAGE ) )
>                 language = std::string( (const char*)options->getPluginData(
> PROPERTY_LANGUAGE ) );
>             else
>                 language = "en";
>         }
>
>         // validate dataset
>         if ( dataset.empty() ) dataset = "aerial"; // default to the aerial
> view
>     }
>
>     void initialize( const std::string& referenceURI, const Profile*
> overrideProfile)
>     {
>                 setProfile( Profile::create( "spherical-mercator", 2, 2 ) );
>     }
>
>     //const Profile* createProfile( const Profile* mapProfile, const
> std::string& configPath )
>    // {
>    //     return osgEarth::Registry::instance()->getGlobalMercatorProfile();
>    // }
>
>         void VirtualEarthSource::VEtileName(int x, int y, unsigned int z,
> char * b)
>         {
>                 std::stringstream ss;
>                 int c = 23 - z;
>                 b[c] = '\0';
>                 while (z++ < 23)
>                 {
>                         c--;
>                         if (x % 2)
>                         {
>                                 if (y % 2)
>                                         b[c] = '3';
>                                 else
>                                         b[c] = '1';
>                         }
>                         else
>                         {
>                                 if (y % 2)
>                                         b[c] = '2';
>                                 else
>                                         b[c] = '0';
>                         }
>                         x/=2;
>                         y/=2;
>                 }
>         }
>
>     osg::Image* createImage( const TileKey* key,
>                              ProgressCallback* progress )
>     {
>         // If we are given a geodetic key, resample the mercator imagery.
> Some quality
>         // loss will result
>
>         //Return NULL if we are given a non-mercator key
>         if ( !key->isMercator() ) return 0;
>
>         std::stringstream buf;
>         unsigned int tile_x, tile_y;
>         key->getTileXY( tile_x, tile_y );
>         int zoom = key->getLevelOfDetail();
>                 char cname[23];
>                 VEtileName(tile_x, tile_y, 23-zoom, cname);
>                 std::string name(cname);
>
>         if ( dataset == "aerial" )
>         {
>                         buf << "http://tiles.virtualearth.net/tiles/a"
>                                 << name
>                                 << "."
>                                 << "jpg"
>                                 << "?g=" << 15
>                                 << "&.jpg";
>         }
>         else if ( dataset == "road" )
>         {
>                         buf << "http://tiles.virtualearth.net/tiles/r"
>                                 << name
>                                 << "."
>                                 << "png"
>                                 << "?g=" << 15
>                                 << "&.png";
>         }
>         else if ( dataset == "hybrid" )
>         {
>                         buf << "http://tiles.virtualearth.net/tiles/h"
>                                 << name
>                                 << "."
>                                 << "jpg"
>                                 << "?g=" << 15
>                                 << "&.jpg";
>         }
>                 std::string base;
>                 base = buf.str();
>
>         osg::notify(osg::INFO) << key->str() << "=" << base << std::endl;
>         osg::ref_ptr<osg::Image> image;
>         HTTPClient::readImageFile( base, image, getOptions(), progress );
>         return image.release();
>        // return osgDB::readImageFile ( buf.str(), getOptions());
>     }
>
>     osg::HeightField* createHeightField( const TileKey* key )
>     {
>         //TODO
>         return NULL;
>     }
>
>     virtual std::string getExtension()  const
>     {
>         if ( dataset == "aerial" ) return "jpg";
>         else if ( dataset == "road" ) return "png";
>         else if ( dataset == "hybrid" ) return "jpg";
>         else return "";
>     }
>
> private:
>     std::string dataset;
>     std::string version;
>     std::string language;
> };
>
>
> class ReaderWriterVirtualEarth : public osgDB::ReaderWriter
> {
>     public:
>         ReaderWriterVirtualEarth()
>         {
>             supportsExtension( "osgearth_virtual_earth", "Virtual Earth maps
> imagery" );
>         }
>
>         virtual const char* className()
>         {
>             return "Virtual Earth Imagery ReaderWriter";
>         }
>
>         virtual ReadResult readObject(const std::string& file_name, const
> Options* options) const
>         {
>             if ( !acceptsExtension(osgDB::getLowerCaseFileExtension(
> file_name )))
>                         {
>                 return ReadResult::FILE_NOT_HANDLED;
>                         }
>             return new VirtualEarthSource(static_cast<const
> PluginOptions*>(options));
>         }
> };
>
> REGISTER_OSGPLUGIN(osgearth_virtual_earth, ReaderWriterVirtualEarth)
>
>
> ________________________________
> View message @ http://n2.nabble.com/osgEarth-upgrade-tp4590925p4590925.html
> To start a new topic under osgEarth, email
> [hidden email]
> To unsubscribe from osgEarth, click here.
>
raphael raphael
Reply | Threaded
Open this post in threaded view
|

Re: osgEarth upgrade

I think I found the root cause. My company uses a proxy. With the previous version, the environment variable OSG_CURL_PROXY was correctly read. With the current version the HTTPClient readOptions method doesn't use OSG_CURL_PROXY because it doesn't enter a loop (while( iss >> opt ) is never entered).
Maybe it is a configuration mistake from me.
raphael raphael
Reply | Threaded
Open this post in threaded view
|

Re: osgEarth upgrade

I checked the open tickets and I guess my problems are related to tickets 81 / 82.