osgearth二维地球显示

需要用的GDAL

#include <osgEarth/MapNode>

#include <osgEarthDrivers/gdal/GDALOptions>
#include <osgEarthDrivers/cache_filesystem/FileSystemCache>
#include <osgEarth/ImageLayer>

#include <osgEarthUtil/EarthManipulator>        

        CPLSetConfigOption("GDAL_DATA", "D:\\OSG64\\osgearth\\gdal\\data");

		string wktString = "EPSG:3857";			//web墨卡托投影
		//string wktString = "EPSG:4326";			//wgs84
		osgEarth::ProfileOptions profileOpts;
		profileOpts.srsString() = wktString;
		
		//地图配置:设置缓存目录
		osgEarth::Drivers::FileSystemCacheOptions cacheOpts;
		string cacheDir = "D:/Work/OSGNewBuild/tmp";
		cacheOpts.rootPath() = cacheDir;
		//
		osgEarth::MapOptions mapOpts;
		mapOpts.cache() = cacheOpts;
		mapOpts.coordSysType() = osgEarth::MapOptions::CSTYPE_PROJECTED;

		mapOpts.profile() = profileOpts;

		//创建地图节点
		osg::ref_ptr<osgEarth::Map> map = new osgEarth::Map(mapOpts);
		osg::ref_ptr<osgEarth::MapNode> mapNode = new osgEarth::MapNode(map);

		osgEarth::Drivers::GDALOptions gdal;
		gdal.url() = "D:\\OSG64\\osgearth\\osgearth\\data/world.tif";
		osg::ref_ptr<osgEarth::ImageLayer> layer = new osgEarth::ImageLayer("BlueMarble", gdal);
		map->addImageLayer(layer);
		m_root->addChild(mapNode);
		osg::ref_ptr< osgEarth::Util::EarthManipulator> mainManipulator = new osgEarth::Util::EarthManipulator;
		m_viewer->setCameraManipulator(mainManipulator);

		m_viewer->setUpViewInWindow(100, 100, 800, 600);

 

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
OSGearth是一个功能强大的地理信息系统(GIS)软件工具包,用于开发和展示二维和三维地图。要在osgearth2.8中显示二维地图,您可以按照以下步骤进行操作: 1. 获得地图数据:首先,您需要获取包含二维地图数据的图层或数据源。您可以通过下载地图图层文件或连接到在线地图服务来获取数据。常见的图层文件格式包括ESRI Shapefile、GeoTIFF等。 2. 配置图层:在osgearth2.8中,您需要使用XML文件来配置图层。在XML文件中,您可以指定图层的类型(例如WMS、TMS等)、数据源路径和其他参数。根据您的实际需求,您可以配置多个图层。确保在XML文件中正确指定图层的投影、坐标系和图层顺序。 3. 创建地图视图:使用osgEarth API,您可以创建一个地图视图。地图视图是osgEarth显示地图数据的主要视窗。您可以指定地图的视锥体、背景色和其他视图参数。 4. 加载图层:在地图视图中加载图层,使用osgEarth API的功能将配置文件中定义的图层加载到地图视图中。确保正确加载图层,并根据需要进行设置和调整。 5. 显示地图:最后,通过执行osgViewer的循环来显示地图osgViewer会将地图视图显示在屏幕上,并处理用户交互事件,如缩放、平移和旋转等。 通过以上步骤,您可以使用osgearth2.8成功显示二维地图。请注意,这只是一个简单的概述,并不涵盖osgearth的所有功能和配置选项。要深入了解osgearth的更多特性和用法,请参考官方文档或其他学习资源。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值