Beispiel #1
0
        //添加cad文件
        public void addcadfile(string filePath, string filename, AxMapControl mapControl)
        {
            if (filename + filePath == "")
            {
                return;
            }
            IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactoryClass();                                 //打开CAD数据集
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0); //打开一个要素集
            IFeatureLayer     pFeatureLayer;
            IFeatureDataset   pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(filename);
            //IFeaturClassContainer可以管理IFeatureDataset中的每个要素类
            IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset;

            //对CAD文件中的要素进行遍历处理
            for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)
            {
                IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
                if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                {
                    //如果是注记,则添加注记层
                    pFeatureLayer = new CadAnnotationLayerClass();
                }
                else
                {
                    //如果是点、线、面,则添加要素层
                    pFeatureLayer              = new FeatureLayerClass();
                    pFeatureLayer.Name         = pFeatClass.AliasName;
                    pFeatureLayer.FeatureClass = pFeatClass;
                    mapControl.Map.AddLayer(pFeatureLayer);
                    mapControl.ActiveView.Refresh();
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 直接添加所有层--通过IFeatureClassContainer
        /// </summary>
        /// <param name="mapControlDefault">地图控件</param>
        /// <param name="pFeatureWorkspace">要素工作空间</param>
        /// <param name="strFileName">文件名,包括后缀</param>
        public static void GetALLCADbyWorkspace(IMapControlDefault mapControlDefault, IWorkspace pCADWorkspace, string strFileName)
        {
            IFeatureWorkspace      pFeatureWorkspace      = pCADWorkspace as IFeatureWorkspace;
            IFeatureDataset        pFeatureDataset        = pFeatureWorkspace.OpenFeatureDataset(strFileName);
            IFeatureClassContainer pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;

            for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
            {
                IFeatureClass pFeatureClass = pFeatureClassContainer.get_Class(i);
                IFeatureLayer pFeatureLayer = null;
                if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    pFeatureLayer = new CadAnnotationLayerClass();
                }
                else
                {
                    pFeatureLayer = new CadFeatureLayerClass();
                }
                if (pFeatureLayer != null)
                {
                    pFeatureLayer.Name         = pFeatureClass.AliasName;
                    pFeatureLayer.FeatureClass = pFeatureClass;
                    mapControlDefault.AddLayer(pFeatureLayer as ILayer, 0);
                }
            }
        }
Beispiel #3
0
        public static StandardItem Import(IFeatureDataset fds)
        {
            if (fds == null)
            {
                return(null);
            }

            StandardItem sItem = new StandardItem();

            sItem.Type             = enumItemType.FeatureDataset;
            sItem.Name             = fds.Name;
            sItem.SpatialReference = (fds as IGeoDataset).SpatialReference;
            sItem.ID = Guid.NewGuid().ToString("N");

            IList <StandardItem> subList = new List <StandardItem>();

            sItem.SubItems = subList;
            IFeatureClassContainer fcContianer = fds as IFeatureClassContainer;

            for (int i = 0; i < fcContianer.ClassCount; i++)
            {
                StandardItem sItemClass = Import(fcContianer.get_Class(i));
                sItemClass.Parent = sItem;

                subList.Add(sItemClass);
            }

            return(sItem);
        }
Beispiel #4
0
        //topology code
        public ITopology create_topology(IWorkspace myWSp, string[] FCIndex, string TopologyName)
        {
            IEnumDataset myEDS = myWSp.get_Datasets(esriDatasetType.esriDTFeatureDataset);
            IDataset     myDS  = myEDS.Next();

            if (myDS != null)
            {
                DS_Name = myDS.Name;
                IFeatureDataset myFDS = myDS as IFeatureDataset;

                //IWorkspace myWSp = DS as IWorkspace;

                IFeatureClassContainer myFCContainer = myFDS as IFeatureClassContainer;
                //要素类容器
                ITopologyContainer myTopologyContainer = myFDS as ITopologyContainer;
                ITopology          myTopology          = myTopologyContainer.CreateTopology(TopologyName, myTopologyContainer.DefaultClusterTolerance, -1, "");
                int count = 0;
                while (count < FCIndex.Length)
                {
                    myTopology.AddClass(myFCContainer.get_Class(int.Parse(FCIndex[count])), 5, 1, 1, false);
                    count++;
                }
                return(myTopology);
            }
            else
            {
                MessageBox.Show("Error,your Dataset is not a standar DataSet which can be uesed to created topology!");
                return(null);
            }
        }
Beispiel #5
0
        public DataTable GetFeaturesStatDt()
        {
            DataTable              result            = GenerateDataTable();
            IFeatureDataset        pDataset          = null;
            IFeatureClassContainer pFeatClsContainer = null;
            IFeatureClass          pFeatureCls       = null;

            try
            {
                //List<StandardLayer> layers = LayerReader.GetLayersByStandard(m_StandardID);
                //获取标准的图层列表
                if (m_Workspace == null)
                {
                    return(result);
                }
                IEnumDataset enumDataset = m_Workspace.get_Datasets(esriDatasetType.esriDTFeatureDataset);
                enumDataset.Reset();
                IFeatureDataset subDataset = enumDataset.Next() as IFeatureDataset;

                while (subDataset != null)
                {
                    pFeatClsContainer = subDataset as IFeatureClassContainer;
                    int     iCount = 0;
                    DataRow dr     = null;
                    for (int i = 0; i < pFeatClsContainer.ClassCount; i++)
                    {
                        pFeatureCls = pFeatClsContainer.get_Class(i);
                        string featClsName = (pFeatureCls as IDataset).Name;

                        iCount = pFeatureCls.FeatureCount(null);
                        dr     = result.NewRow();
                        dr[0]  = featClsName;
                        dr[1]  = pFeatureCls.AliasName;
                        dr[2]  = iCount;
                        result.Rows.Add(dr);
                        Marshal.ReleaseComObject(pFeatureCls);
                    }
                    subDataset = enumDataset.Next() as IFeatureDataset;
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("获取要素个数失败!原因:" + ex.Message, "警告");
                return(result);
            }
            finally
            {
                if (pFeatureCls != null)
                {
                    Marshal.ReleaseComObject(pFeatureCls);
                }
                if (pDataset != null)
                {
                    Marshal.ReleaseComObject(pDataset);
                }
            }
            return(result);
        }
 private void btnCollectCAD_Click(object sender, EventArgs e)
 {
     if (this.textboxCAD.Text == "")
     {
         return;
     }
     try
     {
         //获取文件名和文件路径
         int    pIndex    = this.textboxCAD.Text.LastIndexOf("\\");
         string pFilePath = this.textboxCAD.Text.Substring(0, pIndex);
         string pFileName = this.textboxCAD.Text.Substring(pIndex + 1);
         //打开CAD数据集
         IWorkspaceFactory pWorkspaceFactory;
         IFeatureWorkspace pFeatureWorkspace;
         IFeatureLayer     pFeatureLayer;
         IFeatureDataset   pFeatureDataset;
         pWorkspaceFactory = new CadWorkspaceFactoryClass(); //using ESRI.ArcGIS.DataSourcesFile;
         pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);
         //打开一个要素集
         pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(pFileName);
         //IFeatureClassContainer可以管理IFeatureDataset中的每个要素类
         IFeatureClassContainer pFeatClassContainer = (IFeatureClassContainer)pFeatureDataset;
         IGroupLayer            pGroupLayer         = new GroupLayerClass();
         pGroupLayer.Name = pFileName;
         //对CAD文件中的要素进行遍历处理
         for (int i = 0; i < pFeatClassContainer.ClassCount; i++)
         {
             IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
             //如果是注记,则添加注记层
             if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
             {
                 pFeatureLayer              = new CadAnnotationLayerClass();
                 pFeatureLayer.Name         = pFeatClass.AliasName;
                 pFeatureLayer.FeatureClass = pFeatClass;
                 pGroupLayer.Add(pFeatureLayer);
                 //this.pMapControl.Map.AddLayer(pFeatureLayer);
             }
             else //如果是点、线、面则添加要素层
             {
                 pFeatureLayer              = new FeatureLayerClass();
                 pFeatureLayer.Name         = pFeatClass.AliasName;
                 pFeatureLayer.FeatureClass = pFeatClass;
                 pGroupLayer.Add(pFeatureLayer);
                 //this.pMapControl.Map.AddLayer(pFeatureLayer);
             }
         }
         this.pMapControl.Map.AddLayer(pGroupLayer);
         this.pMapControl.ActiveView.Refresh();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #7
0
        private void ExportDatasetToXML(string datasetFeatureClassName)
        {
            IFeatureDataset        featureDataset        = featureWorkspace.OpenFeatureDataset(datasetFeatureClassName);
            IFeatureClassContainer featureClassContainer = featureDataset as IFeatureClassContainer;

            for (int i = 0; i < featureClassContainer.ClassCount; i++)
            {
                IFeatureClass featureClass = featureClassContainer.get_Class(i);
                ExportFeatureClassToReportData(featureClass);
            }
        }
Beispiel #8
0
        private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset)
        {
            bool flag = false;

            try
            {
                IFeatureLayer layer;
                int           num;
                this.m_ipGeometricNetwork = ((INetworkCollection)FeatureDataset).get_GeometricNetwork(0);
                INetwork network = this.m_ipGeometricNetwork.Network;
                if (this.m_ipMap == null)
                {
                    this.m_ipMap = new MapClass();
                    IFeatureClassContainer ipGeometricNetwork = (IFeatureClassContainer)this.m_ipGeometricNetwork;
                    for (num = 0; num < ipGeometricNetwork.ClassCount; num++)
                    {
                        IFeatureClass class2 = ipGeometricNetwork.get_Class(num);
                        layer = new FeatureLayerClass
                        {
                            FeatureClass = class2
                        };
                        this.m_ipMap.AddLayer(layer);
                    }
                }
                IEnvelope envelope = new EnvelopeClass();
                for (num = 0; num < this.m_ipMap.LayerCount; num++)
                {
                    layer = (IFeatureLayer)this.m_ipMap.get_Layer(num);
                    IGeoDataset dataset = (IGeoDataset)layer;
                    IEnvelope   extent  = dataset.Extent;
                    envelope.Union(extent);
                }
                this.m_ipPointToEID                  = new PointToEIDClass();
                this.m_ipPointToEID.SourceMap        = this.m_ipMap;
                this.m_ipPointToEID.GeometricNetwork = this.m_ipGeometricNetwork;
                double width  = envelope.Width;
                double height = envelope.Height;
                if (width > height)
                {
                    this.m_ipPointToEID.SnapTolerance = width / 100.0;
                }
                else
                {
                    this.m_ipPointToEID.SnapTolerance = height / 100.0;
                }
                flag = true;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString());
            }
            return(flag);
        }
Beispiel #9
0
        private void 查找ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!DBHelper.ifLogin)
            {
                MessageBox.Show("请登录");
                return;
            }

            ArrayList test = DBHelper.queryAll("NAME LIKE '%52%'");

            for (int i = 0; i < test.Count; i++)
            {
                MessageBox.Show(((NameAndType)test[i]).name + "");
            }
            object data = DBHelper.openByTypeAndName(((NameAndType)test[0]).name, ((NameAndType)test[0]).type);

            //显示矢量图的方法
            if (((NameAndType)test[0]).type.StartsWith("f"))
            {
                IFeatureDataset        queryData        = (IFeatureDataset)data;
                IFeatureClassContainer datasetContainer = (IFeatureClassContainer)queryData;
                IFeatureLayer          m_FeatureLayer;
                for (int i = 0; i < datasetContainer.ClassCount; i++)
                {
                    IFeatureClass pFeatureClass = datasetContainer.get_Class(i);
                    if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        m_FeatureLayer = new CadAnnotationLayerClass();
                        MessageBox.Show("");
                    }
                    else
                    {
                        m_FeatureLayer              = new FeatureLayerClass();
                        m_FeatureLayer.Name         = pFeatureClass.AliasName;
                        m_FeatureLayer.FeatureClass = pFeatureClass;

                        m_mapControl.Map.AddLayer(m_FeatureLayer);
                    }
                }
            }

            //显示栅格图的方法
            if (((NameAndType)test[0]).type.StartsWith("r"))
            {
                IRasterDataset queryData    = (IRasterDataset)data;
                IRasterLayer   pRasterLayer = new RasterLayerClass();
                pRasterLayer.CreateFromDataset(queryData);
                m_mapControl.Map.AddLayer(pRasterLayer as ILayer);
            }
        }
        /// <summary>
        /// CAD文件作为矢量图层加载
        /// 整幅图加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddWhileCADToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filePath;
            string fileName;
            string filter = "CAD(*.dwg)|*.dwg";
            string title  = "打开CAD数据文件";

            outFilePathAndFileName(title, filter, out filePath, out fileName);
            if (fileName == null || filePath == null)
            {
                return;
            }
            // 打开一个CAD数据集
            IWorkspaceFactory pWorkspaceFactory = new CadWorkspaceFactory();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(filePath, 0) as IFeatureWorkspace;
            // 打开一个要素集
            IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(fileName);
            // IFeatureClassContainer 可以管理IFeatureDataset中的每个要素类
            IFeatureClassContainer pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;

            // 新增删除数据
            ClearAllData();

            // 对CAD文件中的要素进行遍历处理
            for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
            {
                IFeatureClass pFeatClass = pFeatureClassContainer.get_Class(i);

                // 如果是注记,则添加注记层
                if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                {
                    IFeatureLayer pFeatureLayer = new CadAnnotationLayerClass();
                    pFeatureLayer.Name         = pFeatClass.AliasName;
                    pFeatureLayer.FeatureClass = pFeatClass;
                    MainMapControl.AddLayer(pFeatureLayer);
                }
                // 如果是点线面则添加要素层
                else
                {
                    IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                    pFeatureLayer.Name         = pFeatClass.AliasName;
                    pFeatureLayer.FeatureClass = pFeatClass;
                    MainMapControl.AddLayer(pFeatureLayer);
                }
                MainMapControl.Refresh();
            }

            // 同步鹰眼
            SynchronizeEagleEye();
        }
