//加载数据集
        private void button3_Click(object sender, EventArgs e)
        {
            IFeatureWorkspace      pFeaWS         = pWorkspace as IFeatureWorkspace;
            List <IFeatureDataset> FeatureDSList2 = new List <IFeatureDataset>();

            for (int i = 0; i < checkedListBox1.CheckedItems.Count; i++)
            {
                foreach (IFeatureDataset eachDS in FeatureDSList)
                {
                    if (eachDS.Name == checkedListBox1.CheckedItems[i].ToString())
                    {
                        FeatureDSList2.Add(eachDS);
                    }
                }
            }
            foreach (IFeatureDataset FeaDS2 in FeatureDSList2)
            {
                IEnumDataset pEnumDS = FeaDS2.Subsets;
                IDataset     pFeaDS2;
                while ((pFeaDS2 = pEnumDS.Next()) != null)
                {
                    if (pFeaDS2 is IFeatureClass)
                    {
                        IFeatureLayer pFeaLayer = new FeatureLayer();
                        pFeaLayer.FeatureClass = pFeaWS.OpenFeatureClass(pFeaDS2.Name);
                        pFeaLayer.Name         = pFeaDS2.Name;
                        pMap.AddLayer(pFeaLayer as ILayer);
                    }
                }
                //加载拓扑结果
                ITopologyLayer     pTopolayer;
                ITopology          pTopology;
                ILayer             pLayer;
                ITopologyContainer pTopoContainer = (ITopologyContainer)FeaDS2;
                for (int i = 0; i < pTopoContainer.TopologyCount; i++)
                {
                    pTopolayer          = new TopologyLayerClass();
                    pTopology           = pTopoContainer.Topology[i];
                    pTopolayer.Topology = pTopology;
                    pLayer      = pTopolayer as ILayer;
                    pLayer.Name = FeaDS2.Name + "_拓扑" + i + 1;
                    pMap.AddLayer(pLayer);
                }
            }
        }
Exemplo n.º 2
0
        public static void AddDataset(IBasicMap pMap, IDataset pDataset, string dsName)
        {
            IFeatureLayer fDOGraphicsLayerClass;
            IFeatureClass j;
            IFeatureLayer featureLayerClass;

            if (dsName == null)
            {
                dsName = "";
            }
            switch (pDataset.Type)
            {
            case esriDatasetType.esriDTFeatureDataset:
            {
                IEnumDataset subsets = pDataset.Subsets;
                subsets.Reset();
                for (IDataset i = subsets.Next(); i != null; i = subsets.Next())
                {
                    MapHelper.AddDataset(pMap, i, dsName);
                }
                return;
            }

            case esriDatasetType.esriDTFeatureClass:
            {
                IFeatureClass idataset0 = (IFeatureClass)pDataset;
                if (idataset0.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    fDOGraphicsLayerClass = new FDOGraphicsLayerClass();
                    try
                    {
                        fDOGraphicsLayerClass.FeatureClass = idataset0;
                        fDOGraphicsLayerClass.Name         = string.Concat(dsName, idataset0.AliasName);
                        pMap.AddLayer(fDOGraphicsLayerClass);
                        return;
                    }
                    catch (Exception exception)
                    {
                        exception.ToString();
                        return;
                    }
                }
                else if (idataset0.FeatureType != esriFeatureType.esriFTDimension)
                {
                    fDOGraphicsLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = idataset0,
                        Name         = string.Concat(dsName, idataset0.AliasName)
                    };
                    pMap.AddLayer(fDOGraphicsLayerClass);
                    return;
                }
                else
                {
                    fDOGraphicsLayerClass = new DimensionLayerClass()
                    {
                        FeatureClass = idataset0,
                        Name         = string.Concat(dsName, idataset0.AliasName)
                    };
                    pMap.AddLayer(fDOGraphicsLayerClass);
                    return;
                }
                break;
            }

            case esriDatasetType.esriDTPlanarGraph:
            case esriDatasetType.esriDTText:
            case esriDatasetType.esriDTRelationshipClass:
            {
                return;
            }

            case esriDatasetType.esriDTGeometricNetwork:
            {
                IGeometricNetwork geometricNetwork = pDataset as IGeometricNetwork;
                if (geometricNetwork == null)
                {
                    return;
                }
                IEnumFeatureClass classesByType =
                    geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge];
                classesByType.Reset();
                for (j = classesByType.Next(); j != null; j = classesByType.Next())
                {
                    featureLayerClass = new FeatureLayerClass()
                    {
                        FeatureClass = j,
                        Name         = string.Concat(dsName, (j as IDataset).Name)
                    };
                    pMap.AddLayer(featureLayerClass);
                }
                return;
            }

            case esriDatasetType.esriDTTopology:
            {
                ITopologyLayer topologyLayerClass = new TopologyLayerClass()
                {
                    Topology = pDataset as ITopology
                };
                (topologyLayerClass as ILayer).Name = string.Concat(dsName, pDataset.Name);
                pMap.AddLayer(topologyLayerClass as ILayer);
                return;
            }

            case esriDatasetType.esriDTTable:
            {
                try
                {
                    IRasterCatalogTable rasterCatalogTableClass = new RasterCatalogTable()
                    {
                        Table = (ITable)pDataset
                    };
                    rasterCatalogTableClass.Update();
                    IRasterCatalogLayer rasterCatalogLayerClass = new RasterCatalogLayerClass();
                    rasterCatalogLayerClass.Create(rasterCatalogTableClass);
                    rasterCatalogLayerClass.Name = string.Concat(dsName, pDataset.BrowseName);
                    pMap.AddLayer(rasterCatalogLayerClass);
                    return;
                }
                catch
                {
                    try
                    {
                        IStandaloneTableCollection ibasicMap0 = pMap as IStandaloneTableCollection;
                        IPropertySet connectionProperties     = pDataset.Workspace.ConnectionProperties;
                        bool         flag = false;
                        int          num  = 0;
                        while (true)
                        {
                            if (num < ibasicMap0.StandaloneTableCount)
                            {
                                ITable table = ibasicMap0.StandaloneTable[num].Table;
                                if (
                                    !connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) ||
                                    !((table as IDataset).Name == pDataset.Name))
                                {
                                    num++;
                                }
                                else
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        if (!flag)
                        {
                            ibasicMap0.AddStandaloneTable(new StandaloneTableClass()
                                {
                                    Table = pDataset as ITable
                                });
                        }
                    }
                    catch (Exception exception1)
                    {
                        Logger.Current.Write(exception1.Message, LogLevel.Error, null);
                    }
                    return;
                }
                break;
            }

            case esriDatasetType.esriDTRasterDataset:
            case esriDatasetType.esriDTRasterBand:
            {
                IRasterLayer rasterLayerClass = new RasterLayerClass();
                rasterLayerClass.CreateFromDataset((IRasterDataset)pDataset);
                rasterLayerClass.Name = string.Concat(dsName, pDataset.Name);
                pMap.AddLayer(rasterLayerClass);
                return;
            }

            case esriDatasetType.esriDTTin:
            {
                ITinLayer tinLayerClass = new TinLayerClass()
                {
                    Dataset = (ITin)pDataset,
                    Name    = string.Concat(dsName, pDataset.Name)
                };
                pMap.AddLayer(tinLayerClass);
                return;
            }

            case esriDatasetType.esriDTCadDrawing:
            {
                ICadLayer cadLayerClass = new CadLayerClass()
                {
                    CadDrawingDataset = pDataset as ICadDrawingDataset,
                    Name = pDataset.Name
                };
                pMap.AddLayer(cadLayerClass);
                return;
            }

            default:
            {
                return;
            }
            }
        }
