private void textBoxXTIN_TextChanged(object sender, EventArgs e) { m_TINPath = textBoxXTIN.Text; try { DirectoryInfo dir = Directory.CreateDirectory(m_TINPath); IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass(); IWorkspace pWS = pWSFact.OpenFromFile(dir.Parent.FullName + @"\", 0); ITinWorkspace pTinWS = pWS as ITinWorkspace; ITin pTin = pTinWS.OpenTin(dir.Name); m_pTin = pTin; IEnvelope pExtent = pTin.Extent; double dmaxextent = pExtent.Height; if (pExtent.Width > pExtent.Height) { dmaxextent = pExtent.Width; } double cellsize = dmaxextent / 250; doubleInputCellSize.Value = cellsize; } catch (SystemException ee) { //MessageBox.Show(ee.Message); } }
/// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { // TODO: Add CmdAddTinLayer.OnClick implementation FolderBrowserDialog fdlg = new FolderBrowserDialog(); //fdlg.SelectedPath = @"C:\Users\Administrator\Desktop\sampleAnalysis\TIN\"; try { if (fdlg.ShowDialog() != DialogResult.OK) { return; } //FrmFolderDialog dlg = new FrmFolderDialog(); //dlg.DisplayDialog(); if (fdlg.SelectedPath != "") { // DirectoryInfo dir = Directory.CreateDirectory(dlg.Path); DirectoryInfo dir = Directory.CreateDirectory(fdlg.SelectedPath); IWorkspaceFactory pWSFact = new TinWorkspaceFactoryClass(); IWorkspace pWS = pWSFact.OpenFromFile(dir.Parent.FullName + @"\", 0); ITinWorkspace pTinWS = pWS as ITinWorkspace; ITin pTin = pTinWS.OpenTin(dir.Name); //½«TIN±äΪTINͼ²ã ITinLayer pTinLayer = new TinLayerClass(); pTinLayer.Dataset = pTin; pTinLayer.Name = dir.Name; IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; pMapCtr.Map.AddLayer((ILayer)pTinLayer); } } catch (SystemException ee) { MessageBox.Show(ee.Message); } }
/// <summary> /// 加载栅格图层 /// </summary> private void AddTinFile() { this.Cursor = Cursors.WaitCursor; IWorkspaceFactory pWorkspaceFactory = new TinWorkspaceFactoryClass(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(m_Path, 0); ITinWorkspace pTinWorkspace = pWorkspace as ITinWorkspace; //声明一个pTin变量, 存储所打开的"tin" ITin pTin = pTinWorkspace.OpenTin("tin"); //将TIN变为TIN图层 ITinLayer pTinLayer = new TinLayerClass(); pTinLayer.Dataset = pTin; pTinLayer.Name = "TIN"; //也可以用三维空间AxSceneControl加载 axSceneControl1.Scene.AddLayer(pTinLayer, true); //this.axMapControl1.AddLayer(pTinLayer); this.Cursor = Cursors.Default; }
public static bool AddDataset(ref IBasicMap pBasicMap, IDatasetName pDatasetName, List <IDataset> m_DatasetCol, bool blnAddData) { bool functionReturnValue = false; functionReturnValue = false; ////如果是特征数据集,则添加里边的所有要素类 IFeatureDataset pFeatDS = default(IFeatureDataset); IEnumDataset pEnumDataSet = default(IEnumDataset); IDataset pDataset = default(IDataset); IFeatureClass pFeatCls = default(IFeatureClass); IFeatureLayer pFeatLayer = default(IFeatureLayer); IName pName = default(IName); ILayer pLayer = default(ILayer); ITopologyLayer pTopoLayer = default(ITopologyLayer); //Dim pEnumLyr As IEnumLayer ITinWorkspace pTinWS = default(ITinWorkspace); IEnumFeatureClass pEnumFeatCls = null; IRasterCatalogDisplayProps pRasterCatalogPro = default(IRasterCatalogDisplayProps); //WHFErrorHandle.clsErrorHandle pfrmError = new WHFErrorHandle.clsErrorHandle(); if (pDatasetName is IFeatureDatasetName) { pName = (IName)pDatasetName; pFeatDS = (IFeatureDataset)pName.Open(); pEnumDataSet = pFeatDS.Subsets; pDataset = pEnumDataSet.Next(); m_DatasetCol.Add(pDataset); if (pDataset == null) { return(functionReturnValue); } ////根据数据集的类型,添加特征数据集中的所有要素类(拓扑,一般的,栅格目录,网络) while ((pDataset != null)) { if (pDataset.Type == esriDatasetType.esriDTFeatureClass) { pFeatLayer = null; if (pFeatLayer == null) { pFeatLayer = new FeatureLayer(); pFeatCls = (IFeatureClass)pDataset; pFeatLayer.Name = pFeatCls.AliasName; pFeatLayer.FeatureClass = pFeatCls; } if (pDataset.Type == esriDatasetType.esriDTRasterCatalog) { // Dim pRaster } // pSelectedCln.Add(pFeatLayer) } else if (pDataset.Type == esriDatasetType.esriDTTopology) { pTopoLayer = new TopologyLayerClass(); pTopoLayer.Topology = (ITopology)pDataset; pLayer = (ILayer)pTopoLayer; pLayer.Name = pDataset.Name; //pSelectedCln.Add(pFeatLayer) } pDataset = pEnumDataSet.Next(); } functionReturnValue = true; ////添加拓扑图层 } else if (pDatasetName is ITopologyName) { ITopology pTopo = null; pName = (IName)pDatasetName; pDataset = (IDataset)pName.Open(); pTopoLayer = new TopologyLayerClass(); pTopoLayer.Topology = (ITopology)pDataset; pLayer = (ILayer)pTopoLayer; pLayer.Name = pDataset.Name; m_DatasetCol.Add(pDataset); if (blnAddData == true) { //pMap.AddLayer pLayer AddLyrToBasicMap(ref pBasicMap, pLayer); //SortLayer(pBasicMap, pLayer) } //pSelectedCln.Add(pLayer) //if (pfrmError.DisplayInformation("要把拓扑里边的所有要素类也添加到当前地图中吗?") == true) if (MessageBoxEx.Show("要把拓扑里边的所有要素类也添加到当前地图中吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { IFeatureClassContainer pFeatClsContainer = default(IFeatureClassContainer); pFeatClsContainer = (IFeatureClassContainer)pTopo; pEnumFeatCls = pFeatClsContainer.Classes; pFeatCls = pEnumFeatCls.Next(); pFeatLayer = new FeatureLayer(); ////循环拓扑中的每个要素类,并添加到当前地图中 while ((pFeatCls != null)) { pFeatLayer.FeatureClass = pFeatCls; pFeatLayer.Name = pFeatCls.AliasName; if (blnAddData == true) { //pMap.AddLayer pFeatLayer AddLyrToBasicMap(ref pBasicMap, pFeatLayer); //SortLayer(pBasicMap, pFeatLayer) } //pSelectedCln.Add(pFeatLayer) pFeatCls = pEnumFeatCls.Next(); } } functionReturnValue = true; ////添加网络数据 } else if (pDatasetName is IGeometricNetworkName) { INetworkCollection pNetworkCollection = default(INetworkCollection); IGeometricNetwork pGeometricNetwork = default(IGeometricNetwork); int i = 0; int j = 0; IDataset pGeoDataset = default(IDataset); pName = (IName)pDatasetName; pGeoDataset = (IDataset)pName.Open(); m_DatasetCol.Add(pGeoDataset); if (pGeoDataset.Type == esriDatasetType.esriDTGeometricNetwork) { ////这里对网络数据进行处理 IFeatureClassContainer pFeatureClassContainer = default(IFeatureClassContainer); pGeometricNetwork = (IGeometricNetwork)pGeoDataset; pFeatureClassContainer = (IFeatureClassContainer)pGeometricNetwork; for (i = 0; i <= pFeatureClassContainer.ClassCount - 1; i++) { pFeatCls = pFeatureClassContainer.get_Class(i); pFeatLayer = new FeatureLayer(); pFeatLayer.Name = pFeatCls.AliasName; pFeatLayer.FeatureClass = pFeatCls; if (blnAddData == true) { // pMap.AddLayer pFeatLayer AddLyrToBasicMap(ref pBasicMap, pFeatLayer); //SortLayer(pBasicMap, pFeatLayer) } //pSelectedCln.Add(pFeatLayer) } } else { pFeatDS = (IFeatureDataset)pGeoDataset; pNetworkCollection = (INetworkCollection)pFeatDS; ////如果是用户选择一个网络技术打开的话,肯定只有一个网络在里边,其实 ////可以不需要循环,而用GeometricNetwork(0)代替循环 for (j = 0; j <= pNetworkCollection.GeometricNetworkCount - 1; j++) { pGeometricNetwork = pNetworkCollection.get_GeometricNetwork(j); for (i = 0; i <= 3; i++) { switch (i) { case 0: pEnumFeatCls = pGeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleJunction); break; case 1: pEnumFeatCls = pGeometricNetwork.get_ClassesByType(esriFeatureType.esriFTSimpleEdge); break; case 2: pEnumFeatCls = pGeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexJunction); break; case 3: pEnumFeatCls = pGeometricNetwork.get_ClassesByType(esriFeatureType.esriFTComplexEdge); break; } pFeatCls = pEnumFeatCls.Next(); while ((pFeatCls != null)) { pFeatLayer = new FeatureLayer(); pFeatLayer.Name = pFeatCls.AliasName; pFeatLayer.FeatureClass = pFeatCls; pFeatCls = pEnumFeatCls.Next(); if (blnAddData == true) { //pMap.AddLayer pFeatLayer AddLyrToBasicMap(ref pBasicMap, pFeatLayer); //SortLayer(pBasicMap, pFeatLayer) } // pSelectedCln.Add(pFeatLayer) functionReturnValue = true; } } } } ////添加栅格目录,并设置为显示最新时相 } else if (pDatasetName is IRasterCatalogName) { pName = (IName)pDatasetName; pDataset = (IDataset)pName.Open(); m_DatasetCol.Add(pDataset); pFeatLayer = new GdbRasterCatalogLayerClass(); pFeatLayer.FeatureClass = (IFeatureClass)pDataset; pFeatLayer.Name = pDataset.Name; //'//如果是SDE的栅格目录 //If pFeatLayer.DataSourceType = "SDE Raster Catalog" Then // Dim pFeatLayerDef As IFeatureLayerDefinition // pFeatLayerDef = pFeatLayer // '//设置最初显示地图范围内最近时相的数据 // pFeatLayerDef.DefinitionExpression = "objectid in (select objectid from" & vbNewLine & _ // "(select a.objectid, b.receive_date,rank()" & vbNewLine & _ // "over(partition by a.name,a.resolution order by b.receive_date desc) as cid" & vbNewLine & _ // "from " & pFeatLayer.Name & " a, sj_t_tense b" & vbNewLine & _ // "where a.tense = b.tense" & vbNewLine & "and b.online_state = 1) t2" & vbNewLine & _ // "where " & pFeatLayer.Name & ".objectid=t2.objectid and t2.cid = 1)" //End If ////设置当栅格目录中的图幅在地图上超过16个的时候,以格网来显示,而不显示栅格本身 pRasterCatalogPro = (IRasterCatalogDisplayProps)pFeatLayer; ////不用数量来控制了,而以比例尺来控制 pRasterCatalogPro.DisplayRasters = 16; pRasterCatalogPro.UseScale = true; ////设置一个比例,在此临界栅格数据将会在框架显示与实际栅格显示之间转换 pRasterCatalogPro.TransitionScale = 50000; if (blnAddData == true) { //pMap.AddLayer pFeatLayer AddLyrToBasicMap(ref pBasicMap, pFeatLayer); //'SortLayer(pBasicMap, pFeatLayer) } //pSelectedCln.Add(pFeatLayer) functionReturnValue = true; // 陈昉 2009-3-22 添加单一的RasterDataset } else if (pDatasetName is IRasterDatasetName) { IRasterLayer pRasterLayer = default(IRasterLayer); pName = (IName)pDatasetName; pDataset = (IDataset)pName.Open(); m_DatasetCol.Add(pDataset); pRasterLayer = new RasterLayerClass(); pRasterLayer.CreateFromDataset(pDataset as IRasterDataset); pRasterLayer.Name = pDataset.Name; AddLyrToBasicMap(ref pBasicMap, pRasterLayer); functionReturnValue = true; ////添加TIN图层 } else if (pDatasetName is ITinWorkspace) { pTinWS = (ITinWorkspace)pDatasetName; ITinLayer pTinLyr = default(ITinLayer); pTinLyr = new TinLayer(); pTinLyr.Dataset = pTinWS.OpenTin(pDatasetName.Name); pTinLyr.Name = pDatasetName.Name; if (blnAddData == true) { //pMap.AddLayer pTinLyr AddLyrToBasicMap(ref pBasicMap, pTinLyr); //SortLayer(pBasicMap, pTinLyr) } //pSelectedCln.Add(pTinLyr) functionReturnValue = true; ////添加一般的要素类,未写完。。。。。。 } else { pName = (IName)pDatasetName; pDataset = (IDataset)pName.Open(); pFeatCls = (IFeatureClass)pDataset; m_DatasetCol.Add(pDataset); if (pFeatCls.FeatureType == esriFeatureType.esriFTAnnotation) { pFeatLayer = new FDOGraphicsLayerClass(); } else if (pFeatCls.FeatureType == esriFeatureType.esriFTDimension) { pFeatLayer = new DimensionLayerClass(); } else { pFeatLayer = new FeatureLayer(); } //印骅 20081205 添加"Not" if ((pFeatLayer != null)) { //pFeatLayer.Name = pDataset.Name pFeatLayer.Name = pFeatCls.AliasName; pFeatLayer.FeatureClass = (IFeatureClass)pDataset; } if (blnAddData == true) { //pMap.AddLayer pFeatLayer AddLyrToBasicMap(ref pBasicMap, pFeatLayer); //SortLayer(pBasicMap, pFeatLayer) } //pSelectedCln.Add(pFeatLayer) functionReturnValue = true; } return(functionReturnValue); //'//添加Coverage图层 //ElseIf vItem.SmallIcon = "Coverage" Then //AddSelectedLayer = ADDCoverageLayer(pMap, pCurrentFilePath.Path, _ //vItem.Text, pSelectedCln, blnAddData) }
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; } } } }
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; } } } }