osgearth学习文档
osgEarth1_Document

Developers : Working with Maps ¶A Map is the central data model in osgEarth. It is a container for image, elevation, and feature layers.Loading a Map ¶The easiest way to render a Map is to load it from a earth file?. Since osgEarth uses OpenSceneGraph plugins, you can do this with a single line of code:osg::Node* globe = osgDB::readNodeFile("myglobe.earth");You now have an OpenSceneGraph Node that can be added to your scene graph and displayed. Seriously, it really is that simple!This method of loading a Map is, more often than not, all that an application will need to do. However, if you want to create your Map using the API, read on.Programmatic Map Creation ¶osgEarth provides an API for creating Maps at runtime.The basic steps to creating a Map with the API are:1.Create a Map object2.Add imagery and elevation layers to the Map as you see fit3.Create a MapNode that will render the Map object4.Add your MapNode to your scene graph.You can add layers to the map at any time.#include <osgEarth/Map>#include <osgEarth/MapNode>#include <osgEarthDrivers/tms/TMSOptions>#include <osgEarthDrivers/gdal/GDALOptions>using namespace osgEarth;using namespace osgEarth::Drivers;...// Create a Map and set it to Geocentric to display a globeMap* map = new Map();// Add an imagery layer (blue marble from a TMS source){TMSOptions tms;tms.url() = "/wms-c/Basic.py/1.0.0/satellite/"; ImageLayer* layer = new ImageLayer( "NASA", tms );map->addImageLayer( layer );}// Add an elevationlayer (SRTM from a local GeoTiff file){GDALOptions gdal;gdal.url() = "c:/data/srtm.tif";ElevationLayer* layer = new ElevationLayer( "SRTM", gdal );map->addElevationLayer( layer );}// Create a MapNode to render this map:MapNode* mapNode = new MapNode( map );...viewer->setSceneData( mapNode );Working with a MapNode at runtime ¶A MapNode is the scene graph node that renders a Map. Whether you loaded your Map from an Earth File or created it using the API, you can access the Map and its MapNode at runtime to make changes. If you did not explicitly create a MapNode using the API, you will first need to get a reference to the MapNode to work with. Use the !Map::findMapNode utility function://Load the maposg::Node* loadedModel = osgDB::readNodeFile("mymap.earth");//Find the MapNodeosgEarth::MapNode* mapNode = MapNode::findMapNode( loadedModel );Once you have a reference to the MapNode, you can get to the map:// Add an OpenStreetMap image sourceTMSOptions driverOpt;driverOpt.url() = "/";driverOpt.tmsType() = "google";ImageLayerOptions layerOpt( "OSM", driverOpt );layerOpt.profile() = ProfileOptions( "global-mercator" );ImageLayer* osmLayer = new ImageLayer( layerOpt );mapNode->getMap()->addImageLayer( osmLayer );You can also remove or re-order layers:// Remove a layer from the map. All other layers are repositioned accordingly mapNode->getMap()->removeImageLayer( layer );// Move a layer to position 1 in the image stackmapNode->getMap()->moveImageLayer( layer, 1 );Working with Layers ¶The Map contains ImageLayers and ElevationLayers. These contain some properties that you can adjust at runtime. For example, you can toggle a layer on or off or adjust an ImageLayer opacity using the API:ImageLayer* layer;...layer->setOpacity( 0.5 ); // makes the layer partially transparentBack to Developers GuideDevelopers Guide : Shader Composition ¶osgEarth uses GLSL shaders in several of its rendering modes. By default, osgEarth will detect the capabilities of your graphics hardware and automatically select an appropriate mode to use.Since osgEarth relies on shaders, and since you as the developer may wish to use your own shader code as well, osgEarth provides a shader composition framework. This allows you a great deal of flexibility when incorporating your own shaders into osgEarth.There are several ways to integrate your own shader code into osgEarth. These are discussed below. But first it is important to understand the basics of osgEarth's shader composition framework.Framework Basics ¶osgEarth installs default shaders for rendering. The default shaders are shown below. Note the following function types:•built-in functions: functions that osgEarth installs by default (but that you can override) •user functions: functions that you "inject" into the shader either before (pre) or after (post) the built-ins.// VERTEX SHADER:void main(void){gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;...// "LOCATION_PRE_VERTEX" user functions are called here:pre_vertex_function_1(...);...// the built-in functions are called next:osgearth_vert_setupTexturing();if ( lighting_enabled )osgearth_vert_setupLighting();// "LOCATION_POST_VERTEX" user functions are called last:post_vertex_function_1(...);}// FRAGMENT SHADER:void main(void){vec4 color = vec4(1,1,1,1);...// "LOCATION_PRE_FRAGMENT" user functions are called here:pre_fragment_function_1(color);...// then the built-in osgEarth functions are called:osgearth_frag_applyTexturing(color);if (osgearth_lighting_enabled)osgearth_frag_applyLighting(color);...// "LOCATION_POST_FRAGMENT" user functions are called last:post_fragment_function_1(color);...gl_FragColor = color;}VirtualProgram ¶osgEarth include an OSG state attribute called VirtualProgram that performs the runtime shader composition. Since VirtualProgram is an osg::StateAttribute, you can attach one to any node in the scene graph. Shaders that belong to a VirtualProgram can override shaders lower down on the attribute stack (i.e., higher up in the scene graph). In the way you can override individual shader functions in osgEarth.The sections below on integration will demonstrate how to use VirtualProgram.Integrating Custom Shaders ¶There are two ways to use shader composition in osgEarth.•Injecting user functions•Overriding osgEarth's built-in functions with a custom ShaderFactoryInjecting User Functions ¶In the core shader code above, you see "user functions" (e.g., "pre_fragment_function_1()" etc). These don't exist in the default shaders that osgEarth generates; rather, they represent code that you as the developer can "inject" into various locations in the built-in shaders.For example, let's use User Functions to create a simple "haze" effect. (NOTE: see this example in its entirety in osgearth_shadercomp.cpp)static char s_hazeVertShader[] ="varying vec3 v_pos; \n""void setup_haze() \n""{ \n"" v_pos = vec3(gl_ModelViewMatrix * gl_Vertex); \n""} \n";static char s_hazeFragShader[] ="varying vec3 v_pos; \n""void apply_haze(inout vec4 color) \n""{ \n"" float dist = clamp( length(v_pos)/10000000.0, 0, 0.75 ); \n"" color = mix(color, vec4(0.5, 0.5, 0.5, 1.0), dist); \n""} \n";osg::StateAttribute*createHaze(){osgEarth::VirtualProgram* vp = new osgEarth::VirtualProgram();vp->setFunction( "setup_haze", s_hazeVertShader,osgEarth::ShaderComp::LOCATION_POST_VERTEX );vp->setFunction( "apply_haze", s_hazeFragShader,osgEarth::ShaderComp::LOCATION_POST_FRAGMENT );return vp;}...sceneGraph->getOrCreateStateSet()->setAttributeAndModes( createHaze() );In this example, the function "setup_haze" is called from the core vertex shader after the built-in vertex functions. The "apply_haze" function gets called from the core fragment shader after the built-in fragment functions.There are FOUR injection points, as follows:Location Shader SignatureShaderComp::LOCATION_PRE_VERTEXVERTEX void functionName(void) ShaderComp::LOCATION_POST_VERTEXVERTEX void functionName(void)ShaderComp::LOCATION_PRE_FRA GMENT FRAGMENTvoid functionName(inout vec4color)ShaderComp::LOCATION_POST_FR AGMENT FRAGMENTvoid functionName(inout vec4color)As you can see, user functions literally let you inject code into the main shaders seamlessly.Customizing the Shader Factory ¶If you want to replace osgEarth's built-in shader functions (e.g. osgearth_vert_setupLighting() et al), you can install a custom ShaderFactory. The ShaderFactory is stored in the osgEarth Registry and contains all the methods for creating the built-in functions. You can install your own ShaderFactory like this:#include <osgEarth/ShaderComposition>...class CustomShaderFactory : public osgEarth::ShaderFactory{... override desired methods here ...};...osgEarth::Registry::instance()->setShaderFactory( new CustomShaderFactory() ); This method is good for replacing osgEarth's built-in lighting shader code. HOWEVER: be aware that override the built-in texturing functions may not work. This is because osgEarth's image layer composition mechanisms override these methods themselves to perform layer rendering.Sampling Image Layers ¶What if you want to access one of the Map's ImageLayers from your shader? Since osgEarth internally manages image layers, texture units, and composition, it is not as simple of calling GLSL's texture2D() function. Here's how to do it.Use the TextureCompositor interface to create a sampler function for the layer you want to query.You can then call this sampler function from your shader. Here's an example.// assume "layer" is the image layer you want to sample, and "vp" is a VirtualProgram state attribute:osgEarth::ImageLayer* layer;osgEarth::VirtualProgram* vp;// first get a reference to the texture compositor.osgEarth::TerrainEngine* engine = mapNode->getTerrainEngine();osgEarth::TextureCompositor* comp = engine->getTextureCompositor();// next, request a sampling shader for the layer in question.osg::Shader* sampler = comp->createSamplerFunction( layer, "sampleMyLayer", osg::Shader::FRAGMENT );// add it to your VirtualProgram:vp->setShader( "sampleMyLayer", sampler );...Then in your shader code, you can call the "sampleMyLayer" function:// FRAGMENT SHADERvoid sampleMyLayer(void); // declaration...void someFunction(){...vec4 texel = sampleMyLayer();...}The sampler function will automatically sample the proper sampler with the current texture coordinate.System Uniforms ¶In addition the the OpenSceneGraph system uniforms (which all start with "osg_"), osgEarth provides various uniforms (all of which start with ("osgearth_"). They are:•bool osgearth_LightingEnabled - whether GL lighting is enabled•bool[] osgearth_ImageLayerEnabled - whether image layer "n" is enabled•float osgearth_CameraRange - distance from the camera to the current vertexBack to Developers Guide。
OSGEarth编译与测试

第一章OSGEarth编译与测试2.1 OSGEarth编译第一步:配置系统环境变量。
新设置OSG_FILE_PATH变量,值为E:\OSGearth\OSGEARTH\data; E:\OSGearth\GDAL\data;向PATH添加值:E:\OSGearth\3rdParty\bin;E:\OSGearth\OSGEARTH\bin\Debug;E:\OSGearth\OSGEARTH\bin\Release;第二步:使用“生成”->“批生产”,选择all_build(debug|win32和release|win32)进行生成。
在编译过程中存在4个文件无法编译成功,但是不影响正常的测试。
第三步:修改这些错误。
上述错误的问题主要出现在E:\osgearth\osgearth\src\applications\osgearth_imageoverlay\osgearth_imageoverlay.cpp文件的36-39行。
原因是OSG_MIN_VERSION_REQUIRED(2,9,6)限制了osg的版本。
本文使用了v3.0.1版,因此需要添加需要添加ImageOverlayEditor文件。
(目前还没有解决)2.2 OSGEarth测试测试release版本:1.打开cmd窗口,进入E:\osgearth\osgearth\vs2010\bin\Release;2.输入命令:osgearth_viewer.exe E:\osgearth\osgearth\tests\gdal_tiff.earth;会出现一个提示3.复制所需的dll到E:\osgearth\osgearth\vs2010\bin\Release文件夹中。
可能需要重复好多次。
4.测试成功会出现下面界面:。
osgearth 高度系数

osgearth 高度系数摘要:1.OSGeo 简介2.OSGearth 项目概述3.OSGearth 高度系数的定义与计算方法4.OSGearth 高度系数的应用5.总结正文:1.OSGeo 简介OSGeo(Open Source Geospatial Foundation)是一个致力于地理信息系统(GIS)开源软件发展的非营利组织。
该组织成立于2006 年,旨在为地理信息科学和空间数据处理领域提供高质量、可信赖的开源软件。
OSGeo 的成员包括开发者、用户、研究者和企业家,他们共同推动GIS 技术的创新和发展。
2.OSGearth 项目概述OSGearth 是一个由OSGeo 基金会支持的开源地理信息系统项目。
该项目旨在为地球科学、环境监测、城市规划等领域提供免费的GIS 软件。
OSGearth 项目包括多个模块,例如数据处理、可视化、分析和地图制图等,用户可以根据需求进行自由组合和定制。
3.OSGearth 高度系数的定义与计算方法OSGearth 高度系数(Elevation Coefficient)是OSGearth 项目中一个重要的参数,用于描述地形高程数据的精度。
高度系数的计算方法如下:首先,根据地理坐标(经度和纬度)获取该地点的平均海拔高度。
其次,通过高程数据计算该地点的实际海拔高度。
最后,将实际海拔高度与平均海拔高度相除,得到高度系数。
4.OSGearth 高度系数的应用OSGearth 高度系数在地理信息系统中有广泛的应用,例如:(1)地形分析:通过比较不同地点的高度系数,可以评估地形的陡峭程度,分析山地、平原和丘陵等地貌类型。
(2)洪水风险评估:利用高度系数可以预测洪水发生的可能性,为防洪工程提供参考依据。
(3)生态保护:高度系数可以用于评估生态系统的健康状况,为生物多样性保护提供依据。
(4)城市规划:在城市规划中,高度系数可以用于评估土地使用效率,优化城市空间布局。
5.总结OSGearth 高度系数是OSGeo 基金会支持的开源地理信息系统项目中的一个重要参数,具有广泛的应用前景。
osgEarth数据加载及组织解析-推荐下载

1.1 读取 earth 文件
读取earth文件
分解Conf属性 构建map对象
根据map对象及 options对象,创 建mapNode节点
将mapNode节点加入场 景图中,通过分页LOD 动态调度进行组织渲染
图 3.1 osgEarth 数据加载整体流程
记录数据属性、 渲染属性的Conf
map对象 options对象
mapNode节点
拥有地形的三维 场景
MapNodeHelper::load() ExampleResources.cpp
readNodeFile(filename,Registry::in stance()->getOptions()) ReadFile.h
对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术通关,1系电过,力管根保线据护敷生高设产中技工资术艺料0不高试仅中卷可资配以料置解试技决卷术吊要是顶求指层,机配对组置电在不气进规设行范备继高进电中行保资空护料载高试与中卷带资问负料题荷试2下卷2,高总而中体且资配可料置保试时障卷,各调需类控要管试在路验最习;大题对限到设度位备内。进来在行确管调保路整机敷使组设其高过在中程正资1常料中工试,况卷要下安加与全强过,看度并22工且22作尽22下可22都能22可地护以缩1关正小于常故管工障路作高高;中中对资资于料料继试试电卷卷保破连护坏接进范管行围口整,处核或理对者高定对中值某资,些料审异试核常卷与高弯校中扁对资度图料固纸试定,卷盒编工位写况置复进.杂行保设自护备动层与处防装理腐置,跨高尤接中其地资要线料避弯试免曲卷错半调误径试高标方中高案资等,料,编试要5写、卷求重电保技要气护术设设装交备备置底4高调、动。中试电作管资高气,线料中课并敷3试资件且、设卷料中拒管技试试调绝路术验卷试动敷中方技作设包案术,技含以来术线及避槽系免、统不管启必架动要等方高多案中项;资方对料式整试,套卷为启突解动然决过停高程机中中。语高因文中此电资,气料电课试力件卷高中电中管气资壁设料薄备试、进卷接行保口调护不试装严工置等作调问并试题且技,进术合行,理过要利关求用运电管行力线高保敷中护设资装技料置术试做。卷到线技准缆术确敷指灵设导活原。。则对对:于于在调差分试动线过保盒程护处中装,高置当中高不资中同料资电试料压卷试回技卷路术调交问试叉题技时,术,作是应为指采调发用试电金人机属员一隔,变板需压进要器行在组隔事在开前发处掌生理握内;图部同纸故一资障线料时槽、,内设需,备要强制进电造行回厂外路家部须出电同具源时高高切中中断资资习料料题试试电卷卷源试切,验除线报从缆告而敷与采设相用完关高毕技中,术资要资料进料试行,卷检并主查且要和了保检解护测现装处场置理设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。
osgEarth编译总结

首先在osg的编译上有一点记录一下:1 我们下载的第三方依赖3rdParty_x86_x64 这个文件对于VS2008和VS2010来说可能VS2008的提供库要全一些。
2 对于3rdParty_x86_x64文件夹下的x86和x64来说我们的系统如果是32位的应该就只能选x86 对于x64来说我们两个包都是可以选择的,据说在64位的系统上的32位程序是模拟运行的。
如果我们编译时选择直接编译。
那最好是选x86那个包。
在这次的选择中选择x64包结果编译到osgDB库的时候出现了错误。
如果想编译出来的程序只是用于x64 那么可以尝试在x64包的基础上对VS进行相关的设置,应该是不会有很大问题的。
下面主要是对osgEarth进行编译由于osgEarth没有对第三方依赖进行打包,所以我们就不得不自己进行配置相关的依赖。
首先下载源码包,我们进入官网/wiki/Downloads下载源码简单明了。
接下来我们下载第三方依赖:1 GDAL下载:/gdal/wiki/DownloadSource在这里我们选择1.8.1版本,因为在1.9.0版本使用中出现了编译不能通过的情况。
当然我们也可以自己将编译过程中出现的问题解决。
在这里我们只是为了编译GDAL“不节外生枝”下面我们来对这个库进行编译:对于这个版本有两种方法可以编译1 它里面有两个.sln,使用其中之一编译就行2 下载完GDAL的源码后,还需要先运行makegdal_gen.bat这个文件,然后打开X:\Program Files\Microsoft Visual Studio\VC98\bin\VCVARS32.BAT,X代表你VS的安装盘.打开后用cd命令切换到你GDAL的目录下执行命令,nmake /f makefile.vc MSVC_VER=1500 BUILD_DEBUG=YES,其中1500代表VS版本2008,当然你也可以进入nmake配置文件修改.文件编译完成后我们有两种不同的处理方法方法一将生成的lib dll 包括: gdal_i.lib gdal.lib cpl.lib(port目录下) ogr.lib(ogr目录下), 以及gdal17.dll 拷贝到E:\OSG\GDAL\apps下,这一种在后面的使用中会直接将这个作为cmake的应用目录(在工程中添加包含目录时会很麻烦,不推荐采用)方法二GDAL编译完成后的文件存放于C0:\warmerda\bld,包含文件include,lib,data,bin,可将它们拷贝到GDAL文件夹下,置于OSG目录下。
osgearth

Pelican Mapping maintains osgEarth.
The best way to interact with the osgEarth team and the user community is through the support forum. Please read and follow these guidelines for using the forum:
1.1.2 Community Resources
Since osgEarth is a free open source SDK, the source code is available to anyone and we welcome and encourage community participation when it comes to testing, adding features, and fixing bugs. Support Forum
• Sign up for an account and use your real name. You can participate anonymously, but using your real name helps build a stronger community (and makes it more likely that we will get to your question sooner).
• Always include as much supporting information as possible. Post an earth file or short code snippet. Post the output to osgearth_version --caps. Post the output to gdalinfo if you are having trouble with a GeoTIFF or other data file. List everything you have tried so far.
osgearth各个例子功能概述

osgearth各个例⼦功能概述转⾃:/wl198302/article/details/21177309最近在学习osgearth,对其还不是很理解,有些例⼦不会运⾏,有些可以,把可以的做个统计,以备后⾯查⽤。
1、osgearth_graticule:⽣成经纬线。
2、osgearth_annotation:各类标注(点、线、⾯、模型、⽂本等)。
3、osgearth_city:加载⼀个城市三维模型,可以浏览。
4、osgearth_clamp:在⼀个区域加载⽣成5000个树⽊的三维模型展⽰。
5、osgearth_colorfilter:运⾏不起来……6、osgeatth_controls:有⼀个osg的图标,可以控制透明度与⽅向。
还有⼀些⽂本矩形框之类的。
7、osgearth_demo:qt的⼀个集成地球的例⼦8、osgearth_elevation:显⽰⿏标所指位置的经纬度、坐标系、⾼程(MSL\HAE)、分辨率。
不过运⾏⾮常缓慢。
9、osgearth_featureeditor:添加⼀条线,并可以修改线的节点与颜⾊(编辑时,线的形状变为虚线段)。
10、osgearth_featurfilter:出来⼀个地球,不知道需要什么数据才能运⾏出效果。
例⼦给出的⽤途为-简单的功能过滤,改变数据源特征属性的值。
11、osgearth_featureinfo:不是界⾯程序,不知道⼲嘛的……12、osgearth_featuremanip:出现⼀个地球,没明⽩⼲嘛的……13、osgearth_featurequery:同上……14、osgearth_imageoverlay:在地图上叠加⼀张gif图⽚,并可以控制图⽚的透明度。
15、osgearth_features:代码建⽴地图,并加载各国分界线的shp数据。
16、osgearth_los:以稍稍⽔平的视⾓,显⽰飞机模型绕⼀点旋转,还有⼀些运动对象。
17、osgearth_manip:地球上⽣成⼀个⽴体的helloworld⽂字,并且可以控制⽂字⾏⾛,快速定位不同级别的视点,让⽂字始终在屏幕中央,地球滚动,很好的功能 O(∩_∩)O~18、osgearth_map:代码⽣成地球tms地图图层。
osgEarth手册