Beispiel #11
0
    //在数据集中查找要素类
    //-----------------------------------------------------------------------------------------------------
    private static IFeatureClass GetFcFromDataset(IFeatureDataset featDs, string className)
    {
        IFeatureClass          featClass;
        IFeatureClassContainer fcContainer = featDs as IFeatureClassContainer;

        for (int i = 0; i < fcContainer.ClassCount; i++)
        {
            featClass = fcContainer.get_Class(i);
            if (featClass.AliasName == className)
            {
                return(featClass);
            }
        }
        return(null);
    }
Beispiel #12
0
        /// <summary>
        /// 整体添加CAD数据
        /// </summary>
        /// <param name="mapControl">要添加的地图控件</param>
        public void AddWholeCAD(AxMapControl mapControl)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "CAD(*.dwg)|*.dwg";
            openFileDialog.Title  = "打开CAD数据文件";
            openFileDialog.ShowDialog();

            string fullPath = openFileDialog.FileName;

            if (fullPath == "")
            {
                return;
            }
            //获取文件名和文件路径
            int    SubIndex = fullPath.LastIndexOf("\\");
            string fileDir  = fullPath.Substring(0, SubIndex);
            string fileName = fullPath.Substring(SubIndex + 1);

            IWorkspaceFactory      workspaceFactory      = new CadWorkspaceFactory();
            IFeatureWorkspace      workspace             = (IFeatureWorkspace)workspaceFactory.OpenFromFile(fileDir, 0);
            IFeatureDataset        FeatureDataset        = workspace.OpenFeatureDataset(fileName);
            IFeatureClassContainer featureClassContainer = FeatureDataset as IFeatureClassContainer;
            IFeatureClass          featureClass;
            IFeatureLayer          featureLayer;

            for (int i = 0; i < featureClassContainer.ClassCount; i++)
            {
                featureClass = featureClassContainer.get_Class(i);
                if (featureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                {
                    featureLayer = new CadAnnotationLayerClass();
                    featureLayer.FeatureClass = featureClass;
                    featureLayer.Name         = featureClass.AliasName;
                    mapControl.AddLayer(featureLayer);
                }
                else
                {
                    featureLayer = new FeatureLayerClass();
                    featureLayer.FeatureClass = featureClass;
                    featureLayer.Name         = featureClass.AliasName;
                    mapControl.AddLayer(featureLayer);
                }
                mapControl.ActiveView.Refresh();
            }
        }
