基于AE的基础的GIS系统的开发

该博客分享了GIS系统的基本功能实现,包括打开.mxd文件、添加Shp文件以及退出系统的代码。通过判断文件路径、加载地图文件、打开Shape文件并添加到地图,实现了数据的浏览。最后,介绍了退出系统时关闭窗口和释放资源的步骤。
摘要由CSDN通过智能技术生成

一个GIS系统需要的基本功能的代码

一些基本的拖拽操作就不讲了,直接上代码吧。

  1. 打开.mxd文件

基本思路:判断mxd路径存在→打开mxd文件

string filename = Application.StartupPath + "\\GIS系统.mxd";

if (axMapControl1.CheckMxFile(filename))

{

    axTOCControl1.SetBuddyControl(axMapControl1); //设置TOC与MapControl绑定

    axMapControl1.LoadMxFile(filename); //加载mxd文件

}

2、添加Shp(打开文件方式)

基本思路:打开文件→判断shp→添加shp→刷新地图

                OpenFileDialog pOpenFileDialog = new OpenFileDialog();

                pOpenFileDialog.CheckFileExists = true;

                pOpenFileDialog.Title = "导入文件";

                pOpenFileDialog.Filter = "Shape文件(*.shp)|*.shp|个人地理数据库(*.mdb)|*.mdb";

                pOpenFileDialog.ShowDialog();



                获取文件路径

                //FileInfo pFileInfo = new FileInfo(pOpenFileDialog.FileName);

                //string pPath = pOpenFileDialog.FileName.Substring(0, pOpenFileDialog.FileName.Length - pFileInfo.Name.Length);

                //mainMapControl.AddShapeFile(pPath, pFileInfo.Name);



                IWorkspaceFactory pWorkspaceFactory;

                IFeatureWorkspace pFeatureWorkspace;

                IFeatureLayer pFeatureLayer;



                string pFullPath = pOpenFileDialog.FileName;

                if (pFullPath == "") return;



                int pIndex = pFullPath.LastIndexOf("\\");

                string pFilePath = pFullPath.Substring(0, pIndex); //文件路径

                string pFileName = pFullPath.Substring(pIndex + 1); //文件名

                string pLastName = pFileName.Substring(pFileName.Length - 3);

                if (pLastName == "shp")

                {

                    //实例化ShapefileWorkspaceFactory工作空间,打开Shape文件

                    pWorkspaceFactory = new ShapefileWorkspaceFactory();

                    pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(pFilePath, 0);

                    //创建并实例化要素集

                    IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pFileName);

                    pFeatureLayer = new FeatureLayer();

                    pFeatureLayer.FeatureClass = pFeatureClass;

                    pFeatureLayer.Name = pFeatureLayer.FeatureClass.AliasName;



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



                    axMapControl1.Map.AddLayer(pFeatureLayer);

                    axMapControl1.ActiveView.Refresh();

                }

3、退出系统

基本思路:关闭窗口→释放资源→关闭系统

this.Close();

            //if (mExitOperate == -1) //取消关闭

            //    return;

            //else

            //{

            //    Process.GetCurrentProcess().Kill();

            //    System.Environment.Exit(0);

            //}

            Process.GetCurrentProcess().Kill();

            System.Environment.Exit(0);

这三个基本功能可以满足一个基础的浏览数据的GIS系统。

说明:后文中可能会出现一些并未声明的变量,极有可能为全局变量,程序中的全局变量如下:

        //图层右键

        private ILayer m_Layer;

        private ILayer pMoveLayer;

        private int toIndex;

        private System.Drawing.Point pMoveLayerPoint;

        IFeatureLayer pTocFeatureLayer = null;

        private string sMapUnits = "";       

//指北针

        private INorthArrow m_NorthArrrow;

        private IElement pElement;

        private string operation;

若有任何问题,欢迎留言!

 在这里插入图片描述

扫码关注公众号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值