OSGearth学习(一)

本文介绍了osgEarth开源库的基础用法,通过解析示例代码`osgearth_city`展示如何加载TMS高程数据和建筑位文件,创建3D建筑物并设置分层显示。详细讨论了`FeatureDisplayLayout`类在实现建筑物分层显示中的作用,包括成员函数如`maxRange()`、`minRange()`和`cropFeatures()`等。
摘要由CSDN通过智能技术生成

今天开始仔细研究osgearth,osgearth是一个开源的地理信息库,里面有很方便的插件可以使用。但是osgearth的资料少之又少,所以我们从osgearth的例程开始研究。

我们从第一个osgearth_city开始。

#include <osg/Notify>
#include <osgGA/GUIEventHandler>
#include <osgGA/StateSetManipulator>
#include <osgViewer/Viewer>
#include <osgEarth/MapNode>
#include <osgEarthUtil/ExampleResources>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/AutoClipPlaneHandler>
#include <osgEarthUtil/SkyNode>
#include <osgEarthDrivers/tms/TMSOptions>
#include <osgEarthDrivers/feature_ogr/OGRFeatureOptions>
#include <osgEarthDrivers/model_feature_geom/FeatureGeomModelOptions>

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

int
main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);

// 创建一个新的地图
Map* map = new Map();

// 添加一个TMS高程的数据层
TMSOptions imagery;
imagery.url() = "http://readymap.org/readymap/tiles/1.0.0/22/"; //这个是TMS数据库网址
map->addImageLayer( new ImageLayer("ReadyMap imagery", imagery) );

// 创建一个osgearth里面提供的波士顿城市的建筑位置文件。
OGRFeatureOptions feature_opt;
feature_opt.name() = "buildings";
feature_opt.url() = "../data/boston_buildings_utm19.shp";//波士顿城市的位置文件
feature_opt.buildSpatialIndex() = true;

//创建一个建筑物风格
Style buildingStyle;
buildingStyle.setName( "default" );


//ExtrusionSymbol提供了一个将二维图形挤出为三维的一个类继承于osgEarth::Symbology::Symbol
ExtrusionSymbol* extrusion = buildingStyle.getOrCreate<ExtrusionSymbol>();
extrusion->heightExpression() = NumericExpression( "3.5 * max( [story_ht_], 1 )" ); //挤出建筑物的高度
extrusion->flatten() = true;
extrusion->wallStyleName() = "building-wall";//设置挤出墙的名字
extrusion->roofStyleName() = "building-roof";

// 为墙的纹理创建风格
Style wallStyle;
wallStyle.setName( "building-wall" );
SkinSymbol* wallSkin = wallStyle.getOrCreate<SkinSymbol>();//得到设置墙体风格的指针
wallSkin->libraryName() = "us_resources";
wallSkin->addTag( "building" );
wallSkin->randomSeed() = 1;

// 为挤出的屋顶设置纹理风格
Style roofStyle;
roofStyle.setName( "building-roof" );
SkinSymbol* roofSkin = roofStyle.getOrCreate<SkinSymbol>();
roofSkin->libraryName() = "us_resources";
roofSkin->addTag( "rooftop" );
roofSkin->randomSeed() = 1;
roofSkin->isTiled() = true;

//将所有的墙体风格集合到一个建筑物上面,形成虚构的建筑物
StyleSheet* styleSheet = new StyleSheet();
styleSheet->add

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值