Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 3
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);
                }
            }
        }
 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);
     }
 }
Exemplo n.º 5
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();
        }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 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);
             }
         }
     }
 }
Exemplo n.º 10
0
        public static void AddData_CAD(AxMapControl axMapControl1)
        {
            IWorkspaceFactory pWorkspaceFactory;
            IFeatureWorkspace pFeatureWorkspace;
            IFeatureLayer pFeatureLayer;
            IFeatureDataset pFeatureDataset;
            //获取当前路径和文件名
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string strFullPath = dlg.FileName;
                if (strFullPath == "") return;
                int Index = strFullPath.LastIndexOf("//");
                string filePath = strFullPath.Substring(0, Index);
                string fileName = strFullPath.Substring(Index + 1);
                //打开CAD数据集
                pWorkspaceFactory = new CadWorkspaceFactoryClass();
                pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(filePath, 0);
                //打开一个要素集
                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;
                    axMapControl1.Map.AddLayer(pFeatureLayer);
                    axMapControl1.ActiveView.Refresh();
                }

                ILayer layer = axMapControl1.get_Layer(0);
                axMapControl1.Extent = layer.AreaOfInterest;
            }
        }
Exemplo n.º 11
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();
            }
        }
Exemplo n.º 12
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);
                }
            }
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
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);
                }
            }
        }
