ArcEngine提供了加载3dd文件的方法,却没有开放保存3dd文件的接口,通过查找资料,主要是采用二进制段实现了3dd文件的保存和加载,但是用这种方法保存的3dd文件其实是“伪”3dd文件,在ArcGlobe下是打不开的。下面是源代码:
private void button_Open3dd_Click (object sender,EventArgs e) { try { ClearGlobe(); OpenFileDialog open3ddDialog = new OpenFileDialog(); open3ddDialog.Title = "打开3dd文件"; open3ddDialog.Filter = "3dd文件(*.3dd)|*.3dd"; if(open3ddDialog.ShowDialog() == DialogResult.OK) { if(axGlobeControl1.Check3dFile(open3ddDialog.FileName)) { axGlobeControl1.Load3dFile(open3ddDialog.FileName); } else { IObjectStream pObjectStream = new ObjectStreamClass(); IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStreamClass(); pMemoryBlobStream.LoadFromFile(open3ddDialog.FileName); IPersistStream pPersistStream = m_globeControl.Globe as IPersistStream; pObjectStream.Stream = pMemoryBlobStream; pPersistStream.Load(pObjectStream); } } else { return; } } catch(System.Exception ex) { MessageBox.Show(ex.Message); } } private void button_Save3dd_Click (object sender,EventArgs e) { try { SaveFileDialog save3ddDialog = new SaveFileDialog(); save3ddDialog.Title = "保存3dd文件"; save3ddDialog.Filter = "3dd文件(*.3dd)|*.3dd"; save3ddDialog.FileName = "test.3dd"; if (save3ddDialog.ShowDialog()==DialogResult.OK) { IMemoryBlobStream pMemoryBlobStream = new MemoryBlobStream(); IObjectStream pObjectStream = new ObjectStream(); pObjectStream.Stream = pMemoryBlobStream; IPersistStream pPersistStream = m_globeControl.Globe as IPersistStream; pPersistStream.Save(pObjectStream,1); pMemoryBlobStream.SaveToFile(save3ddDialog.FileName); } else { return; } } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }还有需要注意的问题:如果在加载3dd时,当前globecontrol中有图层存在的话,会出现闪退,我在这里只是简单的把当前globe中的所有图层清空(ClearGlobe函数),也可以采用ArcGlobe的方式写一个提示对话框的方式来处理,这样就不会出现闪退了