首先就是中所周知的由世界坐标转成经纬度的方法,鼠标操作获取地理信息都是这样的。
如果已知经纬度,要得到高程主要有以下两种方法。
方法一:
GeoPoint gp(mapNode, lon, la, 0.0);
double query_resolution= 0.0;
double actual_resolution = 0.0;
float elevation = 0.0f;
osgEarth::ElevationQuery query(mapNode->getMap());
elevation= query.getElevation(gp,query_resolution, &actual_resolution);
return elevation;
方法二:
float elevation = 0.0;
mapNode->getTerrain()->getHeight(mapNode->getMapSRS(), lon,la, &elevation);
第一种方法速度比较慢release版本会快很多,第二种方法获得的高程在不同情况下会变化。
官方解释:The Terrain interface (on MapNode::getTerrain) returns heights based on scene graph intersection, i.e. the triangles in memory. So the value will differ depending on what level of detail of terrain tiles are currently paged into memory.
If you want to query the source elevation data directly you can use ElevationQuery object. It's slower, but more accurate since it samples the actual source data.
就是当数据不再内存时判断不准确。