最简单的ArcGIS Engine应用程序(下)

在中篇我们讲到使用OpenFileDialog控件可以添加shp文件。(最简单的ArcGIS Engine应用程序(中)

添加lyr文件的操作也是大同小异的。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;

namespace SimpleArcEngineDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void menuAddLyr_Click(object sender, EventArgs e)
        {
            //步骤1: 打开文件对话框浏览到一个具体lyr文件。
            
            //文件过滤器, 选择后缀名为.lyr
            openFileDialog1.Filter = "lyr文件(*.lyr)|*.lyr";
            
            //设定文件对话框的初始化路径
            openFileDialog1.InitialDirectory = @"D:\data";
            
            openFileDialog1.Multiselect = false; //不允许多选
            DialogResult pDialogResult = openFileDialog1.ShowDialog(); //打开对话框
            if (pDialogResult != DialogResult.OK)
            {
                return; //用户没有选择时返回
            }
            string pFileName = openFileDialog1.FileName; //得到完整的路径(路径+文件名)

            //步骤2: 通过地图控件的方法(AddLayerFromFile)直接加载。
            axMapControl1.AddLayerFromFile(pFileName);
            axMapControl1.ActiveView.Refresh();
} } }

 

简述:

单机“添加lyr”,会弹出一个打开文件的对话框,浏览目录后选择任意一个lyr文件,单机确定,即可将指定的lyr文件加载到地图控件当中。

 

谢谢观看!本人初学GIS二次开发,如果有不对的地方,请多多包涵!

 

posted @ 2019-10-21 14:32  the_path_of_grace  阅读(384)  评论(0编辑  收藏  举报