ArcGlobe控件加载与保存文档

来源:互联网 发布:手机屏幕特效软件 编辑:程序博客网 时间:2024/06/06 00:35

在操作*.3dd文档时,ArcEngine给我们提供了IGlobeDocument的接口来操作*.3dd的文档,但是从arcgis developer Help的帮助文档中,我们可以了解到实际上对于AE开发已经不支持用IGlobeDocument的接口;

IGlobeDocument  - The IGlobeDocument interface provides properties and methods for reading globe document files (*.3dd) and writing and saving changes to globe document files (*.3dd).  However, since it is not tied to the ArcGlobe application, application-specific functionality in the GlobeDocument will not be persisted.

虽然下面可以通过IGlobeDocument打开*.3dd的文档,但是我们不能像AxMapControl.Map属性给AxGlobeControl.Globe赋属性,所以即使我们通过文档打开了,也不能够赋给控件,而时要用AxGlobeControl.Load3dFile方法来加载文档。

当我们把AxGlobeControl.Globe赋给IGlobeDocument.Globe的属性时然后来保存的话就会报下面的错误:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt

所以我们要通过文档(像IMapDocument)来与控件界面进行直接传递就行不能了,那我们就需要换个方式来实现文档的加载与保存

AxGlobeControl.Load3dFile方法可以直接加载*.3dd文档

保存*.3dd文档方法:

1. try  

2.     {  

3.         SaveFileDialog save3ddDialog = new SaveFileDialog();  

4.         save3ddDialog.Title = "保存3dd文件";  

5.         save3ddDialog.Filter = "3dd文件(*.3dd)|*.3dd";  

6.         save3ddDialog.FileName = "test.3dd";  

7.         if (save3ddDialog.ShowDialog()==DialogResult.OK)  

8.         {  

9.   

10.             IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStream();  

11.             IObjectStream pObjectStream = new ObjectStream();  

12.             pObjectStream.Stream = pMemoryBlobStream;  

13.             IPersistStream pPersistStream = m_globeControl.Globe as IPersistStream;  

14.             pPersistStream.Save(pObjectStream,1);  

15.             pMemoryBlobStream.SaveToFile(save3ddDialog.FileName);  

16.         }  

17.         else  

18.         {  

19.             return;  

20.         }  

21.     }  

22.     catch (System.Exception ex)  

23.     {  

24.         MessageBox.Show(ex.Message);  

25.     }  


通过这种数据流的方式保存的*.3dd文档并不是arcgis所谓的*.3dd文档,只不过后缀名同样是*.3dd,

所以这样的保存的文档我们是不能够直接通过ArcGlobe来打开;我们就需要用同样的方式来打开自定义保存的*.3dd文档;

打开*.3dd文档

1.  try  

2.     {  

3.         ClearGlobe();  

4.         OpenFileDialog open3ddDialog = new OpenFileDialog();  

5.         open3ddDialog.Title = "打开3dd文件";  

6.         open3ddDialog.Filter = "3dd文件(*.3dd)|*.3dd";  

7.   

8.         if(open3ddDialog.ShowDialog() == DialogResult.OK)  

9.         {  

10.             if(axGlobeControl1.Check3dFile(open3ddDialog.FileName))  

11.             {  

12.                 axGlobeControl1.Load3dFile(open3ddDialog.FileName);  

14.             }  

15.             else  

16.             {  

17.                 IObjectStream pObjectStream = new ObjectStreamClass();  

18.                 IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass();  

19.                 pMemoryBlobStream.LoadFromFile(open3ddDialog.FileName);  

20.                 IPersistStream pPersistStream = m_globeControl.Globe as IPersistStream;  

21.                 pObjectStream.Stream = pMemoryBlobStream;  

22.                 pPersistStream.Load(pObjectStream);  

24.             }     

26.         }  

27.         else  

28.         {  

29.             return;  

30.         }  

31.     }  

32.     catch(System.Exception ex)  

33.     {  

34.         MessageBox.Show(ex.Message);  

35.     }  



0 0
原创粉丝点击