OSGEarth基于经纬度获取高程数据

在添加了DEM数据后,有时需要基于经纬度查询某一点的高程信息,本文主要介绍了如何实现基于经纬度查询高程数据的实现过程。
首先加载头文件:

#include 
#include 
#include 

创建需要使用到的变量:

osg::ref_ptr mapNode;
double query_resolution;
double out_resolution;
double out_haml ;
osgEarth::ElevationQuery *query;

初始化变量:

query_resolution = 0.00000001;
out_resolution = 0.0;
osg::ref_ptr mp = osgDB::readNodeFile("./simple.earth");
mapNode = dynamic_cast(mp.get());
query = new osgEarth::ElevationQuery(mapNode->getMap());
out_haml = 0.0;

基于经纬度对高程信息进行查询:

query->getElevation(osgEarth::GeoPoint(mapNode->getMapSRS(), 112.900, 21.950, 0.0, osgEarth::AltitudeMode::ALTMODE_RELATIVE),out_haml, query_resolution, &out_resolution);

完整代码:

#include 
#include 
#include 
#include
using namespace std;

int main(){
	double query_resolution = 0.00000001;
	double out_resolution = 0.0;
	double out_haml = 0.0;
	osg::ref_ptr mp = osgDB::readNodeFile("./simple.earth");
	osg::ref_ptr  mapNode = dynamic_cast(mp.get());
	osgEarth::ElevationQuery *query = new osgEarth::ElevationQuery(mapNode->getMap());
	query->getElevation(osgEarth::GeoPoint(mapNode->getMapSRS(), 112.900, 21.950, 0.0, osgEarth::AltitudeMode::ALTMODE_RELATIVE),out_haml, query_resolution, &out_resolution);
	cout<<"高程信息为:"<

上述代码实现了对经度为112.900,纬度为21.950的地点的查询,其中query_resolution 设置得越小精度越高,out_haml为查询出的高程信息。

你可能感兴趣的:(OSG)