/// <summary> /// 从文件夹获取Tin图层 /// </summary> /// <param name="strPath"></param> /// <returns></returns> public static ILayer GetTinLayer(string strPath) { if (string.IsNullOrEmpty(strPath) || !Directory.Exists(strPath)) return null; //DirectoryInfo dirInfo = new DirectoryInfo(strPath); //string strParent=dirInfo.Parent.FullName; //string strName=dirInfo.Name; string strParent = Path.GetDirectoryName(strPath); string strName = Path.GetFileName(strPath); IWorkspaceFactory wsfTin = new TinWorkspaceFactoryClass(); if (!wsfTin.IsWorkspace(strParent)) return null; try { IWorkspace wsTin = wsfTin.OpenFromFile(strParent, 0); ITin tinTarget = (wsTin as ITinWorkspace).OpenTin(strName); ITinLayer lyrTin = new TinLayerClass(); lyrTin.Dataset = tinTarget; return lyrTin; } catch { return null; } }
// // // public static ILayer openTinLayer(string fullPath) { ITinWorkspace pTinWorkspace; IWorkspace pWS; IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass(); ITinLayer pTinLayer = new TinLayerClass(); string pathToWorkspace = System.IO.Path.GetDirectoryName(fullPath); string tinName = System.IO.Path.GetFileName(fullPath); ITin pTin; pWS = pWSFact.OpenFromFile(pathToWorkspace, 0); pTinWorkspace = pWS as ITinWorkspace; if (pTinWorkspace.get_IsTin(tinName)) { pTin = pTinWorkspace.OpenTin(tinName); pTinLayer.Dataset = pTin; pTinLayer.ClearRenderers(); return pTinLayer as ILayer; } else { MessageBox.Show("��Ŀ¼������Tin�ļ�"); return null; } }
/// <summary> /// 通过TIN文件,建立*.shp文件 /// </summary> /// <param name="TINDir">TIN文件的文件夹路径</param> private void CreateContourData(string TINDir) { try { IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); CopyFolder(Application.StartupPath + "\\Convert\\TemContour", Application.StartupPath + "\\Convert\\ContourResult\\" + this.Random); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\Convert\\ContourResult\\" + this.Random, 0); IWorkspaceEdit w = pWorkspace as IWorkspaceEdit; IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass tFeatureClass = pFeatureWorkspace.OpenFeatureClass("Contour.shp"); ITinWorkspace pTinWorkspace; IWorkspace pWS; IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass(); pWS = pWSFact.OpenFromFile(TINDir, 0); ITin pTin; pTinWorkspace = pWS as ITinWorkspace; w.StartEditing(true); w.StartEditOperation(); if (pTinWorkspace.get_IsTin(this.Random)) { pTin = pTinWorkspace.OpenTin(this.Random); ITinSurface pTinSurface = pTin as ITinSurface; pTinSurface.Contour(0, this.Interval, tFeatureClass, "Z", 0); w.StopEditOperation(); w.StopEditing(true); } } catch (Exception) { } }
public void ThreeDToolLibrary(string toolName) { switch (toolName) { case"3DOpen": m_command = new ControlsSceneOpenDocCommandClass(); break; case "Navigation": m_command = new ControlsSceneNavigateToolClass(); break; case"3DZoomIn": m_command = new ControlsSceneZoomInToolClass(); break; case "3DZoomOut": m_command = new ControlsSceneZoomOutToolClass(); break; case "3DPan": m_command = new ControlsScenePanToolClass(); break; case"3DExtent": m_command = new ControlsSceneFullExtentCommandClass(); break; case"3DSel": m_command = new ControlsSceneSelectGraphicsToolClass(); break; } if (m_command is ITool) { m_command.OnCreate(m_sceneControl.Object); m_sceneControl.CurrentTool = (ITool)m_command; } if (m_command is ICommand) { m_command.OnCreate(m_sceneControl.Object); m_command.OnClick(); } m_command = null; if (toolName == "3DAddTIN") { FolderBrowserDialog fdlg = new FolderBrowserDialog(); fdlg.Description = "打开TIN"; if (fdlg.ShowDialog() == DialogResult.OK) { IWorkspaceFactory wsFac = new TinWorkspaceFactoryClass(); if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath))) { ITinWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as ITinWorkspace; ITinLayer tinLyr = new TinLayerClass(); try { tinLyr.Dataset = tinWS.OpenTin(System.IO.Path.GetFileName(fdlg.SelectedPath)); this.m_sceneControl.Scene.AddLayer((ILayer)tinLyr,false); SetTinAsBase(tinLyr); } catch { MessageBox.Show("请选择有效的TIN文件!"); } } else { MessageBox.Show("请选择有效的TIN文件!"); return; } } } if (toolName == "3DAddDEM") { FolderBrowserDialog fdlg = new FolderBrowserDialog(); fdlg.Description = "打开DEM"; if (fdlg.ShowDialog() == DialogResult.OK) { IWorkspaceFactory wsFac = new RasterWorkspaceFactoryClass(); if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath))) { IRasterWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as IRasterWorkspace; IRasterLayer rasLyr = new RasterLayerClass(); try { rasLyr.CreateFromDataset(tinWS.OpenRasterDataset(System.IO.Path.GetFileName(fdlg.SelectedPath))); this.m_sceneControl.Scene.AddLayer((ILayer)rasLyr, false); SetlayerSurface(rasLyr, 1); //this.axSceneControl1.Refresh(); } catch { MessageBox.Show("请选择有效的DEM文件!"); } } else { MessageBox.Show("请选择有效的DEM文件!"); return; } } } }
public void StandardToolLibrary(string toolName) { switch (toolName) { case "AddData": m_command = new ControlsAddDataCommandClass(); break; case"New": m_command = new CreateNewDocument(); break; case"Open": m_command = new ControlsOpenDocCommandClass(); break; case"Save": break; case"SaveAs": m_command = new ControlsSaveAsDocCommandClass(); break; case "CADToVec": m_command = new AddCADToFeatures(); break; case "CADToRas": m_command = new AddCADToRaster(); break; } if(m_command!=null) { m_command.OnCreate(m_mapControl.Object); m_command.OnClick(); m_command = null; } if (toolName == "Open") { m_frmMian.ControlsSynchronizer.ReplaceMap(m_mapControl.Map); } if (toolName == "AddTin") { FolderBrowserDialog fdlg = new FolderBrowserDialog(); fdlg.Description = "打开TIN"; if (fdlg.ShowDialog() == DialogResult.OK) { IWorkspaceFactory wsFac = new TinWorkspaceFactoryClass(); if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath))) { ITinWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as ITinWorkspace; ITinLayer tinLyr = new TinLayerClass(); try { tinLyr.Dataset = tinWS.OpenTin(System.IO.Path.GetFileName(fdlg.SelectedPath)); tinLyr.Name = System.IO.Path.GetFileName(fdlg.SelectedPath); this.m_mapControl.Map.AddLayer((ILayer)tinLyr); } catch { MessageBox.Show("请选择有效的TIN文件!"); } } else { MessageBox.Show("请选择有效的TIN文件!"); return; } } } if (toolName == "AddDEM") { FolderBrowserDialog fdlg = new FolderBrowserDialog(); fdlg.Description = "打开DEM"; if (fdlg.ShowDialog() == DialogResult.OK) { IWorkspaceFactory wsFac = new RasterWorkspaceFactoryClass(); if (wsFac.IsWorkspace(System.IO.Path.GetDirectoryName(fdlg.SelectedPath))) { IRasterWorkspace tinWS = wsFac.OpenFromFile(System.IO.Path.GetDirectoryName(fdlg.SelectedPath), 0) as IRasterWorkspace; IRasterLayer rasLyr = new RasterLayerClass(); try { rasLyr.CreateFromDataset(tinWS.OpenRasterDataset(System.IO.Path.GetFileName(fdlg.SelectedPath))); this.m_mapControl.Map.AddLayer((ILayer)rasLyr); } catch { MessageBox.Show("请选择有效的DEM文件!"); } } else { MessageBox.Show("请选择有效的DEM文件!"); return; } } } }