1、OSGEARTH 安装OsgEarth是一个跨平台的库,可以使用版本号为2.6.2或更新版本的Cmake 对其进行编译。
1.1、获取源码三个方法可以获取osgearth源码:Option1:使用GITosgEarth源码托管于GitHub,所以我们需要一个Git客户端。
Windows下推荐T ortoiseGit,SVN 小乌龟的Git 版本。
评价:该有的功能基本都有了,还是不错的。
备注:GitHub是一个为那些使用Git版本控制系统的项目提供基于互联网的存取服务的Git存取站点。
它是由GItHub公司(先前被称作用Logical Awesome)的开发者Chris Wanstrath, PJ Hyett, 和Tom Preston-Werner 使用Ruby on Rails写成的。
最新版本是Version 2.0,osgearth_2.0_T2011-02-24。
Option2: 下载tarballtarball是linux下最方便的打包工具,是以tar这个指令来打包与压缩的档案。
下载页面: /gwaldron/osgearth/downloadsOption3:使用版本控制SVN在您的SVN客户端上键入:/gwaldron/osgearth.git1.2、准备工作osgEarth需要第三方支持库才能编译。
所需的依赖服务如下:●OpenSceneGraph 2.8或更新的●GDAL 1.6或更新的,Geospatial Data Abstraction Layer的缩写。
是一个在X/MIT许可协议下的开源栅格空间数据转换库●CURL- HTTP transfer library,是一个利用URL语法在命令行方式下工作的文件传输工具。
可选依赖如下(没有他们,osgEarth可以运行,但将会失去一些功能):●GEOS3.2.0或更高版本-C++拓展库,这个库是用来osgEarthFeatures模块执行各种几何处理操作,如缓冲和交集。
earth文档读取

Earth插件-------------------------------轻轻的来到osgearth 主旨:OSGEarth如何序列化一Earth 文件结构1结构图2属性2.1 <map> ? <earth>用config类表示,可设属性<name><type>球面,平面(geocentric,projected)<version> 版本2,2 <options> 主要配置整个map地图运行时的各种属性用mapOptions类表示可设属性<lighting> 灯光<elevation_interploation> 插值,nearset 最近点插值average 最近点平均值bilinear 线性插值,取坐标值triangulate 三角面片插值<elevation_tile_size> 瓦片大小<elevation_texture_size> 纹理大小<overlay_wapring><overlay_blending><overlay_minmapping><overlay_texture_size><overlay_attach_stencil>Tip 资源路径options 下<osg_files_paths>3.3 <terrain>用terrianOptions类表示<name><driver><lighting><sample_ratio> 瓦片采样率<skit_ration> 瓦片边缘率,当高层夸张过大时<min_tile_range_factor> 瓦片可视范围<min_lod> 最低显示的细节级别<max_lod> 最高显示的细节级别<first_lod> 第一显示的细节级别(也就是说低于这个级别的数据,不显示,即使有)<cluster_culling> 集群裁剪<Mercator_fast_path> bool 墨卡托最快地形渲染?<blending> 地形混合3.4 <image>用ImageLavelOptions表示<nodata_image> 无数据显示的url<opacity> 透明度<min_range> 最小可视范围<max_range> 最大可视范围<min_level> 最小显示细节层级<max_level> 最大显示细节层级<min_resolution> 数据的最小分辨率,单位的像素<max_resolution>数据的最大分辨率,单位的像素<enable> 是否包含进map层<visible> 可视3.5 <model> 模型层用modelLayerOption类表示<name><driver><enable><visible>3.6<profile> 空间坐标系统用profileOption类表示<srs> 空间参考系统,采用wkt字符串<vdatum> 垂直基准面相当于大地高程<xmin, xmax, ymin, ymax> 地理空间范围,地心投影以°为单位,平面投影以米为单位<num_tiles_*_at_lod_0> 瓦片大小? 可续3.7 <cache> 缓存数据用cacheOption类表示<driver><path>3.8 <cachePolicy> 瓦片配置策略用config类表示<usage> read_write read_only cache_onlyno_cache:只读数据源3.9 <proxy> 代理设置用httpClient,config 类<host><post><username><passwork>3.10 <colorFileter>用config类表示着色器插件,配置对应层的颜色,设置各种过滤器∙BrightnessContrast光线∙ChromaKey对应原色的透明度∙CMYK设置cyan, magenta, yellow, black颜色的变值∙Gamma伽玛校正RGB值∙GLSL glsl 模式处理∙HSL色调,饱和度,亮度∙RGB rgb值3.11 <mask> 隐藏地形用maskLayerOption类序列化<name><driver>3.12 <external> 功能点标签用config 序列化<sky><ocean><annotation><decluttering> 标注优化<viewpoints>3.13 <elevation>用elvationLayerOptions类表示<min_level> 最小显示细节层级<max_level> 最大显示细节层级<min_resolution> 数据的最小分辨率,单位的像素<max_resolution>数据的最大分辨率,单位的像素<enable> 是否包含进map层二例子解析Example test.earth三如何序列化1 几个类视图2 BXVR 插件开始1从mapOption 开始读取earth文件的开头以及options子项,构造map ,继而构造mapNodeOptions, 然后读取六大子节点(ImageLayerOptions, elevationLayerOptions……),最终构造的mapNode结论:mapNode包含我们有的信息。
osgEarth基础入门

osgEarth基础⼊门osgEarth基础⼊门2015年3⽉21⽇16:19osgEarth是基于三维引擎osg开发的三维数字地球引擎库,在osg基础上实现了⽡⽚调度插件,可选的四叉树调度插件,更多的地理数据加载插件(包括GDAL,ogr,WMS,TMS,VPB,filesystem等),再结合⼀套地理投影转换插件,这样就能够实现⾼效处理加载调度地理数据在三维地球上的显⽰,实现三维虚拟地球。
想要实现⼀个简单的基于osgEarth的三维地球,有两种⽅式,这两种⽅式是互通的。
⼀种基于XML标签的earth⽂件加载,另外⼀种是采⽤C++代码,本质是⼀样的,osgEarth内部⽀持直接解析XML标签⽂件,转换为代码实现,具体参考tests⽂件夹例⼦,代码则参考application 下⾯例⼦。
但是⼤多数情况下,你需要更灵活掌控性更强的代码来实现功能,因为只有⼀个加载了基础数据的三维地球是只能看,不能解决实际问题的,需要界⾯通常采⽤QT,更多的三维渲染和仿真业务则由osg来完成。
因此学好osg是做这⼀切的基础。
osgEarth的特点:⽀持加载常见的栅格数据(影像和DEM),但是⼤数据必须建⽴⾦字塔,设置为地理投影,想要⾼效率最好处理为⽡⽚,这样也便于部署在服务端。
⽮量数据,最好尽可能的简化,因为⼤的⽮量会⼗分影响渲染速度,当然也可以对⽮量栅格化处理加快速度,对于模型的话,⼤数据量⼀定要做LOD或者pageLod。
osgEarth程序的常规流程:创建osgViewer---->创建MapNode---->设置Earth操作器---->设置场景参数----->runMapNode是继承⾃osg的Node,是osgEarth中地球节点,你所添加的影像,DEM,模型都包含在MapNode中,因为它们都加⼊到Map中,Map则类似⼆维中的Map可以添加各种图层。
剩余的不管是模型节点Node,或者是标注Node,还是其他的都是可以直接添加到MapNode中或者另外的Group中。
osgEarth编译