Exemplo n.º 15
0
        private void btnAddCadAsFeat_Click(object sender, EventArgs e)
        {
            this.openFileDialog.Filter = "CAD文件(*.dwg)|*.dwg";
            this.openFileDialog.Title = "请选择CAD文件";
            if (this.openFileDialog.ShowDialog() == DialogResult.OK)
            {
                Application.DoEvents();
                try
                {
                    IWorkspaceFactory pCADWorksapceFactory;
                    pCADWorksapceFactory = new CadWorkspaceFactoryClass();
                    IFeatureWorkspace pFeatureWorkspace;
                    pFeatureWorkspace = pCADWorksapceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(this.openFileDialog.FileName), 0) as IFeatureWorkspace;
                    IFeatureDataset pFeatureDataset;
                    pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(System.IO.Path.GetFileName(this.openFileDialog.FileName));
                    IFeatureClassContainer pFeatureClassContainer;
                    pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;
                    IFeatureClass pFeatureClass;
                    IFeatureLayer pFeatureLayer;
                    int i;
                    for (i = 0; i <= pFeatureClassContainer.ClassCount - 1; 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;
                        this.mainMapControl.AddLayer(pFeatureLayer);
                        this.EagleaxMapControl.AddLayer(pFeatureLayer);
                    }
                    this.EagleaxMapControl.Extent = this.mainMapControl.FullExtent;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

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

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

            processAssist.InitProgress();
            processAssist.SetMaxValue(objs.Count);
            processAssist.SetMessage("正在加载数据,请稍候...");
            processAssist.Start();
            try
            {
                ILayer layer = null;
                IMap   map   = this.GetMap();
                this.list_0 = new List <ILayer>();
                List <string> strs      = new List <string>();
                IEnvelope     envelope  = null;
                IDataset      item      = null;
                IGxDataset    gxDataset = null;
                for (int k = 0; k < objs.Count; k++)
                {
                    string name = "";
                    if (objs[k] is IGxObject)
                    {
                        name = (objs[k] as IGxObject).Name;
                    }
                    else if (objs[k] is IDataset)
                    {
                        name = (objs[k] as IDataset).Name;
                    }
                    bool flag = true;
                    str = string.Format("加载图层[{0}],第{1}/{2}个", name, k + 1, objs.Count);
                    processAssist.Increment(1);
                    processAssist.SetMessage(str);
                    if (objs[k] is IGxLayer)
                    {
                        layer = (objs[k] as IGxLayer).Layer;
                        if (layer is IGeoDataset && !SpatialReferenctOperator.ValideFeatureClass(layer as IGeoDataset))
                        {
                            strs.Add(layer.Name);
                            flag = false;
                        }
                        this.AddLayer(map, layer, ref envelope, flag);
                    }
                    else if (!(objs[k] is IGxAGSObject))
                    {
                        if (objs[k] is IGxDataset)
                        {
                            gxDataset = objs[k] as IGxDataset;
                            item      = gxDataset.Dataset;
                        }
                        else if (ilist_0[k] is IDataset)
                        {
                            item = objs[k] as IDataset;
                        }
                        if (item != null)
                        {
                            if (item is IGeoDataset)
                            {
                                flag = SpatialReferenctOperator.ValideFeatureClass(item as IGeoDataset);
                            }
                            if (item.Type == esriDatasetType.esriDTFeatureClass)
                            {
                                dataset = (IFeatureClass)item;
                                if ((gxDataset as IGxObject).Category.IndexOf("CAD") != -1)
                                {
                                    if (dataset.FeatureType != esriFeatureType.esriFTCoverageAnnotation)
                                    {
                                        cadFeatureLayerClass = new CadFeatureLayerClass();
                                    }
                                    else
                                    {
                                        cadFeatureLayerClass = new CadAnnotationLayerClass();
                                    }
                                    cadFeatureLayerClass.FeatureClass = dataset;
                                    cadFeatureLayerClass.Name         = dataset.AliasName;
                                }
                                else if (dataset.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else if (dataset.FeatureType != esriFeatureType.esriFTDimension)
                                {
                                    cadFeatureLayerClass = new FeatureLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                else
                                {
                                    cadFeatureLayerClass = new DimensionLayerClass()
                                    {
                                        FeatureClass = dataset,
                                        Name         = dataset.AliasName
                                    };
                                }
                                if (!flag)
                                {
                                    strs.Add(cadFeatureLayerClass.Name);
                                }
                                this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTCadDrawing)
                            {
                                if ((gxDataset as IGxObject).Category != "CAD绘图")
                                {
                                    IEnumGxObject enumGxObject = (gxDataset as IGxObjectContainer).Children;
                                    enumGxObject.Reset();
                                    for (IGxDataset l = enumGxObject.Next() as IGxDataset; l != null; l = enumGxObject.Next() as IGxDataset)
                                    {
                                        dataset = l.Dataset as IFeatureClass;
                                        if (dataset != null)
                                        {
                                            if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                            {
                                                cadFeatureLayerClass = new CadFeatureLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            else
                                            {
                                                cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                                {
                                                    FeatureClass = dataset,
                                                    Name         = dataset.AliasName
                                                };
                                            }
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag1 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag1;
                                                if (!flag1)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                }
                                else
                                {
                                    ICadLayer cadLayerClass = new CadLayerClass()
                                    {
                                        CadDrawingDataset = gxDataset.Dataset as ICadDrawingDataset,
                                        Name = gxDataset.Dataset.Name
                                    };
                                    if (!flag)
                                    {
                                        strs.Add(cadLayerClass.Name);
                                    }
                                    this.AddLayer(map, cadLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTFeatureDataset)
                            {
                                subsets = item.Subsets;
                                subsets.Reset();
                                for (j = subsets.Next(); j != null; j = subsets.Next())
                                {
                                    if (j.Type == esriDatasetType.esriDTFeatureClass)
                                    {
                                        dataset = j as IFeatureClass;
                                        if (dataset.FeatureType != esriFeatureType.esriFTAnnotation)
                                        {
                                            cadFeatureLayerClass = new FeatureLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag2 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag2;
                                                if (!flag2)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                        else
                                        {
                                            cadFeatureLayerClass = new FDOGraphicsLayerClass()
                                            {
                                                FeatureClass = dataset,
                                                Name         = dataset.AliasName
                                            };
                                            flag = true;
                                            if (cadFeatureLayerClass is IGeoDataset)
                                            {
                                                bool flag3 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                                flag = flag3;
                                                if (!flag3)
                                                {
                                                    strs.Add(cadFeatureLayerClass.Name);
                                                }
                                            }
                                            this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                        }
                                    }
                                    else if (j.Type == esriDatasetType.esriDTTopology)
                                    {
                                        topologyLayerClass = new TopologyLayerClass()
                                        {
                                            Topology = j as ITopology
                                        };
                                        (topologyLayerClass as ILayer).Name = j.Name;
                                        this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTopology)
                            {
                                if (MessageBox.Show(string.Concat("是否将参加拓扑-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        flag = true;
                                        if (cadFeatureLayerClass is IGeoDataset)
                                        {
                                            bool flag4 = SpatialReferenctOperator.ValideFeatureClass(cadFeatureLayerClass as IGeoDataset);
                                            flag = flag4;
                                            if (!flag4)
                                            {
                                                strs.Add(cadFeatureLayerClass.Name);
                                            }
                                        }
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, flag);
                                    }
                                }
                                topologyLayerClass = new TopologyLayerClass()
                                {
                                    Topology = item as ITopology
                                };
                                (topologyLayerClass as ILayer).Name = item.Name;
                                this.AddLayer(map, topologyLayerClass as ILayer, ref envelope, true);
                            }
                            else if (item.Type == esriDatasetType.esriDTTin)
                            {
                                ITinLayer tinLayerClass = new TinLayerClass()
                                {
                                    Dataset = (ITin)item,
                                    Name    = item.Name
                                };
                                flag = true;
                                if (tinLayerClass is IGeoDataset)
                                {
                                    bool flag5 = SpatialReferenctOperator.ValideFeatureClass(tinLayerClass as IGeoDataset);
                                    flag = flag5;
                                    if (!flag5)
                                    {
                                        strs.Add(tinLayerClass.Name);
                                    }
                                }
                                this.AddLayer(map, tinLayerClass, ref envelope, flag);
                            }
                            else if (item.Type == esriDatasetType.esriDTRasterCatalog)
                            {
                                IGdbRasterCatalogLayer gdbRasterCatalogLayerClass = null;
                                gdbRasterCatalogLayerClass = new GdbRasterCatalogLayerClass();
                                if (gdbRasterCatalogLayerClass.Setup((ITable)(item as IRasterCatalog)))
                                {
                                    bool flag6 = SpatialReferenctOperator.ValideFeatureClass(gdbRasterCatalogLayerClass as IGeoDataset);
                                    flag = flag6;
                                    if (!flag6)
                                    {
                                        strs.Add((gdbRasterCatalogLayerClass as ILayer).Name);
                                    }
                                    this.AddLayer(map, gdbRasterCatalogLayerClass as ILayer, ref envelope, flag);
                                }
                            }
                            else if (!(item.Type == esriDatasetType.esriDTRasterDataset ? false : item.Type != esriDatasetType.esriDTRasterBand))
                            {
                                bool flag7 = true;
                                if (!((IRasterPyramid)item).Present)
                                {
                                    if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysBuildNoPrompt)
                                    {
                                        ((IRasterPyramid)item).Create();
                                    }
                                    else if (this.m_pApp.PyramidPromptType == PyramidPromptType.AlwaysPrompt)
                                    {
                                        DialogResult dialogResult = BuildPyramidSet.Show();
                                        if (dialogResult == DialogResult.Yes)
                                        {
                                            ((IRasterPyramid)item).Create();
                                        }
                                        else if (dialogResult == DialogResult.Cancel)
                                        {
                                            flag7 = false;
                                        }
                                    }
                                }
                                if (flag7)
                                {
                                    IRasterLayer rasterLayerClass = new RasterLayerClass()
                                    {
                                        Cached = true
                                    };
                                    rasterLayerClass.CreateFromDataset((IRasterDataset)item);
                                    rasterLayerClass.Name = item.Name;
                                    bool flag8 = SpatialReferenctOperator.ValideFeatureClass(rasterLayerClass as IGeoDataset);
                                    flag = flag8;
                                    if (!flag8)
                                    {
                                        strs.Add(rasterLayerClass.Name);
                                    }
                                    this.AddLayer(map, rasterLayerClass, ref envelope, flag);
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTTable)
                            {
                                try
                                {
                                    IStandaloneTableCollection standaloneTableCollection = this.GetMap() as IStandaloneTableCollection;
                                    IPropertySet connectionProperties = item.Workspace.ConnectionProperties;
                                    bool         flag9 = false;
                                    int          num   = 0;
                                    while (true)
                                    {
                                        if (num < standaloneTableCollection.StandaloneTableCount)
                                        {
                                            ITable table = standaloneTableCollection.StandaloneTable[num].Table;
                                            if (!connectionProperties.IsEqual((table as IDataset).Workspace.ConnectionProperties) || !((table as IDataset).Name == item.Name))
                                            {
                                                num++;
                                            }
                                            else
                                            {
                                                flag9 = true;
                                                break;
                                            }
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                    if (!flag9)
                                    {
                                        standaloneTableCollection.AddStandaloneTable(new StandaloneTableClass()
                                        {
                                            Table = item as ITable
                                        });
                                    }
                                }
                                catch (Exception exception)
                                {
                                    CErrorLog.writeErrorLog(this, exception, "");
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTGeometricNetwork)
                            {
                                IGeometricNetwork geometricNetwork = item as IGeometricNetwork;
                                if (geometricNetwork != null)
                                {
                                    IEnumFeatureClass classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexJunction];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTSimpleEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                    classesByType = geometricNetwork.ClassesByType[esriFeatureType.esriFTComplexEdge];
                                    classesByType.Reset();
                                    for (n = classesByType.Next(); n != null; n = classesByType.Next())
                                    {
                                        featureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = n,
                                            Name         = (n as IDataset).Name
                                        };
                                        this.AddLayer(map, featureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                            else if (item.Type == esriDatasetType.esriDTNetworkDataset)
                            {
                                INetworkLayer networkLayerClass = new NetworkLayerClass()
                                {
                                    NetworkDataset = item as INetworkDataset
                                };
                                this.AddLayer(map, networkLayerClass as ILayer, ref envelope, true);
                                if (MessageBox.Show(string.Concat("是否将参加网络要素集-", item.Name, "-的所有要素添加到地图中"), "添加拓扑层", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) == DialogResult.Yes)
                                {
                                    classes = (item as IFeatureClassContainer).Classes;
                                    classes.Reset();
                                    for (m = classes.Next(); m != null; m = classes.Next())
                                    {
                                        cadFeatureLayerClass = new FeatureLayerClass()
                                        {
                                            FeatureClass = m,
                                            Name         = m.AliasName
                                        };
                                        this.AddLayer(map, cadFeatureLayerClass, ref envelope, true);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        IMapServerLayer mapServerLayerClass = new MapServerLayerClass();
                        mapServerLayerClass.ServerConnect((objs[k] as IGxAGSObject).AGSServerObjectName, (objs[k] as IGxAGSObject).DefaultMapName);
                        this.AddLayer(map, mapServerLayerClass as ILayer, ref envelope, false);
                    }
                }
                processAssist.End();
                bool layerCount = this.GetMap().LayerCount > 0;
                if (strs.Count > 0)
                {
                    MessageBox.Show("警告:数据范围不一致。\r\n 一个或多个添加的图层范围与关联的空间坐标系范围不一致。请检查数据问题。存在问题图层信息请查看错误日志!", "管理平台", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    StringBuilder stringBuilder = new StringBuilder();
                    foreach (string str1 in strs)
                    {
                        if (stringBuilder.Length > 0)
                        {
                            stringBuilder.Append(",");
                        }
                        stringBuilder.Append(str1);
                    }
                    CErrorLog.writeErrorLog(stringBuilder, null, "图层范围不一致!");
                }
                foreach (ILayer list0 in this.list_0)
                {
                    list0.Visible = true;
                }
                if (layerCount && envelope != null)
                {
                    IMap map1 = this.GetMap();
                    ISpatialReference spatialReference = map1.SpatialReference;
                    if ((spatialReference is IUnknownCoordinateSystem || envelope.SpatialReference is IUnknownCoordinateSystem || envelope.SpatialReference == null ? false : spatialReference != null))
                    {
                        envelope.Project(spatialReference);
                    }
                    (map1 as IActiveView).Extent = envelope;
                    (map1 as IActiveView).Refresh();
                }
                if (this.m_pApp != null)
                {
                    this.m_pApp.MapDocumentChanged();
                }
                else if (ApplicationRef.Application != null)
                {
                    ApplicationRef.Application.MapDocumentChanged();
                }
            }
            catch (Exception exception1)
            {
                str = exception1.ToString();
            }
            if (this.onLoadCompleteHand_0 != null)
            {
                this.onLoadCompleteHand_0();
            }
        }
Exemplo n.º 18
0
        /// <summary>
        ///导入dxf,shp等文件
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public void ImportFile(string path,AxMapControl mapControl)
        {
            string fileName = "";
            IWorkspaceFactory pWorkspaceFactory;
            IFeatureWorkspace pFeatureWorkspace;
            IFeatureLayer pFeatureLayer;
            IFeatureDataset pFeatureDataset;
            OpenFileDialog ofd = new OpenFileDialog();                //new一个方法
            ofd.Title = "导入地图数据";
            ofd.InitialDirectory = path; //定义打开的默认文件夹位置
            ofd.Filter = "shp文件(*.shp)|*.shp|CAD文件(*.dwg)|*.dwg";
            if (ofd.ShowDialog() == DialogResult.OK)          //显示打开文件的窗口
            {
                fileName = ofd.FileName;               //获得选择的文件路径
                if (fileName.Substring(fileName.Length - 4, 4).ToLower() == ".shp")
                {
                    try
                    {
                        pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                        pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(path, 0);
                        pFeatureLayer = new FeatureLayerClass();
                        pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass((System.IO.Path.GetFileName(ofd.FileName)).Replace(".shp", ""));
                        pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;
                        mapControl.Map.AddLayer(pFeatureLayer);
                        mapControl.ActiveView.Refresh();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
                else
                {
                    if (fileName.Substring(fileName.Length -4, 4).ToLower() == ".dwg")
                    {
                        try
                        {
                         //打开CAD数据集
                        pWorkspaceFactory = new CadWorkspaceFactoryClass();
                        pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(path, 0);
                        //打开一个要素集
                        pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset((System.IO.Path.GetFileName(ofd.FileName)).Replace(".dwg", ""));
                        //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();
                            }
                        }
                        }
                            catch(Exception e)
                        {
                                MessageBox.Show(e.Message);
                            }

            }
               }
            }
        }
Exemplo n.º 19
0
        /// <summary>
        ///导入dxf,shp等文件
        /// 日期2013-12-13
        /// lntu_GISer1
        /// </summary>
        public void ImportFile(string path, AxMapControl mapControl)
        {
            string            fileName = "";
            IWorkspaceFactory pWorkspaceFactory;
            IFeatureWorkspace pFeatureWorkspace;
            IFeatureLayer     pFeatureLayer;
            IFeatureDataset   pFeatureDataset;
            OpenFileDialog    ofd = new OpenFileDialog();             //new一个方法

            ofd.Title            = "导入地图数据";
            ofd.InitialDirectory = path;             //定义打开的默认文件夹位置
            ofd.Filter           = "shp文件(*.shp)|*.shp|CAD文件(*.dwg)|*.dwg";
            if (ofd.ShowDialog() == DialogResult.OK) //显示打开文件的窗口
            {
                fileName = ofd.FileName;             //获得选择的文件路径
                if (fileName.Substring(fileName.Length - 4, 4).ToLower() == ".shp")
                {
                    try
                    {
                        pWorkspaceFactory          = new ShapefileWorkspaceFactoryClass();
                        pFeatureWorkspace          = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(path, 0);
                        pFeatureLayer              = new FeatureLayerClass();
                        pFeatureLayer.FeatureClass = pFeatureWorkspace.OpenFeatureClass((System.IO.Path.GetFileName(ofd.FileName)).Replace(".shp", ""));
                        pFeatureLayer.Name         = pFeatureLayer.FeatureClass.AliasName;
                        mapControl.Map.AddLayer(pFeatureLayer);
                        mapControl.ActiveView.Refresh();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
                else
                {
                    if (fileName.Substring(fileName.Length - 4, 4).ToLower() == ".dwg")
                    {
                        try
                        {
                            //打开CAD数据集
                            pWorkspaceFactory = new CadWorkspaceFactoryClass();
                            pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(path, 0);
                            //打开一个要素集
                            pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset((System.IO.Path.GetFileName(ofd.FileName)).Replace(".dwg", ""));
                            //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();
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show(e.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 20
0
        private void bubbleBtnAddCAD_Click(object sender, DevComponents.DotNetBar.ClickEventArgs e)
        {
            this.openFileDialog.Filter = "DWG文件|*.dwg";
            this.openFileDialog.Title = "请选择CAD文件";
            if (this.openFileDialog.ShowDialog() == DialogResult.OK)
            {
                string dirction = System.IO.Path.GetDirectoryName(this.openFileDialog.FileName);
                //MessageBox.Show(System.IO.Path.GetDirectoryName(this.openFileDialog.FileName) + "\n" +
                //                System.IO.Path.GetFileName(this.openFileDialog.FileName) + "\n" +
                //                System.IO.Path.GetFullPath(this.openFileDialog.FileName));
                string file = System.IO.Path.GetFileName(this.openFileDialog.FileName);

                IWorkspaceFactory pWorkspaceFatory = new CadWorkspaceFactoryClass();
                IWorkspace pWorkspace = pWorkspaceFatory.OpenFromFile(dirction, 0);
                IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
                IFeatureDataset pFeatureDataset = pFeatureWorkspace.OpenFeatureDataset(file);
                IFeatureClassContainer pFeatureClassContainer = pFeatureDataset as IFeatureClassContainer;
                IFeatureClass pFeatureClass;
                IFeatureLayer pFeatureLayer;
                //for (int i = 0; i < pFeatureClassContainer.ClassCount; i++)
                //{
                //    pFeatureClass = pFeatureClassContainer.get_ClassByID(i);
                //    if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                //    {
                //        pFeatureLayer = new CadAnnotationLayerClass();
                //    }
                //    else
                //    {
                //        pFeatureLayer = new FeatureLayerClass();
                //    }
                //    pFeatureLayer.Name = pFeatureClass.AliasName;
                //    pFeatureLayer.FeatureClass = pFeatureClass;
                //    this.mainMapControl.AddLayer(pFeatureLayer as ILayer);
                //    this.EagleaxMapControl.AddLayer(pFeatureLayer as ILayer);
                //}
                IEnumFeatureClass pEnumFeatureClass = pFeatureClassContainer.Classes;
                pEnumFeatureClass.Reset();
                for (pFeatureClass = pEnumFeatureClass.Next(); pFeatureClass != null; pFeatureClass = pEnumFeatureClass.Next())
                {
                    if (pFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        pFeatureLayer = new CadAnnotationLayerClass();
                    }
                    else
                    {
                        pFeatureLayer = new FeatureLayerClass();
                    }
                    pFeatureLayer.Name = pFeatureClass.AliasName;
                    pFeatureLayer.FeatureClass = pFeatureClass;
                    this.mainMapControl.AddLayer(pFeatureLayer as ILayer);
                    this.EagleaxMapControl.AddLayer(pFeatureLayer as ILayer);
                }

                this.m_controlsSynchronizer.ReplaceMap(this.mainMapControl.Map);
                this.EagleaxMapControl.Extent = this.EagleaxMapControl.FullExtent;
                this.EagleaxMapControl.Refresh();
            }
        }