/// <summary> /// 获取网络数据 /// </summary> /// <param name="netCollection"></param> /// <param name="index"></param> /// <returns></returns> public static IGeometricNetwork GetGeometricNetWork(INetworkCollection netCollection, int index) { if (index < 0 || index >= netCollection.GeometricNetworkCount) { throw new Exception("索引异常"); } IGeometricNetwork pGeoNet = netCollection.get_GeometricNetwork(index); return(pGeoNet); }
/// <summary> /// 获取网络数据 /// </summary> /// <param name="netCollection"></param> /// <param name="index"></param> /// <returns></returns> public static IGeometricNetwork GetGeometricNetWork(string dbFileName, string datasetName, int index) { INetworkCollection netCollection = OpenNetworkCollection(dbFileName, datasetName); if (index < 0 || index >= netCollection.GeometricNetworkCount) { throw new Exception("索引异常"); } IGeometricNetwork pGeoNet = netCollection.get_GeometricNetwork(index); return(pGeoNet); }
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) }
//初始化几何网络和地图 private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset) { IFeatureClassContainer ipFeatureClassContainer; IFeatureClass ipFeatureClass; IGeoDataset ipGeoDataset; ILayer ipLayer; IFeatureLayer ipFeatureLayer; IEnvelope ipEnvelope, ipMaxEnvelope; double dblSearchTol; INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection; int count = ipNetworkCollection.GeometricNetworkCount; //获取第一个几何网络工作空间 m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0); INetwork ipNetwork = m_ipGeometricNetwork.Network; if (m_ipMap != null) { //m_ipMap = new MapClass(); ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer; count = ipFeatureClassContainer.ClassCount; for (int i = 0; i < count; i++) { ipFeatureClass = ipFeatureClassContainer.get_Class(i); ipFeatureLayer = new FeatureLayerClass(); ipFeatureLayer.FeatureClass = ipFeatureClass; for (int j = 0; j < m_ipMap.LayerCount; j++) { if (m_ipMap.get_Layer(j).Name.ToUpper() == ipFeatureLayer.Name.ToUpper()) { continue; } } m_ipMap.AddLayer(ipFeatureLayer); } m_ipActiveView.Refresh(); } count = m_ipMap.LayerCount; ipMaxEnvelope = new EnvelopeClass(); for (int i = 0; i < count; i++) { ipLayer = m_ipMap.get_Layer(i); ipFeatureLayer = ipLayer as IFeatureLayer; ipGeoDataset = ipFeatureLayer as IGeoDataset; ipEnvelope = ipGeoDataset.Extent; ipMaxEnvelope.Union(ipEnvelope); } m_ipPointToEID = new PointToEIDClass(); m_ipPointToEID.SourceMap = m_ipMap; m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork; double dblWidth = ipMaxEnvelope.Width; double dblHeight = ipMaxEnvelope.Height; if (dblWidth > dblHeight) { dblSearchTol = dblWidth / 100; } else { dblSearchTol = dblHeight / 100; } m_ipPointToEID.SnapTolerance = dblSearchTol; return(true); }