以下文档是osg和osgearth的编译过程,系统要求如下:操作系统:win7 home basic x64编译器:vs2010〇前言本文档编译成功后会形成4个目录,分别为:1Open Scene Graph, C:\Open Scene Graph2OpenSceneGraph, C:\OpenSceneGraph3OSG, D:\OSG4osgEarth, D:\osgEarth第一个存放osg软件,用于只使用osg软件用。
文件夹大小199M第二个存放osg+osgearth软件,用于使用osgearth和osg用。
文件夹大小626M第三个存放osg编译过程文件,用于对osg软件升级开发用。
文件夹大小3.6G第四个存放osgEarth编译过程文件,用于对osgEarth软件升级开发用。
文件夹大小2.54G 先编译一osg编译1.1 文件目录构建第一步:我们在D盘编译OSG,首先建立一个文件夹:D:\OSG;第二步:把源代码拷贝进OSG文件夹:D:\OSG\OpenSceneGraph-3.0.1第三步:把3rdParty第三方库拷贝到OSG文件夹:D:\OSG\3rdParty第四步:重新组织3rdParty,把x86文件夹中的内容拷贝到3rdParty中,把x86,x64删除。
如下图所示:第五步:把数据文件Data拷贝到OSG文件夹:D:\OSG\Data通过以上五步,所需准备完毕,文件目录组织情况如下:1.2 Qt和wxWidgets安装下载qt和wxWidgets安装文件:qt-win-opensource-4.8.4-vs2010.exe和wxMSW-2.8.12-Setup.exe,如图所示:1.3 cmake设置第一步:把cmake程序拷贝到C盘,C:\cmake-2.8.11-win32-x86第二步:打开cmake程序第三步:直接在source code文本框中输入D:/OSG/OpenSceneGraph-3.0.1第四步:在OSG文件夹中建立Build目录,用于存放编译工程文件第五步:直接在build the binaries文本框中输入D:/OSG/Build第六步:点击Configure第七步:选择Visual Studio 10,点击finish 第八步:等待初始配置结果:第九步:观察配置结果第十步:TIFF,FreeType配置修改观察cmake配置结果,显示TIFF,FREETYPE,没有找到,需要进行指定,TIFF没有debug版本,这里把debug版本指定为release版本。
osgearthsetelevation范围 -回复

osgearthsetelevation范围-回复关于osgearth.setElevation范围的一步一步解析在使用osgEarth进行地理信息系统(GIS)开发时,一个常见的需求是设置地形的高程范围。
osgEarth是一个强大的地理可视化引擎,它结合了OpenSceneGraph和地理空间数据,可以为用户提供高效、灵活的地球可视化、地图生成和地理空间分析工具。
在osgEarth中,通过osgearth.setElevation方法可以设置地形(或海底)的高程范围。
本文将一步一步地解析关于osgearth.setElevation范围的相关知识。
第一步:理解osgearth.setElevation方法的作用osgearth.setElevation方法用于设置地形的高程范围。
地形高程通常表示地球表面的海拔高度,可以用来模拟山脉、山谷、平原等地貌特征。
通过设置地形的高程范围,可以控制地形的细节和表现效果,从而实现更加真实和精细的地球模拟。
第二步:了解osgearth.setElevation方法的参数osgearth.setElevation方法接受两个参数:minElevation和maxElevation。
minElevation表示地形的最低高程,maxElevation表示地形的最高高程。
这两个参数可以指定为绝对高程值,也可以指定为离散的离地高度。
第三步:理解最低和最高高程的含义最低高程和最高高程决定了地形的高程范围。
设置最低高程可以控制地形的最低部分,比如海平面或低洼地区。
设置最高高程可以控制地形的最高部分,比如山峰或高原。
通过调整最低和最高高程的数值,可以实现对地形的局部或整体高程范围的控制。
第四步:确定合适的高程范围数值确定合适的高程范围数值需要考虑具体的需求和数据情况。
一般来说,可以通过查看地理数据源的高程信息来获取合适的数值范围。
比如,可以查看DEM(数字高程模型)数据,了解地形的高程分布情况。
osgEarth使用笔记4—加载矢量数据