Beispiel #13
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count > 0)
            {
                NameAndType select = new NameAndType();
                int         lvi    = listView1.SelectedItems[0].Index;
                select = (NameAndType)data[lvi];
                object dBdata = DBHelper.openByTypeAndName((select).name, (select).type);
                m_mapControl.Map.ClearLayers();
                //显示矢量图的方法
                if ((select).type.StartsWith("f"))
                {
                    IFeatureDataset        queryData        = (IFeatureDataset)dBdata;
                    IFeatureClassContainer datasetContainer = (IFeatureClassContainer)queryData;
                    IFeatureLayer          m_FeatureLayer;
                    for (int i = 0; i < datasetContainer.ClassCount; i++)
                    {
                        IFeatureClass pFeatureClass = datasetContainer.get_Class(i);
                        if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                        {
                            m_FeatureLayer = new CadAnnotationLayerClass();
                            MessageBox.Show("");
                        }
                        else
                        {
                            m_FeatureLayer              = new FeatureLayerClass();
                            m_FeatureLayer.Name         = pFeatureClass.AliasName;
                            m_FeatureLayer.FeatureClass = pFeatureClass;

                            m_mapControl.Map.AddLayer(m_FeatureLayer);
                        }
                    }
                }

                //显示栅格图的方法
                if ((select).type.StartsWith("r"))
                {
                    IRasterDataset queryData    = (IRasterDataset)dBdata;
                    IRasterLayer   pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(queryData);
                    m_mapControl.Map.AddLayer(pRasterLayer as ILayer);
                }
            }
            //MessageBox.Show(listView1.SelectedItems[0].Text);
        }
Beispiel #14
0
        //新建一个要素类
        private void CreateFeatureclass(IQueryDef pQueryDef, IFeatureWorkspace pFeatureWorkspace)
        {
            IFeatureDataset        pFeatureDataset        = pFeatureWorkspace.OpenFeatureQuery("My counties join ", pQueryDef);
            IFeatureClassContainer pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;

            //判断IFeatureClassContainer中是否有要素类存在
            if (pFeatureClassContainer.ClassCount != 1)
            {
                MessageBox.Show("Failed to create feature class by query!");
                return;
            }
            IFeatureClass pFeatureClass = pFeatureClassContainer.get_Class(0);
            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.FeatureClass = pFeatureClass;
            pFeatureLayer.Name         = pFeatureClass.AliasName;
            pMap.AddLayer(pFeatureLayer);
        }
Beispiel #15
0
        /// <summary>
        /// 检查数据集是否有锁,一旦检测到数据集内有图层含有锁,就返回有锁信息
        /// </summary>
        /// <param name="ipFeatDataset">被检查的数据集</param>
        /// <returns>是否有锁</returns>
        public static bool CheckFeatureDatasetHasLock(IFeatureDataset ipFeatDataset)
        {
            IFeatureClassContainer ipFeatClassContainer = (IFeatureClassContainer)ipFeatDataset;
            int numFeatClasses = ipFeatClassContainer.ClassCount;

            IFeatureClass ipFeatClass = null;
            bool          hasLock     = false;

            for (int i = 0; i < numFeatClasses; i++)
            {
                ipFeatClass = ipFeatClassContainer.get_Class(i);
                if (CheckFeatureClassHasLock(ipFeatClass))
                {
                    hasLock = true;
                    break;
                }
            }
            return(hasLock);
        }
Beispiel #16
0
        /// <summary>
        /// 获取CAD的FeatureClassNode
        /// </summary>
        /// <param name="parentNode"></param>
        private void getDwgFCNode(DevComponents.AdvTree.Node parentNode)
        {
            //获取当前的CAD文件
            FileInfo file = (FileInfo)parentNode.Tag;
            IFeatureClassContainer pFeatureClassContainer = null;

            //获取CAD文件的FeatureClassContainer
            pFeatureClassContainer = GetFeatureClassContainer(file);
            for (int i = 0; i < pFeatureClassContainer.ClassCount - 1; i++)
            {
                IFeatureClass pFeatureClass;
                //获取FeatureClassContainer中的FeatureClass
                pFeatureClass = pFeatureClassContainer.get_Class(i);
                DevComponents.AdvTree.Node node = new DevComponents.AdvTree.Node();
                node.Tag  = pFeatureClass;
                node.Name = pFeatureClass.AliasName;
                node.Text = pFeatureClass.AliasName;
                parentNode.Nodes.Add(node);
                //根据FeatureClass的不同类型,设置不同的图标
                switch (pFeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    node.ImageIndex = 9;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    node.ImageIndex = 10;
                    break;

                case esriGeometryType.esriGeometryPoint:
                    node.ImageIndex = 11;
                    break;

                case esriGeometryType.esriGeometryMultiPatch:
                    node.ImageIndex = 14;
                    break;

                default:
                    break;
                }
            }
        }
 private void method2ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     System.Windows.Forms.OpenFileDialog openFileDialog =
         new System.Windows.Forms.OpenFileDialog();
     openFileDialog.Filter           = "CAD (*.dwg)|*.dwg";
     openFileDialog.FilterIndex      = 2;
     openFileDialog.RestoreDirectory = true;
     openFileDialog.Multiselect      = false;
     if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         string filename = openFileDialog.FileName;
         if (filename != "")
         {
             //axMapControl1.ClearLayers();
             IWorkspaceFactory pCadWorkspaceFactory = new CadWorkspaceFactory();
             IFeatureWorkspace pWorkspace           = pCadWorkspaceFactory.OpenFromFile(
                 System.IO.Path.GetDirectoryName(filename), 0) as IFeatureWorkspace;
             IFeatureDataset pFeatureDataset = pWorkspace.OpenFeatureDataset(
                 System.IO.Path.GetFileName(filename));
             IFeatureClassContainer pFeatureClassContainer =
                 pFeatureDataset as IFeatureClassContainer;
             IFeatureClass pFeatureClass;
             IFeatureLayer pFeatureLayer;
             for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
             {
                 pFeatureClass = pFeatureClassContainer.get_Class(i);
                 if (pFeatureClass.FeatureType ==
                     esriFeatureType.esriFTCoverageAnnotation)
                 {
                     pFeatureLayer = new CadAnnotationLayerClass();
                 }
                 else
                 {
                     pFeatureLayer = new FeatureLayerClass();
                 }
                 pFeatureLayer.Name         = pFeatureClass.AliasName;
                 pFeatureLayer.FeatureClass = pFeatureClass;
                 axMapControl1.AddLayer(pFeatureLayer, 0);
             }
         }
     }
 }
