今天开始仔细研究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