osgEarth使用笔记4—加载矢量数据目录1. 概述2. 详论2.1. 基本绘制2.2. 矢量符号化2.2.1. 可见性2.2.2. 高度设置2.2.3. 符号化2.2.4. 显示标注2.3. 其他3. 结果4. 问题1. 概述前面文章加载的底图数据是一种栅格数据,还有一种很重要的地理信息表现形式是矢量数据。
在osgEarth中,这部分包含的内容还是很丰富的,这里就总结一二。
2. 详论在《osgEarth使用笔记1——显示一个数字地球》这篇文章中代码的基础之上,添加加载显示矢量的代码:1.#include<Windows.h>2.#include<iostream>3.#include<string>4.5.#include<osgViewer/Viewer>6.#include<osgDB/ReadFile>7.8.#include<osgEarth/MapNode>9.#include<osgEarth/ImageLayer>10.11.#include<osgEarthDrivers/gdal/GDALOptions>12.#include<osgEarthDrivers/cache_filesystem/FileSystemCache>13.#include<osgEarthDrivers/feature_ogr/OGRFeatureOptions>14.15.#include<osgEarthFeatures/FeatureSourceLayer>16.#include<osgEarthFeatures/FeatureModelLayer>17.18.#include<osgEarthUtil/EarthManipulator>19.ing namespace std;21.22.void AddVector(osg::ref_ptr<osgEarth::Map> map)23.{24.//25.std::string filePath ="D:/Work/OSGNewBuild/osgearth-2.10.1/data/world.shp";26.osgEarth::Drivers::OGRFeatureOptions featureData;27.featureData.url()= filePath;28.29.// 如果缺少空间参考,可以手动指定30.// ifstreaminfile("C:/Data/vector/hs/23.prj");31.// string line;32.// getline(infile, line);33.// featureData.profile()->srsString() = line;34.35.// Make a feature source layer and add itto the Map:36.osgEarth::Features::FeatureSourceLayerOptio ns ogrLayer;()= filePath +"_source";38.ogrLayer.featureSource()= featureData;39.osgEarth::Features::FeatureSourceLayer* featureSourceLayer =newosgEarth::Features::FeatureSourceLayer(ogrLayer);40.map->addLayer(featureSourceLayer);41.osgEarth::Features::FeatureSource*features = featureSourceLayer->getFeatureSource();42.if(!features)43.{44.printf(("无法打开该矢量文件!"));45.return;46.}47.48.//49.osgEarth::Features::FeatureModelLayerOption s fmlOpt;()= filePath;51.fmlOpt.featureSourceLayer()= filePath +"_source";52.fmlOpt.enableLighting()=false;53.54.osg::ref_ptr<osgEarth::Features::FeatureMod elLayer> fml =newosgEarth::Features::FeatureModelLayer(fmlOpt);55.map->addLayer(fml);56.}57.58.int main()59.{60.osgEarth::ProfileOptions profileOpts;61.62.//地图配置:设置缓存目录63.osgEarth::Drivers::FileSystemCacheOptions cacheOpts;64.string cacheDir ="D:/Work/OSGNewBuild/tmp";65.cacheOpts.rootPath()= cacheDir;66.67.//68.osgEarth::MapOptions mapOpts;69.mapOpts.cache()= cacheOpts;70.mapOpts.profile()= profileOpts;71.72.//创建地图节点73.osg::ref_ptr<osgEarth::Map> map =new osgEarth::Map(mapOpts);74.osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map);75.76.osgEarth::Drivers::GDALOptions gdal;77.gdal.url()="D:/Work/OSGNewBuild/osgearth-2.10.1/data/world.tif";78.osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer("BlueMarble", gdal);79.map->addLayer(layer);80.81.AddVector(map);82.83.osgViewer::Viewer viewer;84.viewer.setSceneData(mapNode);85.86.osg::ref_ptr<osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;87.viewer.setCameraManipulator(mainManipulator);88.89.viewer.setUpViewInWindow(100,100,800,600);90.91.return viewer.run();92.}osgEarth表达矢量的基本思路是,先将其读取到矢量源图层FeatureSourceLayer中,这个图层加载到osgEarth的图层列表中是不显示的,必须得再加载一个专门的符号化图层,将其符号号,才能正常显示。
osgearth

能够显示经纬度、海拔、分辨率:Osgearth_elevationfeature_model_scatter.earthOsgearth_graticuleOsgearth_featuresOsgearth_featurequeryC:\Program Files\NVIDIA Corporation\PhysX\Common;C:\Program Files\CMake 2.8\bin;F:\OSG视频教程\osgOcean与osgEarth编译相关包\osgEarth\proj446_win32_bin\proj\bin; E:\osgearth\openscenegraph\bin;E:\osgearth\osgearth\vs2010\bin\Debug;E:\osgearth\osgearth\vs2010\bin\Release;E:\osgOcean\osgOcean\vs2010\bin\Debug;E:\osgOcean\osgOcean\vs2010\bin\Release包含文件:E:\osgearth\OpenSceneGraph\include;E:\osgearth\sqlite\include;E:\osgearth\libzip\include;E:\osgearth\geos\include;E:\osg\libpng\include;E:\osg\3rdParty\x86\include;E:\osgearth\osgearth\include;E:\osgOcean\osgOcean\include;$(IncludePath)库文件:E:\osgearth\OpenSceneGraph\lib;E:\osgearth\sqlite\lib;E:\osgearth\libzip\lib;E:\osgearth\geos\lib;E:\osg\libpng\lib;E:\osg\3rdParty\x86\lib;E:\osgearth\osgearth\vs2010\lib;E:\osgOcean\osgOcean\vs2010\lib;$(LibraryPath)E:\osgearth\sqlite\lib;E:\osgearth\OpenSceneGraph\lib;E:\osgearth\libzip\lib;E:\osgearth\geos\lib; E:\osg\3rdParty\x86\lib;$(LibraryPath)E:\osgearth\osgearth\tests>osgearth_featurequery feature_stencil_polygon_draping.earth包含文件:E:\osgearth\OpenSceneGraph\include;E:\osgearth\sqlite\include;E:\osgearth\libzip\include;E:\osge arth\geos\include;E:\osg\libpng\include;E:\osg\3rdParty\x86\include;E:\osgearth\osgearth\include; E:\osgearth\osgearth\src;E:\osgOcean\osgOcean\include;$(IncludePath)库文件:E:\osgearth\OpenSceneGraph\lib;E:\osgearth\sqlite\lib;E:\osgearth\libzip\lib;E:\osgearth\geos\lib; E:\osg\libpng\lib;E:\osg\3rdParty\x86\lib;E:\osgearth\osgearth\vs2010\lib\Debug;E:\osgearth\osge arth\vs2010\lib;E:\osgOcean\osgOcean\vs2010\lib;$(LibraryPath)附加依赖项:OpenThreadsd.lib;osgd.lib;osgDBd.lib;osgFXd.lib;osgGAd.lib;osgManipulatord.lib;osgParticled.l ib;osgShadowd.lib;osgSimd.lib;osgTerraind.lib;osgTextd.lib;osgUtild.lib;osgViewerd.lib;osgdb_os gearth_feature_ogrd.lib;osgdb_osgearth_feature_tfsd.lib;osgdb_osgearth_feature_wfsd.lib;osgdb_ osgearth_gdald.lib;osgEarthd.lib;osgEarthAnnotationd.lib;osgEarthFeaturesd.lib;osgEarthSymbol ogyd.lib;osgEarthUtild.lib;%(AdditionalDependencies)。
osgearth学习文档