Beispiel #18
0
        /// <summary>
        /// 获取CAD的FeatureClassItem
        /// </summary>
        /// <param name="parentNode"></param>
        private void getDwgFCItem(DevComponents.AdvTree.Node parentNode)
        {
            //获取当前的CAD文件
            FileInfo file = (FileInfo)parentNode.Tag;
            IFeatureClassContainer pFeatureClassContainer = null;

            //获取CAD文件的FeatureClassContainer
            pFeatureClassContainer = GetFeatureClassContainer(file);
            for (int i = 0; i < pFeatureClassContainer.ClassCount - 1; i++)
            {
                IFeatureClass pFeatureClass;
                //获取FeatureClassContainer中的FeatureClass
                pFeatureClass = pFeatureClassContainer.get_Class(i);
                ListViewItem item = new ListViewItem();
                item.Tag  = pFeatureClass;
                item.Name = pFeatureClass.AliasName;
                item.Text = pFeatureClass.AliasName;
                lvwData.Items.Add(item);
                //根据FeatureClass的不同类型,设置不同的图标
                switch (pFeatureClass.ShapeType)
                {
                case esriGeometryType.esriGeometryPolygon:
                    item.ImageIndex = 7;
                    break;

                case esriGeometryType.esriGeometryPolyline:
                    item.ImageIndex = 8;
                    break;

                case esriGeometryType.esriGeometryPoint:
                    item.ImageIndex = 9;
                    break;

                case esriGeometryType.esriGeometryMultiPatch:
                    item.ImageIndex = 12;
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #19
0
        /// <summary>
        /// DWG转换SHP
        /// </summary>
        /// <param name="DWGPath">CAD文件路径</param>
        /// <returns>返回转化好的*.shp文件路径</returns>
        public void  ConvertToShp(string DWGPath)
        {
            if (string.IsNullOrEmpty(DWGPath))
            {
                return;
            }
            if (File.Exists(DWGPath))
            {
                //try
                //{
                //string temshp = "";
                IWorkspaceFactory pWorkspaceFactory;
                IFeatureWorkspace pFeatureWorkspace;
                //IFeatureLayer pFeatureLayer;
                IFeatureDataset pFeatureDataset;
                //打开CAD数据集

                pWorkspaceFactory = new CadWorkspaceFactoryClass();
                pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(DWGPath), 0);
                //打开一个要素集
                pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(DWGPath));
                //IFeaturClassContainer可以管理IFeatureDataset中的每个要素类
                IFeatureClassContainer pFeatureClassContainer = (IFeatureClassContainer)pFeatureDataset;
                //当前过滤只保留面
                for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
                {
                    IFeatureClass pFeatureClass = pFeatureClassContainer.get_Class(i);
                    if (pFeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon)
                    {
                        ExportFeatureClassToConTempShp(pFeatureClass);
                        break;
                    }
                }
                //return temshp;
                //}
                //catch (Exception)
                //{
                //    return "";
                //}
            }
            /*****20130227杨漾(添加文件有效性判断,去掉trycatch,上层trycatch(MainForm)处理,无返回值)*****/
        }
Beispiel #20
0
        /// <summary>
        /// 加载CAD数据
        /// </summary>
        /// <param name="fileData"></param>
        private void AddCADData(object fileData, IMap pMap)
        {
            //获取CAD文件
            FileInfo file        = (FileInfo)fileData;
            string   dwgPath     = file.FullName;//得到CAD文件的全路径
            int      indexdwg    = dwgPath.LastIndexOf("\\");
            string   filedwgPath = dwgPath.Substring(0, indexdwg);
            string   filedwgName = dwgPath.Substring(indexdwg + 1);
            //获取CAD文件的Workspace
            IWorkspace        dwgWorkspace      = GetWorkspace(filedwgPath, "dwg");
            IFeatureWorkspace pFeatureWorkspace = dwgWorkspace as IFeatureWorkspace;
            IFeatureDataset   pFeatureDataset;
            IFeatureLayer     pFeatureLayer = null;

            //得到CAD文件的FeatureDataset
            pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(filedwgName);

            IFeatureClassContainer pFeatureClassContainer = null;

            pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;
            //遍历并打开CAD文件
            for (int i = 0; i < pFeatureClassContainer.ClassCount - 1; i++)
            {
                IFeatureClass pFeatureClass;
                //得到FeatureClass
                pFeatureClass = pFeatureClassContainer.get_Class(i);
                if (pFeatureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                {
                    pFeatureLayer = new CadAnnotationLayerClass();
                }
                else
                {
                    pFeatureLayer = new FeatureLayerClass();
                }
                pFeatureLayer.FeatureClass = pFeatureClass;
                pFeatureLayer.Name         = pFeatureClass.AliasName;
                m_pFeaturelayer            = pFeatureLayer;
                pMap.AddLayer(pFeatureLayer);
                m_pActiveView.Refresh();
            }
        }
Beispiel #21
0
        public override void OnClick()
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Title  = "打开CAD文件";
            openFileDialog1.Filter = "CAD图形文件(*.dwg)|*.DWG";
            if (openFileDialog1.ShowDialog() == DialogResult.OK && m_hookHelper.Hook is IMapControlDefault)
            {
                FileInfo               fileinfo            = new FileInfo(openFileDialog1.FileName);
                string                 path                = fileinfo.DirectoryName;
                string                 name                = fileinfo.Name;
                IWorkspaceFactory      cadWorkSpaceFactory = new CadWorkspaceFactoryClass();
                IFeatureWorkspace      workspace           = cadWorkSpaceFactory.OpenFromFile(path, 0) as IFeatureWorkspace;
                IFeatureDataset        featDataset         = workspace.OpenFeatureDataset(name);
                IFeatureClassContainer featClassContainer  = featDataset as IFeatureClassContainer;
                IFeatureClass          featClass;
                IFeatureLayer          featLayer;

                for (int i = 0; i < featClassContainer.ClassCount; i++)
                {
                    featClass = featClassContainer.get_Class(i);
                    if (featClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                    {
                        //标注类型,必须设置为单位的标注图层
                        featLayer = new CadAnnotationLayerClass();
                    }
                    else
                    {
                        //点线面类型
                        featLayer = new FeatureLayerClass();
                    }

                    featLayer.Name         = featClass.AliasName;
                    featLayer.FeatureClass = featClass;
                    ((IMapControlDefault)m_hookHelper.Hook).Map.AddLayer((ILayer)featLayer);
                }
            }
        }
        public List <ILayer> ReadCADLayer(List <string> filePathList)
        {
            List <ILayer> layerList = new List <ILayer>();

            if (filePathList.Count == 0)
            {
                return(null);
            }
            else
            {
                foreach (string path in filePathList)
                {
                    IWorkspaceFactory      pWorkspaceFactory   = new CadWorkspaceFactoryClass();
                    IFeatureWorkspace      pFeatureWorkspace   = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(path), 0) as IFeatureWorkspace;
                    IFeatureDataset        pFeatureDataset     = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(path));
                    IFeatureClassContainer pFeatClassContainer = pFeatureDataset as IFeatureClassContainer;

                    for (int i = 0; i < pFeatClassContainer.ClassCount - 1; i++)
                    {
                        IFeatureLayer pFeatureLayer;
                        IFeatureClass pFeatClass = pFeatClassContainer.get_Class(i);
                        if (pFeatClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                        {
                            pFeatureLayer = new CadAnnotationLayerClass();
                        }
                        else
                        {
                            pFeatureLayer = new FeatureLayerClass();
                        }

                        pFeatureLayer.Name         = pFeatClass.AliasName;
                        pFeatureLayer.FeatureClass = pFeatClass;
                        layerList.Add(pFeatureLayer as ILayer);
                    }
                }
                return(layerList);
            }
        }
Beispiel #23
0
        /// <summary>
        /// 以原工作空间为模板创建新的工作空间
        /// </summary>
        private void CreatWorkspaceFromOrig()
        {
            WaitForm.SetCaption("正在创建新的工作空间...请稍后");
            IFeatureClassContainer pFcContainer = null;
            IFeatureClass          pFcTemp      = null;
            IFeatureClass          pNewFc       = null;
            ISpatialReference      pSr          = null;
            ISpatialReference      pSrTemp      = null;
            IFields pflds = null;
            double  dblXmin, dblXmax, dblYmin, dblYmax;
            double  dblZmin, dblZmax, dblMmin, dblMmax;

            CreateWorkspaceDomains(m_pOrigWorkspace, m_pDestWorkspace);
            IFeatureWorkspace pFeaWorkspace = m_pDestWorkspace as IFeatureWorkspace;
            IEnumDataset      enumDs        = m_pOrigWorkspace.get_Datasets(esriDatasetType.esriDTAny);
            IDataset          pDs           = enumDs.Next();

            while (pDs != null)
            {
                if (pDs.Type == esriDatasetType.esriDTFeatureDataset)
                {
                    pSr     = new UnknownCoordinateSystemClass();
                    pSrTemp = (pDs as IGeoDataset).SpatialReference;
                    if (pSrTemp.HasXYPrecision())
                    {
                        pSrTemp.GetDomain(out dblXmin, out dblXmax, out dblYmin, out dblYmax);
                        pSr.SetDomain(dblXmin, dblXmax, dblYmin, dblYmax);
                    }
                    if (pSrTemp.HasZPrecision())
                    {
                        pSrTemp.GetZDomain(out dblZmin, out dblZmax);
                        pSr.SetZDomain(dblZmin, dblZmax);
                    }
                    if (pSrTemp.HasMPrecision())
                    {
                        pSrTemp.GetMDomain(out dblMmin, out dblMmax);
                        pSr.SetMDomain(dblMmin, dblMmax);
                    }
                    IFeatureDataset pFeaDs = pFeaWorkspace.CreateFeatureDataset(pDs.Name, pSr);
                    pFcContainer = (IFeatureClassContainer)pDs;
                    if (pFcContainer.ClassCount > 0)
                    {
                        for (int i = 0; i < pFcContainer.ClassCount; i++)
                        {
                            try
                            {
                                pFcTemp = pFcContainer.get_Class(i);
                                pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp);

                                //若为注记
                                if (pFcTemp.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    IFeatureWorkspaceAnno pFWSAno    = pFeaWorkspace as IFeatureWorkspaceAnno;
                                    IAnnoClass            pAnnoClass = pFcTemp.Extension as IAnnoClass;
                                    IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                                    pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                    pGLS.Units          = pAnnoClass.ReferenceScaleUnits;


                                    pNewFc = pFWSAno.CreateAnnotationClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.ShapeFieldName,
                                                                           "", pFeaDs, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                                    (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                }
                                else//若为地理要素
                                {
                                    try
                                    {
                                        pNewFc = pFeaDs.CreateFeatureClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.FeatureType, pFcTemp.ShapeFieldName, null);
                                        if (pFcTemp.AliasName == "图廓线")
                                        {
                                            int n = 0;
                                        }
                                        (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                    }
                                    catch (System.Exception ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                System.Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTFeatureClass)
                {
                    pFcTemp = (IFeatureClass)pDs;
                    pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp, pSr);
                    try
                    {
                        pNewFc = pFeaWorkspace.CreateFeatureClass(pDs.Name,
                                                                  pflds,
                                                                  pFcTemp.CLSID,
                                                                  pFcTemp.EXTCLSID,
                                                                  pFcTemp.FeatureType,
                                                                  pFcTemp.ShapeFieldName,
                                                                  null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTTable)
                {
                    ITable pTable = (ITable)pDs;
                    try
                    {
                        ITable pNewTable = pFeaWorkspace.CreateTable(pDs.Name,
                                                                     pTable.Fields,
                                                                     pTable.CLSID,
                                                                     pTable.EXTCLSID,
                                                                     null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                pDs = enumDs.Next();
            }
        }
Beispiel #24
0
 public bool GetLayerFormDataset(IDataset pDataset, Collection pLayersColl)
 {
     try
     {
         if (pDataset == null)
         {
             return(false);
         }
         if (pLayersColl == null)
         {
             return(false);
         }
         if (pDataset.Type == esriDatasetType.esriDTFeatureDataset)
         {
             IFeatureLayer          item      = null;
             IFeatureClassContainer container = pDataset as IFeatureClassContainer;
             if (container.ClassCount > 0)
             {
                 int           classIndex = 0;
                 IFeatureClass class2     = null;
                 for (classIndex = 0; classIndex <= (container.ClassCount - 1); classIndex++)
                 {
                     class2 = container.get_Class(classIndex);
                     if (class2.FeatureType == esriFeatureType.esriFTAnnotation)
                     {
                         item = new FDOGraphicsLayerClass() as IFeatureLayer;
                     }
                     else if (class2.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
                     {
                         item = new CoverageAnnotationLayerClass() as IFeatureLayer;
                     }
                     else if (class2.FeatureType == esriFeatureType.esriFTDimension)
                     {
                         item = new DimensionLayerClass() as IFeatureLayer;
                     }
                     else
                     {
                         item = new FeatureLayerClass();
                     }
                     item.FeatureClass = class2;
                     item.Name         = pDataset.Name + " " + class2.AliasName;
                     pLayersColl.Add(item, item.Name, null, null);
                 }
             }
         }
         else if (pDataset.Type == esriDatasetType.esriDTFeatureClass)
         {
             IFeatureLayer layer2 = null;
             IFeatureClass class3 = pDataset as IFeatureClass;
             if (class3.FeatureType == esriFeatureType.esriFTAnnotation)
             {
                 layer2 = new FDOGraphicsLayerClass() as IFeatureLayer;
             }
             else if (class3.FeatureType == esriFeatureType.esriFTCoverageAnnotation)
             {
                 layer2 = new CoverageAnnotationLayerClass() as IFeatureLayer;
             }
             else if (class3.FeatureType == esriFeatureType.esriFTDimension)
             {
                 layer2 = new DimensionLayerClass() as IFeatureLayer;
             }
             else
             {
                 layer2 = new FeatureLayerClass();
             }
             layer2.FeatureClass = class3;
             layer2.Name         = class3.AliasName;
             pLayersColl.Add(layer2, layer2.Name, null, null);
         }
         else if (pDataset.Type == esriDatasetType.esriDTPlanarGraph)
         {
             Interaction.MsgBox("暂时不支持 Planar Graph 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTGeometricNetwork)
         {
             Interaction.MsgBox("暂时不支持 Geometric Network 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTTopology)
         {
             Interaction.MsgBox("暂时不支持 Topology 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTText)
         {
             Interaction.MsgBox("暂时不支持 Text Dataset 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTTable)
         {
             Interaction.MsgBox("暂时不支持 Table Dataset 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTRelationshipClass)
         {
             Interaction.MsgBox("暂时不支持 Relationship Class 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTRasterDataset)
         {
             IRasterDataset rasterDataset = pDataset as IRasterDataset;
             IRasterLayer   layer3        = new RasterLayerClass();
             layer3.CreateFromDataset(rasterDataset);
             layer3.Name = pDataset.Name;
             pLayersColl.Add(layer3, layer3.Name, null, null);
         }
         else if (pDataset.Type == esriDatasetType.esriDTRasterBand)
         {
             Interaction.MsgBox("暂时不支持 Raster Band 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTTin)
         {
             ITinLayer layer4 = new TinLayerClass {
                 Dataset = pDataset as ITin,
                 Name    = pDataset.Name
             };
             pLayersColl.Add(layer4, layer4.Name, null, null);
         }
         else if (pDataset.Type == esriDatasetType.esriDTCadDrawing)
         {
             Interaction.MsgBox("暂时不支持 Cad Drawing 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else if (pDataset.Type == esriDatasetType.esriDTRasterCatalog)
         {
             Interaction.MsgBox("暂时不支持 Raster Catalog 格式的数据。", MsgBoxStyle.Information, "数据格式不支持");
         }
         else
         {
             Interaction.MsgBox("无法识别的数据格式。", MsgBoxStyle.Information, "数据格式错误");
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.LayerFun", "GetLayerFormDataset", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Beispiel #25
0
        private void method_3(object object_0)
        {
            frmOpenFile file = new frmOpenFile
            {
                Text             = "添加数据",
                AllowMultiSelect = true
            };

            file.AddFilter(new MyGxFilterDatasets(), true);
            if (file.DoModalOpen() == DialogResult.OK)
            {
                IFeatureClass featureClass;
                IFeatureLayer layer;
                System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;
                IArray array = new ArrayClass();
                IArray items = file.Items;
                int    index = 0;
                while (true)
                {
                    if (index >= items.Count)
                    {
                        break;
                    }
                    IGxDataset dataset = items.get_Element(index) as IGxDataset;
                    if (dataset != null)
                    {
                        IDataset dataset2 = dataset.Dataset;
                        if (dataset2 != null)
                        {
                            if (dataset2.Type == esriDatasetType.esriDTFeatureClass)
                            {
                                featureClass = (IFeatureClass)dataset2;
                                if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    layer = new FDOGraphicsLayerClass
                                    {
                                        FeatureClass = featureClass,
                                        Name         = featureClass.AliasName
                                    };
                                }
                                else
                                {
                                    layer = new FeatureLayerClass
                                    {
                                        FeatureClass = featureClass,
                                        Name         = featureClass.AliasName
                                    };
                                }
                                array.Add(layer);
                            }
                            else
                            {
                                IFDOGraphicsLayerFactory factory;
                                if (dataset2.Type == esriDatasetType.esriDTCadDrawing)
                                {
                                    IEnumGxObject children = (dataset as IGxObjectContainer).Children;
                                    children.Reset();
                                    for (IGxDataset dataset3 = children.Next() as IGxDataset;
                                         dataset3 != null;
                                         dataset3 = children.Next() as IGxDataset)
                                    {
                                        featureClass = dataset3.Dataset as IFeatureClass;
                                        if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                        {
                                            factory = new FDOGraphicsLayerFactoryClass();
                                            layer   =
                                                (IFeatureLayer)
                                                factory.OpenGraphicsLayer(
                                                    (IFeatureWorkspace)featureClass.FeatureDataset.Workspace,
                                                    featureClass.FeatureDataset, featureClass.AliasName);
                                        }
                                        else
                                        {
                                            layer = new FeatureLayerClass
                                            {
                                                FeatureClass = featureClass,
                                                Name         = featureClass.AliasName
                                            };
                                        }
                                        array.Add(layer);
                                    }
                                }
                                else if (dataset2.Type == esriDatasetType.esriDTFeatureDataset)
                                {
                                    IFeatureClassContainer container = (IFeatureClassContainer)dataset2;
                                    index = 0;
                                    while (index < (container.ClassCount - 1))
                                    {
                                        featureClass = container.get_Class(index);
                                        if (featureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                                        {
                                            factory = new FDOGraphicsLayerFactoryClass();
                                            layer   =
                                                (IFeatureLayer)
                                                factory.OpenGraphicsLayer(
                                                    (IFeatureWorkspace)featureClass.FeatureDataset.Workspace,
                                                    featureClass.FeatureDataset, featureClass.AliasName);
                                        }
                                        else
                                        {
                                            layer = new FeatureLayerClass
                                            {
                                                FeatureClass = featureClass,
                                                Name         = featureClass.AliasName
                                            };
                                        }
                                        array.Add(layer);
                                        index++;
                                    }
                                }
                                else if (dataset2.Type == esriDatasetType.esriDTTin)
                                {
                                    ITinLayer unk = new TinLayerClass
                                    {
                                        Dataset = (ITin)dataset2,
                                        Name    = dataset2.Name
                                    };
                                    array.Add(unk);
                                }
                                else if ((dataset2.Type == esriDatasetType.esriDTRasterDataset) ||
                                         (dataset2.Type == esriDatasetType.esriDTRasterBand))
                                {
                                    bool flag = true;
                                    if (!((IRasterPyramid)dataset2).Present)
                                    {
                                        if (ApplicationRef.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt)
                                        {
                                            ((IRasterPyramid)dataset2).Create();
                                        }
                                        else if (ApplicationRef.PyramidPromptType == PyramidPromptType.AlwaysPrompt)
                                        {
                                            switch (BuildPyramidSet.Show())
                                            {
                                            case DialogResult.Yes:
                                                ((IRasterPyramid)dataset2).Create();
                                                break;

                                            case DialogResult.Cancel:
                                                flag = false;
                                                break;
                                            }
                                        }
                                    }
                                    if (flag)
                                    {
                                        RasterLayerClass class3 = new RasterLayerClass
                                        {
                                            Cached = true
                                        };
                                        IRasterLayer layer3 = class3;
                                        layer3.CreateFromDataset((IRasterDataset)dataset2);
                                        layer3.Name = dataset2.Name;
                                        array.Add(layer3);
                                    }
                                }
                                else if (dataset2.Type == esriDatasetType.esriDTTable)
                                {
                                    try
                                    {
                                        IRasterCatalogTable pCatalog = new RasterCatalogTableClass
                                        {
                                            Table = (ITable)dataset2
                                        };
                                        pCatalog.Update();
                                        IRasterCatalogLayer layer4 = new RasterCatalogLayerClass();
                                        layer4.Create(pCatalog);
                                        layer4.Name = dataset2.BrowseName;
                                        array.Add(layer4);
                                    }
                                    catch
                                    {
                                    }
                                }
                            }
                        }
                    }
                    index++;
                }
                int    count  = array.Count;
                ILayer layer5 = null;
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (layer5 is IRasterCatalogLayer)
                    {
                        if (object_0 is IMap)
                        {
                            (object_0 as IMap).AddLayer(layer5);
                        }
                        else if (object_0 is IGroupLayer)
                        {
                            (object_0 as IGroupLayer).Add(layer5);
                        }
                        array.Remove(index);
                        count--;
                    }
                }
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (layer5 is IRasterLayer)
                    {
                        if (object_0 is IMap)
                        {
                            (object_0 as IMap).AddLayer(layer5);
                        }
                        else if (object_0 is IGroupLayer)
                        {
                            (object_0 as IGroupLayer).Add(layer5);
                        }
                        array.Remove(index);
                        count--;
                    }
                }
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (layer5 is ITinLayer)
                    {
                        if (object_0 is IMap)
                        {
                            (object_0 as IMap).AddLayer(layer5);
                        }
                        else if (object_0 is IGroupLayer)
                        {
                            (object_0 as IGroupLayer).Add(layer5);
                        }
                        array.Remove(index);
                        count--;
                    }
                }
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (layer5 is IFeatureLayer)
                    {
                        layer        = layer5 as IFeatureLayer;
                        featureClass = layer.FeatureClass;
                        if ((featureClass.ShapeType == esriGeometryType.esriGeometryPolygon) ||
                            (featureClass.ShapeType == esriGeometryType.esriGeometryEnvelope))
                        {
                            if (object_0 is IMap)
                            {
                                (object_0 as IMap).AddLayer(layer5);
                            }
                            else if (object_0 is IGroupLayer)
                            {
                                (object_0 as IGroupLayer).Add(layer5);
                            }
                            array.Remove(index);
                            count--;
                        }
                    }
                }
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (layer5 is IFeatureLayer)
                    {
                        layer        = layer5 as IFeatureLayer;
                        featureClass = layer.FeatureClass;
                        if (((((featureClass.ShapeType == esriGeometryType.esriGeometryLine) ||
                               (featureClass.ShapeType == esriGeometryType.esriGeometryBezier3Curve)) ||
                              ((featureClass.ShapeType == esriGeometryType.esriGeometryCircularArc) ||
                               (featureClass.ShapeType == esriGeometryType.esriGeometryEllipticArc))) ||
                             (featureClass.ShapeType == esriGeometryType.esriGeometryPath)) ||
                            (featureClass.ShapeType == esriGeometryType.esriGeometryPolyline))
                        {
                            if (object_0 is IMap)
                            {
                                (object_0 as IMap).AddLayer(layer5);
                            }
                            else if (object_0 is IGroupLayer)
                            {
                                (object_0 as IGroupLayer).Add(layer5);
                            }
                            array.Remove(index);
                            count--;
                        }
                    }
                }
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (layer5 is IFeatureLayer)
                    {
                        layer        = layer5 as IFeatureLayer;
                        featureClass = layer.FeatureClass;
                        if ((featureClass.ShapeType == esriGeometryType.esriGeometryMultipoint) ||
                            (featureClass.ShapeType == esriGeometryType.esriGeometryPoint))
                        {
                            if (object_0 is IMap)
                            {
                                (object_0 as IMap).AddLayer(layer5);
                            }
                            else if (object_0 is IGroupLayer)
                            {
                                (object_0 as IGroupLayer).Add(layer5);
                            }
                            array.Remove(index);
                            count--;
                        }
                    }
                }
                for (index = count - 1; index >= 0; index--)
                {
                    layer5 = array.get_Element(index) as ILayer;
                    if (object_0 is IMap)
                    {
                        (object_0 as IMap).AddLayer(layer5);
                    }
                    else if (object_0 is IGroupLayer)
                    {
                        (object_0 as IGroupLayer).Add(layer5);
                    }
                    array.Remove(index);
                }
                System.Windows.Forms.Cursor.Current = Cursors.Default;
            }
        }
Beispiel #26
0
        // // 添加CAD,dxf,dgn图层
        public static bool AddCADLayer(ref IBasicMap pBasicMap, string vPath, List <IFeatureLayer> pSelectedCln, bool blnAddData)
        {
            bool functionReturnValue = false;

            //WHFErrorHandle.clsErrorHandle pdisplayinfo = new WHFErrorHandle.clsErrorHandle();
            IWorkspaceFactory pFact             = default(IWorkspaceFactory);
            IWorkspace        pWorkSpace        = default(IWorkspace);
            IFeatureWorkspace pFeatureWorkspace = default(IFeatureWorkspace);
            IFeatureLayer     pFtLyr            = default(IFeatureLayer);
            IFeatureClass     pFtCls            = default(IFeatureClass);
            string            pFile             = null;

            pFact             = new CadWorkspaceFactory();
            pWorkSpace        = pFact.OpenFromFile(vPath, 0);
            pFeatureWorkspace = (IFeatureWorkspace)pWorkSpace;
            int             i          = 0;
            int             j          = 0;
            IFeatureDataset pFtDataset = default(IFeatureDataset);

            for (j = 1; j <= pSelectedCln.Count; j++)
            {
                pFile      = (string)pSelectedCln[j].Name;
                pFtDataset = pFeatureWorkspace.OpenFeatureDataset(pFile);
                IFeatureClassContainer pFtClsContainer = default(IFeatureClassContainer);
                pFtClsContainer = (IFeatureClassContainer)pFtDataset;

                //检查当前目录是否是cad工作空间
                if (pFtClsContainer == null | pFtClsContainer.ClassCount == 0)
                {
                    //pdisplayinfo.DisplayInformation("CAD文件:" + pFile + "不存在数据层", false);
                    MessageBoxEx.Show("CAD文件:" + pFile + "不存在数据层", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    functionReturnValue = false;
                    return(functionReturnValue);
                }

                for (i = 0; i <= pFtClsContainer.ClassCount - 1; i++)
                {
                    pFtCls = pFtClsContainer.get_Class(i);
                    if (pFtCls.FeatureType == esriFeatureType.esriFTSimple)
                    {
                        pFtLyr = new CadFeatureLayerClass();
                        pFtLyr.FeatureClass = pFtCls;
                        pFtLyr.Name         = pFile + ":" + pFtCls.AliasName;

                        pSelectedCln.Add(pFtLyr);
                        functionReturnValue = true;
                    }
                    else if (pFtCls.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        pFtLyr = new CadAnnotationLayerClass();
                        pFtLyr.FeatureClass = pFtCls;

                        pFtLyr.Name = pFile + " " + pFtCls.AliasName;

                        pSelectedCln.Add(pFtLyr);

                        functionReturnValue = true;
                    }
                }
            }
            return(functionReturnValue);
        }
Beispiel #27
0
        private void Network_Load(object sender, EventArgs e)
        {
            //获取几何网络文件路径
            //注意修改此路径为当前存储路径
            string strPath = Application.StartupPath + @"\nanjingroad.mdb";
            //打开工作空间
            IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactory();
            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(strPath, 0) as IFeatureWorkspace;
            //获取要素数据集
            //注意名称的设置要与上面创建保持一致
            IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset("road_merge");

            //获取network集合
            INetworkCollection pNetWorkCollection = pFeatureDataset as INetworkCollection;
            //获取network的数量,为零时返回
            int intNetworkCount = pNetWorkCollection.GeometricNetworkCount;

            //if (intNetworkCount < 1)
            //    return;
            //FeatureDataset可能包含多个network,我们获取指定的network
            //注意network的名称的设置要与上面创建保持一致
            mGeometricNetwork = pNetWorkCollection.get_GeometricNetworkByName("road_merge_Net");

            //将Network中的每个要素类作为一个图层加入地图控件
            IFeatureClassContainer pFeatClsContainer = mGeometricNetwork as IFeatureClassContainer;
            //获取要素类数量,为零时返回
            int intFeatClsCount = pFeatClsContainer.ClassCount;

            if (intFeatClsCount < 1)
            {
                return;
            }
            IFeatureClass pFeatureClass;
            IFeatureLayer pFeatureLayer;

            for (int i = 0; i < intFeatClsCount; i++)
            {
                //获取要素类
                pFeatureClass = pFeatClsContainer.get_Class(i);
                pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pFeatureClass;
                pFeatureLayer.Name         = pFeatureClass.AliasName;
                //加入地图控件
                this.axMapControl1.AddLayer((ILayer)pFeatureLayer, 0);
            }

            //计算snap tolerance为图层最大宽度的1/100
            //获取图层数量
            int         intLayerCount = this.axMapControl1.LayerCount;
            IGeoDataset pGeoDataset;
            IEnvelope   pMaxEnvelope = new EnvelopeClass();

            for (int i = 0; i < intLayerCount; i++)
            {
                //获取图层
                pFeatureLayer = this.axMapControl1.get_Layer(i) as IFeatureLayer;
                pGeoDataset   = pFeatureLayer as IGeoDataset;
                //通过Union获得较大图层范围
                pMaxEnvelope.Union(pGeoDataset.Extent);
            }
            double dblWidth  = pMaxEnvelope.Width;
            double dblHeight = pMaxEnvelope.Height;
            double dblSnapTol;

            if (dblHeight < dblWidth)
            {
                dblSnapTol = dblWidth * 0.05;
            }
            else
            {
                dblSnapTol = dblHeight * 0.05;
            }

            //设置源地图,几何网络以及捕捉容差
            mPointToEID                  = new PointToEIDClass();
            mPointToEID.SourceMap        = this.axMapControl1.Map;
            mPointToEID.GeometricNetwork = mGeometricNetwork;
            mPointToEID.SnapTolerance    = dblSnapTol;
        }
Beispiel #28
0
        /// <summary>
        /// (从Base库)生成Query库
        /// 默认的实现是从Base库导入
        /// </summary>
        /// <returns></returns>
        protected virtual bool GenerateQuery(IWorkspace wsBase)
        {
            string     strWorkspace = this.m_TargetPath + "\\" + COMMONCONST.DB_Name_Query;
            IWorkspace wsQuery      = null;

            if (!Hy.Common.Utility.Esri.AEAccessFactory.OpenPGDB(ref wsQuery, strWorkspace))
            {
                SendMessage(enumMessageType.Exception, "导入数据失败:无法打开Query库,请确认在创建任务文件结构时已创建Query库");
                return(false);
            }
            //Hy.Common.Utility.Esri.AEAccessFactory.CreatePGDB(this.m_TargetPath, COMMONCONST.DB_Name_Query);
            //IFeatureDataset fdsTarget = CreateFeatureDataset(wsQuery, this.m_SpatialReference);

            Hy.Common.Utility.Esri.GPTool gpTool = new Hy.Common.Utility.Esri.GPTool();

            // 打开数据源
            if (wsBase == null)
            {
                SendMessage(enumMessageType.Exception, "创建Query库出错:无法打开Base库");

                return(false);
            }

            // 获取FeatureClass名列表
            IEnumDataset enDataset = wsBase.get_Datasets(esriDatasetType.esriDTAny);
            IDataset     dataset   = enDataset.Next();

            while (dataset != null)
            {
                switch (dataset.Type)
                {
                case esriDatasetType.esriDTTable:
                case esriDatasetType.esriDTFeatureClass:
                    SendEvent(dataset.Name);
                    Hy.Common.Utility.Esri.DataConverter.ConvertTable(wsBase, wsQuery, dataset, GetObjectName(dataset.Name));
                    break;

                case esriDatasetType.esriDTFeatureDataset:
                    IFeatureClassContainer fcContianer = dataset as IFeatureClassContainer;
                    for (int i = 0; i < fcContianer.ClassCount; i++)
                    {
                        IDataset dsSub = fcContianer.get_Class(i) as IDataset;
                        SendEvent(dsSub.Name);
                        Hy.Common.Utility.Esri.DataConverter.ConvertTable(wsBase, wsQuery, dsSub, GetObjectName(dsSub.Name));
                    }
                    break;

                default:
                    break;
                }

                dataset = enDataset.Next();
            }

            // 释放
            enDataset = null;
            dataset   = null;

            System.Runtime.InteropServices.Marshal.ReleaseComObject(wsBase);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(wsQuery);
            wsBase  = null;
            wsQuery = null;
            GC.Collect();

            return(true);
        }
Beispiel #29
0
        /// <summary>
        /// (从数据源)导入到Base库,并返回Base库Workspace对象
        /// </summary>
        /// <param name="wsSource"></param>
        /// <returns></returns>
        protected virtual bool ImportToBase(ref IWorkspace wsBase)
        {
            // 直接复制的方式
            if (m_JustCopy)
            {
                return(CopyToBase(ref wsBase));
            }

            // 导入的方式
            string strWorkspace = this.m_TargetPath + "\\" + COMMONCONST.DB_Name_Base;

            if (!Hy.Common.Utility.Esri.AEAccessFactory.OpenFGDB(ref wsBase, strWorkspace))
            {
                SendMessage(enumMessageType.Exception, "导入数据失败:无法打开Base库,请确认在创建任务文件结构时已创建Base库");
                return(false);
            }// Hy.Common.Utility.Esri.AEAccessFactory.CreateFGDB(this.m_TargetPath, COMMONCONST.DB_Name_Base);
            IFeatureDataset fdsTarget = CreateFeatureDataset(wsBase, this.m_SpatialReference);

            if (fdsTarget == null)
            {
                SendMessage(enumMessageType.Exception, "“Dataset”没有创建成功,无法继续导入");
                return(false);
            }
            Hy.Common.Utility.Esri.GPTool gpTool = new Hy.Common.Utility.Esri.GPTool();

            // 打开数据源
            IWorkspace wsSource = null;

            try
            {
                wsSource = AEAccessFactory.OpenWorkspace(this.m_DataType, this.m_Datasource);
                if (wsSource == null)
                {
                    SendMessage(enumMessageType.Exception, "打开数据源出错");
                    return(false);
                }

                // 获取FeatureClass名列表
                IEnumDataset enDataset = wsSource.get_Datasets(esriDatasetType.esriDTAny);
                IDataset     dataset   = enDataset.Next();
                while (dataset != null)
                {
                    switch (dataset.Type)
                    {
                    case esriDatasetType.esriDTTable:
                        SendEvent(dataset.Name);
                        Hy.Common.Utility.Esri.DataConverter.ConvertTable(wsSource, wsBase, dataset, GetObjectName(dataset.Name));
                        break;

                    case esriDatasetType.esriDTFeatureClass:
                        SendEvent(dataset.Name);
                        gpTool.CopyFeatureClass(string.Format("{0}\\{1}", this.m_Datasource, dataset.Name + (this.m_DataType == enumDataType.SHP ? ".shp" : "")), string.Format("{0}\\{1}\\{2}", strWorkspace, fdsTarget.Name, GetObjectName(dataset.Name)));
                        //Hy.Common.Utility.Esri.DataConverter.ConvertFeatureClass(wsSource as IDataset,fdsTarget as IDataset, dataset as IFeatureClass, GetObjectName(dataset.Name));
                        break;

                    case esriDatasetType.esriDTFeatureDataset:
                        IFeatureClassContainer fsContainer = dataset as IFeatureClassContainer;
                        for (int i = 0; i < fsContainer.ClassCount; i++)
                        {
                            string strFcName = (fsContainer.get_Class(i) as IDataset).Name;
                            SendEvent(strFcName);
                            gpTool.CopyFeatureClass(string.Format("{0}\\{1}\\{2}", this.m_Datasource, dataset.Name, strFcName), string.Format("{0}\\{1}\\{2}", strWorkspace, fdsTarget.Name, GetObjectName(strFcName)));
                            //Hy.Common.Utility.Esri.DataConverter.ConvertFeatureClass(dataset, fdsTarget as IDataset, fsContainer.get_Class(i), (fsContainer.get_Class(i) as IDataset).Name);
                        }

                        break;

                    default: break;
                    }

                    dataset = enDataset.Next();
                }

                // 释放
                enDataset = null;
                dataset   = null;

                // 改别名
                this.RenameClassObjects(wsBase);
            }
            catch (Exception exp)
            {
                SendMessage(enumMessageType.Exception, "导入Base库出错:" + exp.ToString());
            }
            finally
            {
                if (wsSource != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(wsSource);
                    wsSource = null;
                }
            }

            return(true);
        }
Beispiel #30
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)
        }