Exemplo n.º 3
0
        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)
        }
Exemplo n.º 4
0
        public void LoadData(IList ilist_0)
        {
            IEnumDataset      subsets;
            IDataset          j;
            string            str;
            IFeatureClass     dataset;
            IFeatureLayer     cadFeatureLayerClass;
            ITopologyLayer    topologyLayerClass;
            IEnumFeatureClass classes;
            IFeatureClass     m;
            IFeatureClass     n;
            IFeatureLayer     featureLayerClass;
            List <object>     objs = new List <object>();

            foreach (object ilist0 in ilist_0)
            {
                if (ilist0 is IGxDataset)
                {
                    if ((ilist0 as IGxDataset).Type != esriDatasetType.esriDTFeatureDataset)
                    {
                        objs.Add(ilist0);
                    }
                    else
                    {
                        IEnumGxObject children = (ilist0 as IGxObjectContainer).Children;
                        children.Reset();
                        for (IGxObject i = children.Next(); i != null; i = children.Next())
                        {
                            objs.Add(i);
                        }
                    }
                }
                else if (!(ilist0 is IDataset))
                {
                    objs.Add(ilist0);
                }
                else
                {
                    if ((ilist0 as IDataset).Type != esriDatasetType.esriDTFeatureDataset)
                    {
                        continue;
                    }
                    subsets = (ilist0 as IDataset).Subsets;
                    subsets.Reset();
                    for (j = subsets.Next(); j != null; j = subsets.Next())
                    {
                        objs.Add(j);
                    }
                }
            }
            ProcessAssist processAssist = new ProcessAssist();

            processAssist.InitProgress();
            processAssist.SetMaxValue(objs.Count);
            processAssist.SetMessage("正在加载数据,请稍候...");
            processAssist.Start();
            try
            {
                ILayer layer = null;
                IMap   map   = this.GetMap();
                this.list_0 = new List <ILayer>();
                List <string> strs      = new List <string>();
                IEnvelope     envelope  = null;
                IDataset      item      = null;
                IGxDataset    gxDataset = null;
                for (int k = 0; k < objs.Count; k++)
                {
                    string name = "";
                    if (objs[k] is IGxObject)
                    {
                        name = (objs[k] as IGxObject).Name;
                    }
                    else if (objs[k] is IDataset)
                    {
                        name = (objs[k] as IDataset).Name;
                    }
                    bool flag = true;
                    str = string.Format("加载图层[{0}],第{1}/{2}个", name, k + 1, objs.Count);
                    processAssist.Increment(1);
                    processAssist.SetMessage(str);
                    if (objs[k] is IGxLayer)
                    {
                        layer = (objs[k] as IGxLayer).Layer;
                        if (layer is IGeoDataset && !SpatialReferenctOperator.ValideFeatureClass(layer as IGeoDataset))
                        {
                            strs.Add(layer.Name);
                            flag = false;
                        }
                        this.AddLayer(map, layer, ref envelope, flag);
                    }
                    else if (!(objs[k] is IGxAGSObject))
                    {
                        if (objs[k] is IGxDataset)
                        {
                            gxDataset = objs[k] as IGxDataset;
                            item      = gxDataset.Dataset;
                        }
                        else if (ilist_0[k] is IDataset)
                        {
                            item = objs[k] as IDataset;
                        }
                        if (item != null)
                        {
                            if (item is IGeoDataset)
                            {
                                flag = SpatialReferenctOperator.ValideFeatureClass(item as IGeoDataset);
                            }
                            if (item.Type == esriDatasetType.esriDTFeatureClass)
                            {
                                dataset = (IFeatureClass)item;
                                if ((gxDataset as IGxObject).Category.IndexOf("CAD") != -1)
                                {
                                    if (dataset.FeatureType != esriFeatureType.esriFTCoverageAnnotation)
                                    {
                                        cadFeatureLayerClass = new CadFeatureLayerClass();
                                    }
                                    else
                                    {
                                        cadFeatureLayerClass = new CadAnnotationLayerClass();
                                    }
                                    cadFeatureLayerClass.FeatureClass = dataset;
                                    cadFeatureLayerClass.Name         = dataset.AliasName;
                                }
                                else if (dataset.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else if (dataset.FeatureType != esriFeatureType.esriFTDimension)
                                {
                                    cadFeatureLayerClass = new FeatureLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else
                                {
                                    cadFeatureLayerClass = new DimensionLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                if (!flag)
                                {
                                    strs.Add(cadFeatureLayerClass.Name);
                                }
                                this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTCadDrawing)
                            {
                                if ((gxDataset as IGxObject).Category != "CAD绘图")
                                {
                                    IEnumGxObject enumGxObject = (gxDataset as IGxObjectContainer).Children;
                                    enumGxObject.Reset();
                                    for (IGxDataset l = enumGxObject.Next() as IGxDataset; l != null; l = enumGxObject.Next() as IGxDataset)
                                    {
                                        dataset = l.Dataset as IFeatureClass;
                                        if (dataset != null)
                                        {
                                            if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                            {
                                                cadFeatureLayerClass = new CadFeatureLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            else
                                            {
                                                cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag1 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag1;
                                                if (!flag1)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                }
                                else
                                {
                                    ICadLayer cadLayerClass = new CadLayerClass()
                                    {
                                        CadDrawingDataset = gxDataset.Dataset as ICadDrawingDataset,
                                        Name = gxDataset.Dataset.Name
                                    };
                                    if (!flag)
                                    {
                                        strs.Add(cadLayerClass.Name);
                                    }
                                    this.AddLayer(map, cadLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTFeatureDataset)
                            {
                                subsets = item.Subsets;
                                subsets.Reset();
                                for (j = subsets.Next(); j != null; j = subsets.Next())
                                {
                                    if (j.Type == esriDatasetType.esriDTFeatureClass)
                                    {
                                        dataset = j as IFeatureClass;
                                        if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                        {
                                            cadFeatureLayerClass = new FeatureLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag2 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag2;
                                                if (!flag2)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                        else
                                        {
                                            cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag3 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag3;
                                                if (!flag3)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                    else if (j.Type == esriDatasetType.esriDTTopology)
                                    {
                                        topologyLayerClass = new TopologyLayerClass()
                                        {
                                            Topology = j as ITopology
                                        };
                                        (topologyLayerClass as ILayer).Name = j.Name;
                                        this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTopology)
                            {
                                if (MessageBox.Show(string.Concat("是否将参加拓扑-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        flag = true;
                                        if (cadFeatureLayerClass is IGeoDataset)
                                        {
                                            bool flag4 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                            flag = flag4;
                                            if (!flag4)
                                            {
                                                strs.Add(cadFeatureLayerClass.Name);
                                            }
                                        }
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                    }
                                }
                                topologyLayerClass = new TopologyLayerClass()
                                {
                                    Topology = item as ITopology
                                };
                                (topologyLayerClass as ILayer).Name = item.Name;
                                this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                            }
                            else if (item.Type == esriDatasetType.esriDTTin)
                            {
                                ITinLayer tinLayerClass = new TinLayerClass()
                                {
                                    Dataset = (ITin)item,
                                    Name    = item.Name
                                };
                                flag = true;
                                if (tinLayerClass is IGeoDataset)
                                {
                                    bool flag5 = SpatialReferenctOperator.ValideFeatureClass(tinLayerClass as IGeoDataset);
                                    flag = flag5;
                                    if (!flag5)
                                    {
                                        strs.Add(tinLayerClass.Name);
                                    }
                                }
                                this.AddLayer(map, tinLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTRasterCatalog)
                            {
                                IGdbRasterCatalogLayer gdbRasterCatalogLayerClass = null;
                                gdbRasterCatalogLayerClass = new GdbRasterCatalogLayerClass();
                                if (gdbRasterCatalogLayerClass.Setup((ITable)(item as IRasterCatalog)))
                                {
                                    bool flag6 = SpatialReferenctOperator.ValideFeatureClass(gdbRasterCatalogLayerClass as IGeoDataset);
                                    flag = flag6;
                                    if (!flag6)
                                    {
                                        strs.Add((gdbRasterCatalogLayerClass as ILayer).Name);
                                    }
                                    this.AddLayer(map, gdbRasterCatalogLayerClass as ILayer, ref envelope, flag);
                                }
                            }
                            else if (!(item.Type == esriDatasetType.esriDTRasterDataset ? false : item.Type != esriDatasetType.esriDTRasterBand))
                            {
                                bool flag7 = true;
                                if (!((IRasterPyramid)item).Present)
                                {
                                    if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt)
                                    {
                                        ((IRasterPyramid)item).Create();
                                    }
                                    else if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysPrompt)
                                    {
                                        DialogResult dialogResult = BuildPyramidSet.Show();
                                        if (dialogResult == DialogResult.Yes)
                                        {
                                            ((IRasterPyramid)item).Create();
                                        }
                                        else if (dialogResult == DialogResult.Cancel)
                                        {
                                            flag7 = false;
                                        }
                                    }
                                }
                                if (flag7)
                                {
                                    IRasterLayer rasterLayerClass = new RasterLayerClass()
                                    {
                                        Cached = true
                                    };
                                    rasterLayerClass.CreateFromDataset((IRasterDataset)item);
                                    rasterLayerClass.Name = item.Name;
                                    bool flag8 = SpatialReferenctOperator.ValideFeatureClass(rasterLayerClass as IGeoDataset);
                                    flag = flag8;
                                    if (!flag8)
                                    {
                                        strs.Add(rasterLayerClass.Name);
                                    }
                                    this.AddLayer(map, rasterLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTable)
                            {
                                try
                                {
                                    IStandaloneTableCollection standaloneTableCollection = this.GetMap() as IStandaloneTableCollection;
                                    IPropertySet connectionProperties = item.Workspace.ConnectionProperties;
                                    bool         flag9 = false;
                                    int          num   = 0;
                                    while (true)
                                    {
                                        if (num < standaloneTableCollection.StandaloneTableCount)
                                        {
                                            ITable table = standaloneTableCollection.StandaloneTable[num].Table;
                                            if (!connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) || !((table as IDataset).Name == item.Name))
                                            {
                                                num++;
                                            }
                                            else
                                            {
                                                flag9 = true;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (!flag9)
                                    {
                                        standaloneTableCollection.AddStandaloneTable(new StandaloneTableClass()
                                        {
                                            Table = item as ITable
                                        });
                                    }
                                }
                                catch (Exception exception)
                                {
                                    CErrorLog.writeErrorLog(this, exception, "");
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTGeometricNetwork)
                            {
                                IGeometricNetwork geometricNetwork = item as IGeometricNetwork;
                                if (geometricNetwork != null)
                                {
                                    IEnumFeatureClass classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTNetworkDataset)
                            {
                                INetworkLayer networkLayerClass = new NetworkLayerClass()
                                {
                                    NetworkDataset = item as INetworkDataset
                                };
                                this.AddLayer(map, networkLayerClass as ILayer, ref envelope, true);
                                if (MessageBox.Show(string.Concat("是否将参加网络要素集-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        IMapServerLayer mapServerLayerClass = new MapServerLayerClass();
                        mapServerLayerClass.ServerConnect((objs[k] as IGxAGSObject).AGSServerObjectName, (objs[k] as IGxAGSObject).DefaultMapName);
                        this.AddLayer(map, mapServerLayerClass as ILayer, ref envelope, false);
                    }
                }
                processAssist.End();
                bool layerCount = this.GetMap().LayerCount > 0;
                if (strs.Count > 0)
                {
                    MessageBox.Show("警告:数据范围不一致。\r\n 一个或多个添加的图层范围与关联的空间坐标系范围不一致。请检查数据问题。存在问题图层信息请查看错误日志!", "管理平台", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (string str1 in strs)
                    {
                        if (stringBuilder.Length > 0)
                        {
                            stringBuilder.Append(",");
                        }
                        stringBuilder.Append(str1);
                    }
                    CErrorLog.writeErrorLog(stringBuilder, null, "图层范围不一致!");
                }
                foreach (ILayer list0 in this.list_0)
                {
                    list0.Visible = true;
                }
                if (layerCount && envelope != null)
                {
                    IMap map1 = this.GetMap();
                    ISpatialReference spatialReference = map1.SpatialReference;
                    if ((spatialReference is IUnknownCoordinateSystem || envelope.SpatialReference is IUnknownCoordinateSystem || envelope.SpatialReference == null ? false : spatialReference != null))
                    {
                        envelope.Project(spatialReference);
                    }
                    (map1 as IActiveView).Extent = envelope;
                    (map1 as IActiveView).Refresh();
                }
                if (this.m_pApp != null)
                {
                    this.m_pApp.MapDocumentChanged();
                }
                else if (ApplicationRef.Application != null)
                {
                    ApplicationRef.Application.MapDocumentChanged();
                }
            }
            catch (Exception exception1)
            {
                str = exception1.ToString();
            }
            if (this.onLoadCompleteHand_0 != null)
            {
                this.onLoadCompleteHand_0();
            }
        }
Exemplo n.º 5
0
        public static ILayer CreateLayer(ICatalogItem catalogItem)
        {
            if (catalogItem == null || catalogItem.Dataset==null)
                return null;

            ILayer lyrNew = null;
            enumCatalogType catalogType = catalogItem.Type;
            switch(catalogType)
            {
                case enumCatalogType.Workpace:
                case enumCatalogType.FeatureDataset:
                case enumCatalogType.Table:
                    return null;

                case enumCatalogType.FeatureClassPoint:
                case enumCatalogType.FeatureClassLine:
                case enumCatalogType.FeatureClassArea:
                case enumCatalogType.FeatureClassAnnotation:
                case enumCatalogType.FeatureClassEmpty:
                case enumCatalogType.FeatureClass3D:
                case enumCatalogType.RasterCatalog:
                    IFeatureLayer lyrFeature= new FeatureLayerClass();
                    lyrFeature.FeatureClass = catalogItem.Dataset as IFeatureClass;
                    lyrNew = lyrFeature;
                    break;

                case enumCatalogType.RasterMosaic:
                case enumCatalogType.RasterSet:
                    IRasterLayer lyrRaster = new RasterLayerClass();
                    lyrRaster.CreateFromDataset(catalogItem.Dataset as IRasterDataset);
                    lyrNew = lyrRaster;
                    break;

                case enumCatalogType.RasterBand:
                    IRasterLayer lyrRasterBand = new RasterLayerClass();
                    IRasterBand rasterBand = catalogItem.Dataset as IRasterBand;
                    IRasterBandCollection colRasterBand = new RasterClass();
                    colRasterBand.Add(rasterBand, 0);
                    lyrRasterBand.CreateFromRaster(colRasterBand as IRaster);

                    lyrNew = lyrRasterBand;
                    break;

                case enumCatalogType.Tin:
                    ITinLayer lyrTin = new TinLayerClass();
                    lyrTin.Dataset = catalogItem.Dataset as ITin;
                    lyrNew = lyrTin;
                    break;

                case enumCatalogType.Terrain:
                    ITerrainLayer lyrTerrain = new TerrainLayerClass();
                    lyrTerrain.Terrain = catalogItem.Dataset as ITerrain;
                    lyrNew = lyrTerrain;
                    break;

                case enumCatalogType.Topology:
                    ITopologyLayer lyrTopology = new TopologyLayerClass();
                    lyrTopology.Topology = catalogItem.Dataset as ITopology;
                    lyrNew = lyrTopology as ILayer;
                    break;
            }

            return lyrNew;
        }
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool hasTopologyStuff, bool hasStationFunction, bool useRepresentation)
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc = (IMxDocument)ArcMap.Document;
            IMap thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();
            GeoMapGroupLayer.Name = "Geologic Map";

            if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase,"GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }

            if (hasStationFunction == true)
            {
                // Create a Group layer
                IGroupLayer stationGroupLayer = new GroupLayerClass();
                stationGroupLayer.Name = "Station Data";

                #region "StationPoints"
                // Open a FeatureClass, set it to a FeatureLayer
                IFeatureClass stationFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "StationPoints");
                IFeatureLayer stationFL = new FeatureLayerClass();
                stationFL.FeatureClass = stationFC;

                // Configure the FeatureLayer
                stationFL.Name = "Stations";
                stationFL.DisplayField = "FieldID";

                // Collapse the legend for this layer
                ILegendInfo stationLegendInfo = (ILegendInfo)stationFL;
                ILegendGroup stationLegendGroup = stationLegendInfo.get_LegendGroup(0);
                stationLegendGroup.Visible = false;

                // Finally, add the layer to the group layer
                stationGroupLayer.Add(stationFL);

                #endregion

                // Repeat for all these FeatureClasses
                #region "SamplePoints"
                IFeatureClass sampleFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "SamplePoints");
                IFeatureLayer sampleFL = new FeatureLayerClass();
                sampleFL.FeatureClass = sampleFC;

                sampleFL.Name = "Samples";
                sampleFL.DisplayField = "FieldID";

                ILegendInfo sampleLegendInfo = (ILegendInfo)sampleFL;
                ILegendGroup sampleLegendGroup = sampleLegendInfo.get_LegendGroup(0);
                sampleLegendGroup.Visible = false;

                stationGroupLayer.Add(sampleFL);

                #endregion

                #region "OrientationDataPoints"
                IFeatureClass structureFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationDataPoints");
                IFeatureLayer structureFL = new FeatureLayerClass();
                structureFL.FeatureClass = structureFC;

                structureFL.Name = "Orientation Data";
                structureFL.DisplayField = "Type";

                // Symbology, if representations are present
                if (useRepresentation == true)
                {
                    // FeatureLayer must be cast as a GeoFeatureLayer in order to access the Renderer
                    IGeoFeatureLayer structureGeoFL = (IGeoFeatureLayer)structureFL;

                    // Create a RepresentationClassRenderer, assign the appropriate RepresentationClass to it
                    IRepresentationRenderer structureRepRend = new RepresentationRendererClass();
                    structureRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_OrientationDataPoints");

                    // Assign the RepresentationClassRenderer to the GeoFeatureLayer
                    structureGeoFL.Renderer = (IFeatureRenderer)structureRepRend;

                    // Assign generic FeatureTemplates
                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, structureFL as ILayer, "OrientationDataPoints");
                }

                ILegendInfo structureLegendInfo = (ILegendInfo)structureFL;
                ILegendGroup structureLegendGroup = structureLegendInfo.get_LegendGroup(0);
                structureLegendGroup.Visible = false;

                stationGroupLayer.Add(structureFL);

                #endregion

                // Add the Group Layer to the main layer
                stationGroupLayer.Expanded = true;
                GeoMapGroupLayer.Add(stationGroupLayer);

                #region "Notes Table"
                ITable notesTable = commonFunctions.OpenTable(ValidNcgmpDatabase, "Notes");
                IStandaloneTable notesStandalone = new StandaloneTableClass();
                notesStandalone.Table = notesTable;

                notesStandalone.Name = "Notes";
                notesStandalone.DisplayField = "Type";

                thisMapTables.AddStandaloneTable(notesStandalone);

                #endregion

                #region "RelatedDocuments Table"
                ITable relatedDocsTable = commonFunctions.OpenTable(ValidNcgmpDatabase, "RelatedDocuments");
                IStandaloneTable relatedDocsStandalone = new StandaloneTableClass();
                relatedDocsStandalone.Table = relatedDocsTable;

                relatedDocsStandalone.Name = "Related Documents";
                relatedDocsStandalone.DisplayField = "Type";

                thisMapTables.AddStandaloneTable(relatedDocsStandalone);

                #endregion
            }

            if (hasTopologyStuff == true)
            {
                #region "OtherLines"
                IFeatureClass otherLinesFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OtherLines");
                IFeatureLayer otherLinesFL = new FeatureLayerClass();
                otherLinesFL.FeatureClass = otherLinesFC;

                otherLinesFL.Name = "Other Lines";
                otherLinesFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    IGeoFeatureLayer otherLinesGeoFL = (IGeoFeatureLayer)otherLinesFL;

                    IRepresentationRenderer otherLinesRepRend = new RepresentationRendererClass();
                    otherLinesRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_OtherLines");

                    otherLinesGeoFL.Renderer = (IFeatureRenderer)otherLinesRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, otherLinesFL as ILayer, "OtherLines");
                }

                ILegendInfo otherLinesLegendInfo = (ILegendInfo)otherLinesFL;
                ILegendGroup otherLinesLegendGroup = otherLinesLegendInfo.get_LegendGroup(0);
                otherLinesLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(otherLinesFL);

                #endregion

            }

            #region "ContactsAndFaults"
            IFeatureClass contactsAndFaultsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "ContactsAndFaults");
            IFeatureLayer contactsAndFaultsFL = new FeatureLayerClass();
            contactsAndFaultsFL.FeatureClass = contactsAndFaultsFC;

            contactsAndFaultsFL.Name = "Contacts and Faults";
            contactsAndFaultsFL.DisplayField = "Type";

            if (useRepresentation == true)
            {
                // Set the layer renderer to use representations
                IGeoFeatureLayer contactsAndFaultsGeoFL = (IGeoFeatureLayer)contactsAndFaultsFL;

                IRepresentationRenderer contactsAndFaultsRepRend = new RepresentationRendererClass();
                contactsAndFaultsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "r_ContactsAndFaults");

                contactsAndFaultsGeoFL.Renderer = (IFeatureRenderer)contactsAndFaultsRepRend;

                commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, contactsAndFaultsFL as ILayer, "ContactsAndFaults");
            }

            ILegendInfo contactsAndFaultsLegendInfo = (ILegendInfo)contactsAndFaultsFL;
            ILegendGroup contactsAndFaultsLegendGroup = contactsAndFaultsLegendInfo.get_LegendGroup(0);
            contactsAndFaultsLegendGroup.Visible = false;

            GeoMapGroupLayer.Add(contactsAndFaultsFL);

            #endregion

            if (hasTopologyStuff == true)
            {
                #region "OverlayPolys"
                IFeatureClass overlayPolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OverlayPolys");
                IFeatureLayer overlayPolysFL = new FeatureLayerClass();
                overlayPolysFL.FeatureClass = overlayPolysFC;

                overlayPolysFL.Name = "Overlay Polygons";
                overlayPolysFL.DisplayField = "MapUnit";

                ILegendInfo overlayPolysLegendInfo = (ILegendInfo)overlayPolysFL;
                ILegendGroup overlayPolysLegendGroup = overlayPolysLegendInfo.get_LegendGroup(0);
                overlayPolysLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(overlayPolysFL);

                #endregion
            }

            #region "MapUnitPolys"
            IFeatureClass mapUnitPolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "MapUnitPolys");
            IFeatureLayer mapUnitPolysFL = new FeatureLayerClass();
            mapUnitPolysFL.FeatureClass = mapUnitPolysFC;

            mapUnitPolysFL.Name = "Distribution of Map Units";
            mapUnitPolysFL.DisplayField = "MapUnit";

            ILegendInfo mapUnitPolysLegendInfo = (ILegendInfo)mapUnitPolysFL;
            ILegendGroup mapUnitPolysLegendGroup = mapUnitPolysLegendInfo.get_LegendGroup(0);
            mapUnitPolysLegendGroup.Visible = false;

            GeoMapGroupLayer.Add(mapUnitPolysFL);
            #endregion

            if (hasTopologyStuff == true)
            {
                #region "DataSourcePolys"
                IFeatureClass dataSourcePolysFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "DataSourcePolys");
                IFeatureLayer dataSourcePolysFL = new FeatureLayerClass();
                dataSourcePolysFL.FeatureClass = dataSourcePolysFC;

                dataSourcePolysFL.Name = "Data Source Polys";
                dataSourcePolysFL.DisplayField = "DataSourceID";

                ILegendInfo dataSourcePolysLegendInfo = (ILegendInfo)dataSourcePolysFL;
                ILegendGroup dataSourcePolysLegendGroup = dataSourcePolysLegendInfo.get_LegendGroup(0);
                dataSourcePolysLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(dataSourcePolysFL);

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }
Exemplo n.º 7
0
        // bool hasTopologyStuff, bool hasStationFunction,
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation)
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc = (IMxDocument)ArcMap.Document;
            IMap thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();
            GeoMapGroupLayer.Name = "Geologic Map";

            // Create a group layer
            IGroupLayer StationGroupLayer = new GroupLayerClass();
            StationGroupLayer.Name = "Observation Data";

            //if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology geoMapTopo = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo geoMapTopoLegendInfo = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }
            {
                #region "OrientationPoints"
                IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints");
                IFeatureLayer orientationPointsFL = new FeatureLayerClass();
                orientationPointsFL.FeatureClass = orientationPointsFC;

                orientationPointsFL.Name = "Orientation Points";
                orientationPointsFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    // Set the layer renderer to use representations
                    IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL;

                    IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass();
                    orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep");

                    orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints");
                }

                ILegendInfo orientationPointsLegendInfo = (ILegendInfo)orientationPointsFL;
                ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0);
                orientationPointsLegendGroup.Visible = false;

                StationGroupLayer.Add(orientationPointsFL);

                #endregion

                #region "ObservationData"
                string[] arr = new string[4]; // Initialize
                arr[0] = "Stations";               // Element 1
                arr[1] = "GenericPoints";               // Element 2
                arr[2] = "GenericSamples";             // Element 3
                arr[3] = "GeochronPoints";              // Element 4

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;
                        FL.Visible = false;

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        StationGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion

            }

            //add station group layer to map document
            GeoMapGroupLayer.Add(StationGroupLayer);

            {
                #region "LinesWithoutRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "CartographicLines";               // Element 1
                arr[1] = "IsoValueLines";               // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;
                        FL.Visible = false;

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "LinesWithRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "GeologicLines";               // Element 1
                arr[1] = "ContactsAndFaults";               // Element 2

                foreach (string s in arr)
                {
                    try {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        if (useRepresentation == true)
                        {
                            // Set the layer renderer to use representations
                            IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL;

                            IRepresentationRenderer RepRend = new RepresentationRendererClass();
                            RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep");

                            GeoFL.Renderer = (IFeatureRenderer)RepRend;

                            commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s);
                        }

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Polygons"
                string[] arr = new string[3]; // Initialize
                arr[0] = "DataSourcePolys";               // Element 1
                arr[1] = "MapUnitPolys";               // Element 2
                arr[2] = "OtherPolys";               // Element 3

                foreach (string s in arr)
                {
                    try {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        ILegendInfo LegendInfo = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Tables"
                string[] arr = new string[7]; // Initialize
                arr[0] = "DataSources";               // Element 1
                arr[1] = "DescriptionOfMapUnits";               // Element 2
                arr[2] = "ExtendedAttributes";             // Element 3
                arr[3] = "GeologicEvents";              // Element 4
                arr[4] = "Glossary";              // Element 5
                arr[5] = "Notes";              // Element 6
                arr[6] = "StandardLithology";              // Element 7
                foreach (string s in arr)
                {
                    try {
                        ITable Table = commonFunctions.OpenTable(ValidNcgmpDatabase, s);
                        IStandaloneTable Standalone = new StandaloneTableClass();
                        Standalone.Table = Table;

                        Standalone.Name = s;

                        thisMapTables.AddStandaloneTable(Standalone);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }
        private void AddLayersToMap(IWorkspace ValidNcgmpDatabase, bool useRepresentation) // bool hasTopologyStuff, bool hasStationFunction,
        {
            // Get references to the map for adding layers and tables
            IMxDocument MxDoc   = (IMxDocument)ArcMap.Document;
            IMap        thisMap = MxDoc.FocusMap;
            IStandaloneTableCollection thisMapTables = (IStandaloneTableCollection)thisMap;

            // Create a group layer
            IGroupLayer GeoMapGroupLayer = new GroupLayerClass();

            GeoMapGroupLayer.Name = "Geologic Map";

            // Create a group layer
            IGroupLayer StationGroupLayer = new GroupLayerClass();

            StationGroupLayer.Name = "Observation Data";

            //if (hasTopologyStuff == true)
            {
                #region "GeologicMapTopology"
                ITopology      geoMapTopo   = commonFunctions.OpenTopology(ValidNcgmpDatabase, "GeologicMapTopology");
                ITopologyLayer geoMapTopoTL = new TopologyLayerClass();
                geoMapTopoTL.Topology = geoMapTopo;

                ILayer geoMapTopoL = (ILayer)geoMapTopoTL;
                geoMapTopoL.Name    = "Geologic Map Topology";
                geoMapTopoL.Visible = false;

                // Minimizing the legend info in the Table of Contents is not trivial
                ILegendInfo  geoMapTopoLegendInfo  = (ILegendInfo)geoMapTopoL;
                ILegendGroup geoMapTopoLegendGroup = geoMapTopoLegendInfo.get_LegendGroup(0);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup         = geoMapTopoLegendInfo.get_LegendGroup(1);
                geoMapTopoLegendGroup.Visible = false;
                geoMapTopoLegendGroup         = geoMapTopoLegendInfo.get_LegendGroup(2);
                geoMapTopoLegendGroup.Visible = false;

                GeoMapGroupLayer.Add(geoMapTopoL);

                #endregion
            }
            {
                #region "OrientationPoints"
                IFeatureClass orientationPointsFC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, "OrientationPoints");
                IFeatureLayer orientationPointsFL = new FeatureLayerClass();
                orientationPointsFL.FeatureClass = orientationPointsFC;

                orientationPointsFL.Name         = "Orientation Points";
                orientationPointsFL.DisplayField = "Type";

                if (useRepresentation == true)
                {
                    // Set the layer renderer to use representations
                    IGeoFeatureLayer orientationPointsGeoFL = (IGeoFeatureLayer)orientationPointsFL;

                    IRepresentationRenderer orientationPointsRepRend = new RepresentationRendererClass();
                    orientationPointsRepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, "OrientationPoints_Rep");

                    orientationPointsGeoFL.Renderer = (IFeatureRenderer)orientationPointsRepRend;

                    commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, orientationPointsFL as ILayer, "OrientationPoints");
                }

                ILegendInfo  orientationPointsLegendInfo  = (ILegendInfo)orientationPointsFL;
                ILegendGroup orientationPointsLegendGroup = orientationPointsLegendInfo.get_LegendGroup(0);
                orientationPointsLegendGroup.Visible = false;

                StationGroupLayer.Add(orientationPointsFL);

                #endregion

                #region "ObservationData"
                string[] arr = new string[4]; // Initialize
                arr[0] = "Stations";          // Element 1
                arr[1] = "GenericPoints";     // Element 2
                arr[2] = "GenericSamples";    // Element 3
                arr[3] = "GeochronPoints";    // Element 4

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name    = s;
                        FL.Visible = false;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        StationGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            //add station group layer to map document
            GeoMapGroupLayer.Add(StationGroupLayer);

            {
                #region "LinesWithoutRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "CartographicLines"; // Element 1
                arr[1] = "IsoValueLines";     // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name    = s;
                        FL.Visible = false;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "LinesWithRepresentations"
                string[] arr = new string[2]; // Initialize
                arr[0] = "GeologicLines";     // Element 1
                arr[1] = "ContactsAndFaults"; // Element 2

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        if (useRepresentation == true)
                        {
                            // Set the layer renderer to use representations
                            IGeoFeatureLayer GeoFL = (IGeoFeatureLayer)FL;

                            IRepresentationRenderer RepRend = new RepresentationRendererClass();
                            RepRend.RepresentationClass = commonFunctions.GetRepClass(ValidNcgmpDatabase, s + "_Rep");

                            GeoFL.Renderer = (IFeatureRenderer)RepRend;

                            commonFunctions.BuildGenericTemplates(ValidNcgmpDatabase, FL as ILayer, s);
                        }

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Polygons"
                string[] arr = new string[3]; // Initialize
                arr[0] = "DataSourcePolys";   // Element 1
                arr[1] = "MapUnitPolys";      // Element 2
                arr[2] = "OtherPolys";        // Element 3

                foreach (string s in arr)
                {
                    try
                    {
                        IFeatureClass FC = commonFunctions.OpenFeatureClass(ValidNcgmpDatabase, s);
                        IFeatureLayer FL = new FeatureLayerClass();
                        FL.FeatureClass = FC;

                        FL.Name = s;

                        ILegendInfo  LegendInfo  = (ILegendInfo)FL;
                        ILegendGroup LegendGroup = LegendInfo.get_LegendGroup(0);
                        LegendGroup.Visible = false;

                        GeoMapGroupLayer.Add(FL);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }
            {
                #region "Tables"
                string[] arr = new string[7];     // Initialize
                arr[0] = "DataSources";           // Element 1
                arr[1] = "DescriptionOfMapUnits"; // Element 2
                arr[2] = "ExtendedAttributes";    // Element 3
                arr[3] = "GeologicEvents";        // Element 4
                arr[4] = "Glossary";              // Element 5
                arr[5] = "Notes";                 // Element 6
                arr[6] = "StandardLithology";     // Element 7
                foreach (string s in arr)
                {
                    try
                    {
                        ITable           Table      = commonFunctions.OpenTable(ValidNcgmpDatabase, s);
                        IStandaloneTable Standalone = new StandaloneTableClass();
                        Standalone.Table = Table;

                        Standalone.Name = s;

                        thisMapTables.AddStandaloneTable(Standalone);
                    }
                    catch (Exception ex)
                    {
                        // Write exception to C:\Users\<user name>\AppData\Local\Temp\NCGMPToolbarLog.txt
                        string path    = Path.Combine(Environment.GetEnvironmentVariables()["LOCALAPPDATA"] as string, "Temp/NCGMPToolbarLog.txt");
                        string message = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + s + ": " + ex.Message + "\r\n";
                        System.IO.File.AppendAllText(path, message);
                    }
                }

                #endregion
            }

            // Add the Geologic Map Group Layer to the map
            GeoMapGroupLayer.Expanded = true;
            thisMap.AddLayer(GeoMapGroupLayer);

            // Adjust the MapUnitPolys Renderer
            commonFunctions.UpdateMapUnitPolysRenderer(ValidNcgmpDatabase);

            // Adjust the MapUnitPolys Feature Templates
            commonFunctions.UpdateMapUnitPolysFeatureTemplates(ValidNcgmpDatabase);
        }
Exemplo n.º 9
0
        //加载拓扑图层
        public static void AddTopoLayer(ref AxMapControl pMapCtrl, string strTopoLayerName, ITopologyWorkspace ipTopologyWS,IFeatureClassContainer ipFeatClassContainer, IFeatureDataset ipFeatDataset)
        {
            int nOriginClassID, nDestClassID;

            ITopology ipTopology;

            //打开数据集
            //ITopologyContainer ipTopoContainer = (ITopologyContainer)ipFeatDataset;

            IWorkspace2 pWorkspace = (IWorkspace2)ipFeatDataset.Workspace;

            if (pWorkspace.get_NameExists(esriDatasetType.esriDTTopology, strTopoLayerName))
            {
                ipTopology = ipTopologyWS.OpenTopology(strTopoLayerName);

                if (ipTopology == null)
                {
                    return;
                }

                ITopologyLayer ipTopologyLayer = new TopologyLayerClass();
                ipTopologyLayer.Topology = ipTopology;

                ILegendInfo legendInfo = (ILegendInfo)ipTopologyLayer;

                for (int i = 0; i < legendInfo.LegendGroupCount; i++)
                {
                    ILegendGroup legendgroup = legendInfo.get_LegendGroup(i);

                    ILegendClass legendclass = legendgroup.get_Class(0);

                    switch (legendgroup.Heading)
                    {
                        case "Area Errors":
                            {
                                legendgroup.Heading = "";
                                legendclass.Label = "面状错误";
                                legendclass.Description = "面状错误";
                                break;
                            }
                        case "Line Errors":
                            {
                                legendgroup.Heading = "";
                                legendclass.Label = "线状错误";
                                legendclass.Description = "线状错误";
                                break;
                            }
                        case "Point Errors":
                            {
                                legendgroup.Heading = "";
                                legendclass.Label = "点状错误";
                                legendclass.Description = "点状错误";
                                break;
                            }
                    }

                }

                ILayer ipLayer = (ILayer)ipTopologyLayer;
                ipLayer.Name = strTopoLayerName; //将拓扑检查合并后,将拓扑图层名指定为“拓扑错误”后,采用此方法命名  hehy20080724

                /*  将拓扑检查合并后,将拓扑图层名指定为“拓扑错误”后,注销以下代码 hehy20080724
                ///////////////////////////////////////////////////
                //得到拓扑层相对应的规则名称
                CModelSchema pModelSchema = new CModelSchema();
                string strRuleName = pModelSchema.GetRuleNameByTopoLayerName(m_pTask.pSchema, strTopoLayerName);
                //////////////////////////////////////////////////
                if (strRuleName.Length == 0)
                {
                    ipLayer.Name = strTopoLayerName;
                }
                else
                {
                    ipLayer.Name = strRuleName;
                }
                */
                //把拓扑图层加载到map控件中
                //pMapCtrl.AddLayer(ipLayer, pMapCtrl.LayerCount);
                pMapCtrl.Map.AddLayer(ipLayer);
                //pMapCtrl.ActiveView.Extent = ipLayer.AreaOfInterest;
            }
        }
Exemplo n.º 10
0
        public static ILayer CreateLayer(ICatalogItem catalogItem)
        {
            if (catalogItem == null || catalogItem.Dataset == null)
            {
                return(null);
            }

            ILayer          lyrNew      = null;
            enumCatalogType catalogType = catalogItem.Type;

            switch (catalogType)
            {
            case enumCatalogType.Workpace:
            case enumCatalogType.FeatureDataset:
            case enumCatalogType.Table:
                return(null);

            case enumCatalogType.FeatureClassPoint:
            case enumCatalogType.FeatureClassLine:
            case enumCatalogType.FeatureClassArea:
            case enumCatalogType.FeatureClassAnnotation:
            case enumCatalogType.FeatureClassEmpty:
            case enumCatalogType.FeatureClass3D:
            case enumCatalogType.RasterCatalog:
                IFeatureLayer lyrFeature = new FeatureLayerClass();
                lyrFeature.FeatureClass = catalogItem.Dataset as IFeatureClass;
                lyrNew = lyrFeature;
                break;

            case enumCatalogType.RasterMosaic:
            case enumCatalogType.RasterSet:
                IRasterLayer lyrRaster = new RasterLayerClass();
                lyrRaster.CreateFromDataset(catalogItem.Dataset as IRasterDataset);
                lyrNew = lyrRaster;
                break;

            case enumCatalogType.RasterBand:
                IRasterLayer          lyrRasterBand = new RasterLayerClass();
                IRasterBand           rasterBand    = catalogItem.Dataset as IRasterBand;
                IRasterBandCollection colRasterBand = new RasterClass();
                colRasterBand.Add(rasterBand, 0);
                lyrRasterBand.CreateFromRaster(colRasterBand as IRaster);

                lyrNew = lyrRasterBand;
                break;

            case enumCatalogType.Tin:
                ITinLayer lyrTin = new TinLayerClass();
                lyrTin.Dataset = catalogItem.Dataset as ITin;
                lyrNew         = lyrTin;
                break;

            case enumCatalogType.Terrain:
                ITerrainLayer lyrTerrain = new TerrainLayerClass();
                lyrTerrain.Terrain = catalogItem.Dataset as ITerrain;
                lyrNew             = lyrTerrain;
                break;

            case enumCatalogType.Topology:
                ITopologyLayer lyrTopology = new TopologyLayerClass();
                lyrTopology.Topology = catalogItem.Dataset as ITopology;
                lyrNew = lyrTopology as ILayer;
                break;
            }

            return(lyrNew);
        }
Exemplo n.º 11
0
        //加载拓扑图层
        public static void AddTopoLayer(ref AxMapControl pMapCtrl, string strTopoLayerName, ITopologyWorkspace ipTopologyWS, IFeatureClassContainer ipFeatClassContainer, IFeatureDataset ipFeatDataset)
        {
            int nOriginClassID, nDestClassID;

            ITopology ipTopology;

            //打开数据集
            //ITopologyContainer ipTopoContainer = (ITopologyContainer)ipFeatDataset;

            IWorkspace2 pWorkspace = (IWorkspace2)ipFeatDataset.Workspace;

            if (pWorkspace.get_NameExists(esriDatasetType.esriDTTopology, strTopoLayerName))
            {
                ipTopology = ipTopologyWS.OpenTopology(strTopoLayerName);

                if (ipTopology == null)
                {
                    return;
                }

                ITopologyLayer ipTopologyLayer = new TopologyLayerClass();
                ipTopologyLayer.Topology = ipTopology;



                ILegendInfo legendInfo = (ILegendInfo)ipTopologyLayer;

                for (int i = 0; i < legendInfo.LegendGroupCount; i++)
                {
                    ILegendGroup legendgroup = legendInfo.get_LegendGroup(i);

                    ILegendClass legendclass = legendgroup.get_Class(0);

                    switch (legendgroup.Heading)
                    {
                    case "Area Errors":
                    {
                        legendgroup.Heading     = "";
                        legendclass.Label       = "面状错误";
                        legendclass.Description = "面状错误";
                        break;
                    }

                    case "Line Errors":
                    {
                        legendgroup.Heading     = "";
                        legendclass.Label       = "线状错误";
                        legendclass.Description = "线状错误";
                        break;
                    }

                    case "Point Errors":
                    {
                        legendgroup.Heading     = "";
                        legendclass.Label       = "点状错误";
                        legendclass.Description = "点状错误";
                        break;
                    }
                    }
                }


                ILayer ipLayer = (ILayer)ipTopologyLayer;
                ipLayer.Name = strTopoLayerName; //将拓扑检查合并后,将拓扑图层名指定为“拓扑错误”后,采用此方法命名  hehy20080724

                /*  将拓扑检查合并后,将拓扑图层名指定为“拓扑错误”后,注销以下代码 hehy20080724
                 * ///////////////////////////////////////////////////
                 * //得到拓扑层相对应的规则名称
                 * CModelSchema pModelSchema = new CModelSchema();
                 * string strRuleName = pModelSchema.GetRuleNameByTopoLayerName(m_pTask.pSchema, strTopoLayerName);
                 * //////////////////////////////////////////////////
                 * if (strRuleName.Length == 0)
                 * {
                 *  ipLayer.Name = strTopoLayerName;
                 * }
                 * else
                 * {
                 *  ipLayer.Name = strRuleName;
                 * }
                 */
                //把拓扑图层加载到map控件中
                //pMapCtrl.AddLayer(ipLayer, pMapCtrl.LayerCount);
                pMapCtrl.Map.AddLayer(ipLayer);
                //pMapCtrl.ActiveView.Extent = ipLayer.AreaOfInterest;
            }
        }