osgearth学习⽂档osgEarth::Drivers::TMSOptions Class Reference通过程序加载数据赶紧进⼊正题,程序加载各种数据,⾸先介绍⼀下总体的⽅式/*这⾥XXXOptions 是根据不同的数据类型选择不同驱动,⽐如加载本地数据可以使⽤GDALOptions ,加载TMS数据可以使⽤TMSOptions(注意TMSOptions可以加载本地也可以加载⽹上数据),WMSOptions可以加载⽹上数据(注意这个options主要加载影像和图⽚数据),ArcGISOptions加载ArcGIS Server发布数据。
*/osgEarth::Drivers::XXXOptions XXXLayer;/*这⾥就是加载的数据路径,如果加载的本地数据就是本地数据的路径,如果加载是⽹上数据就是相应的⽹址*/ XXXLayer.url()=osgEarth::URI(".................................");/*加载的数据是分层管理,每加载进来⼀个数据在earth上就是⼀个数据层,这⾥给数据层付个名字。
*/std::string LayerName="earth";/*osgearth⾥layer主要有三种类型ImageLayer、ElevationLayer和ModleLayer ,前两个⼤家从字⾯就可以知道第⼀个是加载影像和第⼆个是加载⾼程数据的,第三个是主要⽤来加载shp数据,⾄少我是这样⽤的,不知道还能否加载其他数据类型。
确定加载⽤的驱动、数据源位置(路径)、数据层名和初始化了数据层,接下来就是把数据层加到地球中如下所⽰。
*/osg::ref_ptr layer =new osgEarth::XXXLayer(osgEarth::XXXLayerOptions(LayerName,XXXLayer));m_pMap->addImageLayer(layer.get());(1)加载本地数据a 本地影像数据,数据类型为tifosgEarth::Drivers::GDALOptions imagelayerOpt;//选择GDALOptionsimagelayerOpt.url() = osgEarth::URI("E:\\vs2010Progam Files\\osgVR74\\osgVR74\\world.tif");//影像数据路径std::string imagelayerName = "worldimage"; //影像数据层名osg::ref_ptr imageLayer = new osgEarth::ImageLayer(osgEarth::ImageLayerOptions(imagelayerName ,imagelayerOpt));//初始数据层m_pMap->addImageLayer(imageLayer .get());b 本地⾼程数据,数据类型为tifosgEarth::Drivers::GDALOptions demlayerOpt;//使⽤还是GDALOptionsdemlayerOpt.url() = osgEarth::URI("E:\\vs2010Progam Files\\osgVR74\\osgVR74\\worlddem.tif");//⾼程数据路径std::string demlayerName = "worlddem";//⾼程数据层名osg::ref_ptr demLayer = new osgEarth::ImageLayer(osgEarth::ImageLayerOptions(demlayerName,demlayerOpt));//初始数据层m_pMap->addImageLayer(demLayer.get());加载本地经过package 切⽚的数据还可以⽤TMSOptions,osgEarth::Drivers::TMSOptions tmsOpt;////选择TMSOptions 驱动tmsOpt.url()=osgEarth::URI("//Edvis_-1/Layer_0/tms.xml");//package切⽚⽣成⾦字塔⽂件下的xmlstd::stringDemtmslayerName="TmsDem";//图层名osgEarth::ElevationLayerOptionstmslayerOpt(DemtmslayerName,tmsOpt);osg::ref_ptr TmsDemLayer = new osgEarth::ElevationLayer(tmslayerOpt);m_pMap->addElevationLayer(TmsDemLayer.get());//初始化图层并加⼊到地球中(2)加载⽹上数据a 加载ArcGIS Server 发布的数据加载⽅式与上⾯提到的类似osgEarth::Drivers::ArcGISOptions MapImageLayer;MapImageLayer.url()=osgEarth::URI("http://xxx.xxx.xxx.xxx.:xxxx/arcgis/rest/services/world/ma p003/MapServer");std::string CdlayerName="worldimage";osg::ref_ptr cdlayer =new osgEarth::ImageLayer(osgEarth::ImageLayerOptions(CdlayerName,MapImageLayer));m_pMap->addImageLayer(cdlayer.get());//这⾥注意,当osgearth访问ArcGIS Server 发布数据的时候有些问题很奇怪,⽤上⾯的⽅式访问ArcGIS Server 国外发布的数据没问题,但是访问⾃⼰发布的数据就会有问题,经过试验投影要设成3857才能正常访问。
osgearth 简单的例子

1. 介绍osgEarthosgEarth是一个开源的地理空间3D渲染引擎,它建立在OpenSceneGraph(OSG)之上,提供了一套方便易用的工具和库,用于构建高性能的3D地球可视化应用程序。
osgEarth支持多种数据格式和地理空间数据源,包括地形数据、卫星影像、矢量数据等,用户可以利用osgEarth快速、灵活地构建出各种类型的地球可视化应用。
2. osgEarth的基本概念在了解osgEarth之前,需要了解一些基本概念。
osgEarth使用用于地球可视化的场景图,其中包含了地形、卫星影像、矢量数据和其他图层信息。
osgEarth使用图层树来管理这些数据,每个图层都有自己的样式和渲染规则。
osgEarth还提供了一套简单的、高效的符号渲染系统,可以用于在地图中显示各种地理要素。
3. osgEarth的简单例子下面通过一个简单的例子来介绍osgEarth的基本用法。
假设我们有一些地形数据和卫星影像数据,我们希望将它们加载到osgEarth中进行可视化展示。
(1)我们需要创建一个OSG Viewer实例,作为osgEarth可视化的窗口。
(2)我们需要创建一个Map实例,用于管理地理空间数据。
我们可以向Map实例中添加地形图层和卫星影像图层。
(3)接下来,我们需要创建一个MapNode实例,它是地球可视化的根节点。
我们可以将Map实例和OSG Viewer实例传递给MapNode实例。
(4)我们将MapNode实例添加到OSG Viewer中,这样就完成了地球可视化的搭建工作。
通过以上简单的步骤,我们就可以将地形数据和卫星影像数据加载到osgEarth中进行可视化展示了。
当然,osgEarth还提供了丰富的样式和渲染规则设置,可以根据实际需求进行定制化操作。
4. 总结osgEarth作为一个开源的地理空间3D渲染引擎,提供了丰富的功能和灵活的工具,可以帮助用户快速、高效地构建各种类型的地球可视化应用。
OSGEarth学习

