[osgearth]通過API創建一個earth模型


通過API的方式大體需要以下幾個步驟:

 

創建map對象——

創建影像數據層——

創建高程數據層——

將影像數據層以及高程數據層加入到map對象——

根據前面創建的map對象創建mapNode節點——

將mapNode節點加入到場景;

 

 

我們可以對地形進行修改操作,如添加新的影像、高程數據,移除特定的影像、高程數據,重新制定影像、高程數據的順序等;

 

 

趕緊進入正題,程序加載各種數據,首先介紹一下總體的方式

 

 

/*這里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  本地影像數據,數據類型為tif

 osgEarth::Drivers::GDALOptions imagelayerOpt;//選擇GDALOptions
 imagelayerOpt.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 本地高程數據,數據類型為tif

 osgEarth::Drivers::GDALOptions demlayerOpt; //使用還是GDALOptions

 demlayerOpt.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 切片生成金字塔文件下的 xml

std::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("http://xxx.xxx.xxx.xxx.:xxxx/arcgis/rest/services/world/map003/MapServer");
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 加載方式同上。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM