How to create WFS layer in version 3.0?

classic Classic list List threaded Threaded
3 messages Options
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

How to create WFS layer in version 3.0?

This post was updated on .
Hi, I am trying to load a WFS layer from Geoserver.
I was able to load the features as featureNode using the osgEarth_wfs example, but I can not make it work on a FeatureModelLayer.

here is my code:
       
// Create the WFS driver:
        WFSFeatureSource* wfs = new WFSFeatureSource();
        wfs->options().url() = osgEarth::URI("http://93.187.166.52:8081/geoserver/wfs");
        wfs->options().typeName() = "Armenia:Drought";
        wfs->options().outputFormat() = "gml2";

        if (wfs->open().isError())
        {
            std::cout << wfs->getStatus().message() << std::endl;
            return -1;
        }

        FeatureModelLayer* layer = new FeatureModelLayer();
        layer->setFeatureSource(wfs);

        StyleSheet* styleSheet = new StyleSheet();
        Style style;
        style.getOrCreate<AltitudeSymbol>()->clamping() = AltitudeSymbol::CLAMP_TO_TERRAIN;
        style.getOrCreate<AltitudeSymbol>()->technique() = AltitudeSymbol::TECHNIQUE_DRAPE;
        style.getOrCreate<LineSymbol>()->stroke()->color() = osgEarth::Color (1.0, 0, 0, 0);
        style.getOrCreate<LineSymbol>()->stroke()->width() = 2;
        styleSheet->addStyle(style);
        layer->setStyleSheet(styleSheet);
        mapNode->getMap()->addLayer(layer);

Is it a wrong manner to load a WFS layer, or just a bug?
MCA4213 MCA4213
Reply | Threaded
Open this post in threaded view
|

Re: How to create WFS layer in version 3.0?

Sorry, I just try another server (local one) with the latest master brunch and it works, so it should be somewhere my fault.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: How to create WFS layer in version 3.0?

Glad it works.
In the future, you can (should) use the new API for layers, e.g.

wfs->setURL()
wfs->setTypeName()
wfs->setOutputFormat()

We want to discourage the use of options() structures directly.
Glenn Waldron / Pelican Mapping