第一章OSGEarth学习这是个人在学习osgEarth时根据体会或从别的地方看到的做的一个简单整理,有些东东就是官方文档翻译过来的,都是根据自己的需要感觉需要记录下来什么东西就随便记录下来了,也没有个条理,都是用到哪记到哪,别见怪。
对个人在初期使用osgEarth时有很多帮助,所以特发上来,希望对大家也有帮助osgEarth学习笔记1. 通过earth文件创建图层时,可以指定多个影像数据源和多个高程数据源,数据源的顺序决定渲染顺序,在earth文件中处于最前的在渲染时处于最底层渲染;所以如果有高低精度不同的影响数据或者高程数据,在创建earth文件时要将粗精度的数据放在上方xml节点,高精度的放在其下面的节点;2. osgEarth自带多种驱动器,不同的驱动器驱动不同的数据源,自己也可以扩展驱动器读取相应的数据;3. 可以通过profile属性指定数据的投影方式或者数据分页方式以及地理空间延展;osgEarth通过profile创建数据四叉树,每个四叉树节点数据瓦片通过TileKey类来标示;一个地形数据能否正常工作要看创建它的驱动器是否能够创建和对应profile兼容的数据瓦片;比如,如果要生成地球数据,就需要指定global-geodetic 或者global-mercator profile,相应的数据源要能够在这种profile下生成相应的地形数据;4. 通过earth文件,最基本的也是最主要的功能是我们可以指定生成地形的坐标属性(地理坐标或投影坐标)影像数据、高程数据、矢量数据、模型数据、以及缓冲位置,通过这些基本要素就可以轻易生成我们想要的地形;5. osgEarth只能使用16或32位的高程数据源;6. 如果直接使用原始的影像、高程以及矢量数据,可以用GDAL驱动器,在这种情况下需要注意几个性能的问题。
第一,将数据源预先进行坐标变换,变换为目标地形坐标,否则osgEarth会对源数据进行坐标投影变换,这将降低数据的加载及处理速度。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
osgEarth::Drivers::TMSOptions Class Reference通过程序加载数据赶紧进入正题,程序加载各种数据,首先介绍一下总体的方式/*这里XXXOptions 是根据不同的数据类型选择不同驱动,比如加载本地数据可以使用GDALOptions ,加载TMS数据可以使用TMSOptions(注意TMSOptions可以加载本地也可以加载网上数据),WMSOptions可以加载网上数据(注意这个options主要加载影像和图片数据),ArcGISOptions加载ArcGIS Server发布数据。
*/osgEarth::Drivers::XXXOptions XXXLayer;/*这里就是加载的数据路径,如果加载的本地数据就是本地数据的路径,如果加载是网上数据就是相应的网址*/XXXLayer.url()=osgEarth::URI(".................................");/*加载的数据是分层管理,每加载进来一个数据在earth上就是一个数据层,这里给数据层付个名字。
*/std::string LayerName="earth";/*osgearth里layer主要有三种类型ImageLayer、ElevationLayer和ModleLayer ,前两个大家从字面就可以知道第一个是加载影像和第二个是加载高程数据的,第三个是主要用来加载shp数据,至少我是这样用的,不知道还能否加载其他数据类型。
确定加载用的驱动、数据源位置(路径)、数据层名和初始化了数据层,接下来就是把数据层加到地球中如下所示。
*/osg::ref_ptr<osgEarth::XXXLayer> layer =new osgEarth::XXXLayer(osgEarth::XXXLayerOptions(LayerName,XXXLayer));m_pMap->addImageLayer(layer.get());(1)加载本地数据a 本地影像数据,数据类型为tifosgEarth::Drivers::GDALOptions imagelayerOpt;//选择GDALOptionsimagelayerOpt.url() = osgEarth::URI("E:\\vs2010Progam Files\\osgVR74\\osgVR74\\world.tif");//影像数据路径std::string imagelayerName = "worldimage"; //影像数据层名osg::ref_ptr<osgEarth::ImageLayer> imageLayer = new osgEarth::ImageLayer(osgEarth::ImageLayerOptions(imagelayerName ,imagelayerOpt));//初始数据层m_pMap->addImageLayer(imageLayer .get());b 本地高程数据,数据类型为tifosgEarth::Drivers::GDALOptions demlayerOpt;//使用还是GDALOptionsdemlayerOpt.url() = osgEarth::URI("E:\\vs2010Progam Files\\osgVR74\\osgVR74\\worlddem.tif");//高程数据路径std::string demlayerName = "worlddem";//高程数据层名osg::ref_ptr<osgEarth::ImageLayer> demLayer = new osgEarth::ImageLayer(osgEarth::ImageLayerOptions(demlayerName,demlayerOpt));//初始数据层m_pMap->addImageLayer(demLayer.get());加载本地经过package 切片的数据还可以用TMSOptions,osgEarth::Drivers::TMSOptions tmsOpt;////选择TMSOptions 驱动tmsOpt.url()=osgEarth::URI("//Edvis_-1/Layer_0/tms.xml");//package切片生成金字塔文件下的xmlstd::stringDemtmslayerName="TmsDem";//图层名osgEarth::ElevationLayerOptionstmslayerOpt(DemtmslayerName,tmsOpt);osg::ref_ptr<osgEarth::ElevationLayer> TmsDemLayer = new osgEarth::ElevationLayer(tmslayerOpt);m_pMap->addElevationLayer(TmsDemLayer.get());//初始化图层并加入到地球中(2)加载网上数据a 加载ArcGIS Server 发布的数据加载方式与上面提到的类似osgEarth::Drivers::ArcGISOptions MapImageLayer;MapImageLayer.url()=osgEarth::URI("");std::string CdlayerName="worldimage";osg::ref_ptr<osgEarth::ImageLayer> cdlayer =new osgEarth::ImageLayer(osgEarth::ImageLayerOptions(CdlayerName,MapImageLayer));m_pMap->addImageLayer(cdlayer.get());//这里注意,当osgearth访问ArcGIS Server 发布数据的时候有些问题很奇怪,用上面的方式访问ArcGIS Server 国外发布的数据没问题,但是访问自己发布的数据就会有问题,经过试验投影要设成3857才能正常访问。
b 加载网上数据还可以用WMSOptions 加载方式同上。
2015/12/141.osgEarth::Util::MapNodeHelper.解析内部的命令行参数。
非静态成员变量不能使用类名直接访问。
例如:osgEarth::Util::MapNodeHelper:: load()这样的形式是错误的。
osg::Group * load (osg::ArgumentParser &args, osgViewer::View *view, Control *userControl=0L) const函数是载入map文件,解析所有的内部命令行参数与外部的XML文件。
2. osgEarth::MapNode。
建立OsgEarth的根节点。
3. osgEarth::Util::Controls::Grid. 此类是父类Container按照栅格形式组织子类。
4. osgEarth::Util::Controls::LabelControl.表示一个字符串的控件。
2015/12/151.void osgViewer::View::setCameraManipulator ( osgGA::CameraManipulator * manipulator, bool resetPosition = true )设置相机操作器。
OsgViewer::Viewer的继承关系如下图所示。
视图-View;视景器-Viewer。
osgViewer::View类别2015/12/171.osgGA::GUIEventHandler为GUI事件提供一个基本的接口。
2.osgEarth::Map map是mapNode所渲染的主要的数据模型,包括所有的层对象。
3. osgEarth::Terrain 是为地形图的接口服务的4 .osgEarth::ElevationQuery 查询地图上任意点的高程数据5. osgEarth::GeoPoint2015/12/201. osg::ArgumentParser 解析参数的类。
2. osgEarth::Annotation::ModelNode。
从URI传递一个3D模型(注释节点)然后放置在一个地理节点。
2015/12/21动态显示经纬度坐标以及高程方法1. osgEarth::SpatialReference Class.保留描述参考椭球体和地理空间数据的投影的相关数据。
2.osgEarth::MapNode Class 中的函数const SpatialReference * MapNode::getMapSRS()const.得到地图的地理空间参考系统。
3.osgEarth::Util::Controls:: ControlCanvas Class。
将控件与OSG视景相关联。
4. osgGA::GUIEventHandler 为GUI事件提供一个基本的接口。
在这个类的基础上,派生了其他的类,比如在高程与经纬度查询的osgViewer::StatsHandler类(为了增加屏幕状态到视景体的事件句柄),osgViewer::WindowSizeHandler类(改变窗口模式的屏幕分辨率和开关全屏模式和窗口模式的事件句柄),osgGA::StateSetManipulator类(实验类,不能被观察一段时间,但是能够返回到某个点)。
5.动态显示经纬度和高程经纬度查询的机制。
主要是利用碰撞检测机制,鼠标点在二维的屏幕上的坐标,然后利用碰撞检测求得世界坐标X,Y,Z,然后再将世界坐标转换成与地理相关的三维坐标,然后再将此地理三维坐标转换成与经纬度有关的坐标。
重写handle函数。
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ) {if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE &&aa.asView()->getFrameStamp()->getFrameNumber() % 10 == 0){osgViewer::View* view = static_cast<osgViewer::View*>(aa.asView());update( ea.getX(), ea.getY(), view );}return false;}其中的osgGA::GUIEventAdapter类是存储键盘,鼠标和窗口事件。