style information is missing in .earth file of map

classic Classic list List threaded Threaded
2 messages Options
Ya Hu Ya Hu
Reply | Threaded
Open this post in threaded view
|

style information is missing in .earth file of map

Hi,I want to get style information of map in the .earth file by the following code:
//////////////////////////////////////////////////////////////////

#include <osg/Notify>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgEarth/Map>
#include <osgEarth/MapNode>
#include <osgEarth/EarthFile>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler>

#include <osgEarthSymbology/Style>
#include <osgEarthSymbology/GeometrySymbol>

#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthDrivers/agglite/AGGLiteOptions>
#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>

using namespace osgEarth;
using namespace osgEarth::Features;
using namespace osgEarth::Drivers;
using namespace osgEarth::Symbology;
using namespace osgEarthUtil;

//
// NOTE: run this sample from the repo/tests directory.
//
int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);

    osgViewer::Viewer viewer(arguments);

    // Start by creating the map:
    Map* map = new Map();

        map->setName("styles");


    GDALOptions* basemapOpt = new GDALOptions();
    basemapOpt->url() = "F:/osgEarth/osgEarthData/world.tif";
    map->addMapLayer( new ImageMapLayer( "basemap", basemapOpt ) );
        //basemapOpt->


    OGRFeatureOptions* featureOpt = new OGRFeatureOptions();
    //featureOpt->url() = "F:/osgEarth/osgEarthData/world.shp";

        featureOpt->url() = "F:/osgEarth/osgEarthData/world.shp";

    // vectors as lines, configure the line symbolizer:
    Style* p1 = new Style;
        p1->setName("p1");

        PolygonSymbol* p11 = new PolygonSymbol;
        p11->fill()->color()=osg::Vec4f( 0,0,0,1 );  
        p1->addSymbol(p11);

        StyleSelector selector1;
        selector1.name()="p1";
        selector1.query()->expression()="POP_CNTRY <= 14045470";

    Style* p2 = new Style;
        p2->setName("p2");

        PolygonSymbol* p22 = new PolygonSymbol;
        p22->fill()->color()=osg::Vec4f( 1,0,0,1 );  
        p2->addSymbol(p22);

        StyleSelector selector2;
        selector2.name()="p2";
        selector2.query()->expression()="POP_CNTRY > 14045470 and POP_CNTRY <= 43410900";

    Style* p3 = new Style;
        p3->setName("p3");

        PolygonSymbol* p33 = new PolygonSymbol;
        p33->fill()->color()=osg::Vec4f( 0,1,0,1 );  
        p3->addSymbol(p33);

        StyleSelector selector3;
        selector3.name()="p3";
        selector3.query()->expression()="POP_CNTRY > 43410900 and POP_CNTRY <= 97228750";

    Style* p4 = new Style;
        p4->setName("p4");

        PolygonSymbol* p44 = new PolygonSymbol;
        p44->fill()->color()=osg::Vec4f( 0,0,1,1 );  
        p4->addSymbol(p44);

        StyleSelector selector4;
        selector4.name()="p4";
        selector4.query()->expression()="POP_CNTRY > 97228750 and POP_CNTRY <= 258833000";

    Style* p5 = new Style;
        p5->setName("p5");

        PolygonSymbol* p55 = new PolygonSymbol;
        p55->fill()->color()=osg::Vec4f( 1,1,0,1 );  
        p5->addSymbol(p55);

        StyleSelector selector5;
        selector5.name()="p5";
        selector5.query()->expression()="POP_CNTRY > 258833000";

        osgEarth::Drivers::FeatureGeomModelOptions* opt = new osgEarth::Drivers::FeatureGeomModelOptions();

    opt->featureOptions() = featureOpt;

        opt->styles()->addStyle( p1);
        opt->styles()->addStyle( p2 );
        opt->styles()->addStyle( p3 );
        opt->styles()->addStyle( p4 );
        opt->styles()->addStyle( p5 );

        opt->styles()->selectors().push_back(selector1);
        opt->styles()->selectors().push_back(selector2);
        opt->styles()->selectors().push_back(selector3);
        opt->styles()->selectors().push_back(selector4);
        opt->styles()->selectors().push_back(selector5);


        map->addModelLayer(new osgEarth::ModelLayer("stylesTest", opt));

        std::string outfile="test1.earth";

    EarthFile earthWriter;
    earthWriter.setMap( map );

        earthWriter.writeXML( outfile );


        return 0;
}
////////////////////////////////////////////////////////////////////////

when I open "test1.earth" file,the content of "style" sub-elements is empty,the color information is missing. The following is the content

of "test1.earth" file:
/////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<map name="styles" type="geocentric">
    <engine_properties>
       
    </engine_properties>
    <image driver="gdal" name="basemap">
        <url>
            F:/osgEarth/osgEarthData/world.tif
        </url>
    </image>
    <model driver="feature_geom" name="stylesTest">
        <features driver="ogr" name="">
            <url>
                F:/osgEarth/osgEarthData/world.shp
            </url>
        </features>
        <styles>
            <selector>
                <name>
                    p1
                </name>
                <query>
                    <expr>
                       
<![CDATA[POP_CNTRY <= 14045470]]>

                    </expr>
                </query>
            </selector>
            <selector>
                <name>
                    p2
                </name>
                <query>
                    <expr>
                       
<![CDATA[POP_CNTRY > 14045470 and POP_CNTRY <= 43410900]]>

                    </expr>
                </query>
            </selector>
            <selector>
                <name>
                    p3
                </name>
                <query>
                    <expr>
                       
<![CDATA[POP_CNTRY > 43410900 and POP_CNTRY <= 97228750]]>

                    </expr>
                </query>
            </selector>
            <selector>
                <name>
                    p4
                </name>
                <query>
                    <expr>
                       
<![CDATA[POP_CNTRY > 97228750 and POP_CNTRY <= 258833000]]>

                    </expr>
                </query>
            </selector>
            <selector>
                <name>
                    p5
                </name>
                <query>
                    <expr>
                        POP_CNTRY > 258833000
                    </expr>
                </query>
            </selector>
            <style name="p1"> </style>            <style name="p2"> </style>            <style name="p3"> </style>            <style name="p4"> </style>            <style name="p5"> </style>        </styles>
    </model>
</map>
/////////////////////////////////////////////////////////////////////////////

I want to get the color information in the "style" sub-elements of .earth file, How can I do?

Thanks !:)

Ya Hu
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: style information is missing in .earth file of map

Ya Hu,

This is because serialization of Symbols is not yet implemented. I have entered a todo ticket for this here:
http://www.osgearth.org/ticket/185

Glenn
Glenn Waldron / Pelican Mapping