osgEarth示例分析——osgearth_wfs

前言

osgearth_wfs示例,展示的如何创建wfs驱动,通过http服务加载wfs数据。

由于本示例中的链接无效,所以并没有执行出应有的效果。

关于wfs服务:

 WFS(Web Feature Service,Web 要素服务)服务,该服务符合 OGC(Open Geospatial Consortium,开放地理信息联盟)制定的 WFS 实现规范。WFS 通过 GML(Geography Markup Language,地理标记语言)传递地理空间数据,它支持在基于 HTTP 协议的分布式计算平台上对地理要素进行插入(INSERT)、更新(UPDATE)、删除(DELETE)和发现(DISCOVERY)等操作,并且在这些操作的过程中保证了地理数据变化的一致性。

 

代码分析

#include <osgViewer/Viewer>
#include <osgEarth/Notify>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/ExampleResources>

#include <osgEarth/Units>
#include <osgEarth/MapNode>

// include for WFS feature driver:
#include <osgEarthDrivers/feature_wfs/WFSFeatureOptions>

// include for feature geometry model renderer:
#include <osgEarthAnnotation/FeatureNode>
#include <osgEarthSymbology/Style>


#define LC "[wfs example] "

using namespace osgEarth;
using namespace osgEarth::Annotation;
using namespace osgEarth::Util;
using namespace osgEarth::Features;
using namespace osgEarth::Symbology;

int
usage(const char* name)
{
    OE_NOTICE 
        << "\nUsage: " << name << " file.earth" << std::endl
        << MapNodeHelper().usage() << std::endl;

    return 0;
}

int
main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc,argv);
    if ( arguments.read("--help") )
        return usage(argv[0]);

    // general setup:一般设置
    osgViewer::Viewer viewer(arguments);
    viewer.getDatabasePager()->setUnrefImageDataAfterApplyPolicy( false, false );
    viewer.setCameraManipulator( new EarthManipulator(arguments) );
    viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
    viewer.getCamera()->setNearFarRatio(0.00002);

    // Get the bounds from the command line.从命令窗口获取 --bounds值
    Bounds bounds;
    double xmin = DBL_MAX, ymin = DBL_MAX, xmax = DBL_MIN, ymax = DBL_MIN;
    while (arguments.read("--bounds", xmin, ymin, xmax, ymax))
    {
        bounds.xMin() = xmin, bounds.yMin() = ymin, bounds.xMax() = xmax, bounds.yMax() = ymax;
    }        

    // load an earth file, and support all or our example command-line options
    // and earth file <external> tags    
    osg::Node* node = MapNodeHelper().load( arguments, &viewer );
    if ( node )
    {        
        MapNode* mapNode = MapNode::get(node);
        if ( !mapNode )
            return usage(argv[0]);

        // Create the WFS driver: 创建WFS驱动
        osgEarth::Drivers::WFSFeatureOptions wfs;
        wfs.url()          = osgEarth::URI("http://demo.mapserver.org/cgi-bin/wfs"); 
        wfs.typeName()     = "cities"; 
        wfs.outputFormat() = "gml2";     // JSON or GML

		if (wfs.empty()) {
			return usage("wfs is empty!");
		}
        // Create the feature source from the options 创建特征源
        osg::ref_ptr< FeatureSource > featureSource = FeatureSourceFactory::create(wfs);
        Status s = featureSource->open();

        // Set the query with the bounds if one was specified.
        Query query;
        if (bounds.isValid())
        {
            query.bounds() = bounds;
        }

        // Get the features 获取特征
        osg::ref_ptr< FeatureCursor > cursor = featureSource->createFeatureCursor(query, 0L);
        FeatureList features;
        cursor->fill(features);
        OE_NOTICE << "Got " << features.size() << " features" << std::endl;

        // Create a style 创建文本风格
        Style style;
        style.getOrCreateSymbol<TextSymbol>()->content() = StringExpression("[NAME]");

        // Create the FeatureNode with the features and the style.
        osg::ref_ptr< FeatureNode > featureNode = new FeatureNode(features, style);
        mapNode->addChild(featureNode.get());                

        viewer.setSceneData( node );
        return viewer.run();
    }
    else
    {
        return usage(argv[0]);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值