AE+地图文档基本操作

1.新建地图文档

        public IMapDocument pMapDoc;

        private void TSMenuItem_New_Click(object sender, EventArgs e)
        {
            pMapDoc = new MapDocumentClass();
            //设置默认路径
            string filePath = Application.StartupPath + "\\Temp\\Untitled.mxd";
            pMapDoc.New(filePath);
            pMapDoc.Open(filePath, "");
            //空白的地图文件只有一个地图
            axMapControl1.Map = pMapDoc.get_Map(0);
            MessageBox.Show("新建地图文档成功!");
        }

 

2.打开地图文档

        private void TSMenuItem_Open_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "Map Documents(*.mxd)|*.mxd";
            if(openFileDialog.ShowDialog()==DialogResult.OK)
            {

                第一种方式
                string fileName = Path.GetFileName(filePath);
                if (axMapControl1.CheckMxFile(fileName))
                {
                    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
                    axMapControl1.LoadMxFile(fileName, 0, Type.Missing);
                    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
                }
                else
                {
                    MessageBox.Show("所选文件不是地图文档文件!", "信息提示");
                    return;
                }

                第二种方式

                pMapDoc = new MapDocumentClass();
                pMapDoc.Open(filePath,"");
                for(int i=0;i<pMapDoc.MapCount;i++)
                {
                    axMapControl1.Map=pMapDoc.get_Map(i);
                }
                axMapControl1.ActiveView.Refresh();
            }
        }

 

3.保存地图文档

3.1 用于自定义IMapDocument接口打开地图文档时

        private void TSMenuItem_Save_Click(object sender, EventArgs e)
        {
            //如何pMapDoc为空,取消保存
            if (pMapDoc == null) return;

            if (pMapDoc.get_IsReadOnly(pMapDoc.DocumentFilename))
            {
                MessageBox.Show("地图文档是只读的,不能保存!");
                return;
            }

            //根据相对路径保存文档
            pMapDoc.Save(pMapDoc.UsesRelativePaths, true);
            MessageBox.Show("地图文档保存成功!");
        }

3.2 用于使用AE内置方式打开地图文档时(快捷方式打开)

        private void TSMenuItem_Save_Click(object sender, EventArgs e)
        {
            IMxdContents pMxdC = axMapControl1.Map as IMxdContents;
            IMapDocument pMapDoc= new MapDocumentClass();
            pMapDoc.Open(axMapControl1.DocumentFilename, "");
            pMapDoc.ReplaceContents(pMxdC);

            if (pMapDoc== null) return;

            if (pMapDoc.get_IsReadOnly(pMapDoc.DocumentFilename))
            {
                MessageBox.Show("地图文档是只读的,不能保存!");
                return;
            }

            pMapDoc.Save(pMapDoc.UsesRelativePaths, true);

            MessageBox.Show("地图文档保存成功!");
        }

3.3 用于使用AE内置方式添加数据时(快捷方式添加数据)

        private void TSMenuItem_Save_Click(object sender, EventArgs e)
        {
            IMxdContents pMxdC = axMapControl1.Map as IMxdContents;
            IMapDocument pMapDoc= new MapDocumentClass();
            //设置保存路径
            string filePath = Application.StartupPath + "\\Temp\\Untitled.mxd";
            pMapDoc.New(filePath);
            pMapDoc.ReplaceContents(pMxdC);
            pMapDoc.Save(true, true);
            MessageBox.Show("地图文档保存成功!");
        }

4.另存地图文档

        private void TSMenuItem_SaveAs_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Title = "另存为";
            saveFileDialog.FileName = "Untitled";
            saveFileDialog.DefaultExt = "mxd";
            saveFileDialog.Filter = "Map Documents(*.mxd)|*.mxd";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                string filePath = saveFileDialog.FileName;
                pMapDoc = new MapDocumentClass();
                pMapDoc.New(filePath);
                pMapDoc.Open(filePath,"");
                pMapDoc.Save(pMapDoc.UsesRelativePaths, true);
                MessageBox.Show("地图文档另存成功!");
            }
        }

转载于:https://www.cnblogs.com/Giser5945/p/3309369.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值