ArcGIS Engine开发——加载数据

来源:互联网 发布:手机淘宝首页海报尺寸 编辑:程序博客网 时间:2024/06/08 18:23

代码:

public static IMapDocument pMapDocument;        public static IActiveView pActiveView;        public static IMap pMap;        public static DataTable attributeTable;        //加载地图文档        public static void LoadGeoData(AxMapControl axMapControl1,AxMapControl axMapControl2,string strFileName)        {            string strExtentName = System.IO.Path.GetExtension(strFileName);            switch(strExtentName)            {                case ".shp":                    {                        string strPath = System.IO.Path.GetDirectoryName(strFileName);                        string strNmae = System.IO.Path.GetFileNameWithoutExtension(strFileName);                        axMapControl1.AddShapeFile(strPath, strNmae);                        axMapControl2.AddShapeFile(strPath, strNmae);                        axMapControl2.Extent = axMapControl2.FullExtent;                        break;                    }                case ".bmp":                case ".tif":                case ".jpg":                case ".img":                    {                        IRasterLayer pRasterLayer;                        pRasterLayer = new RasterLayerClass();                        string pathName = System.IO.Path.GetDirectoryName(strFileName);                        string fileName = System.IO.Path.GetFileName(strFileName);                        IRasterWorkspace pRWS;                        IWorkspaceFactory pWSF;                        IRaster pRaster;                        IRasterDataset pRasterDataset;                        IWorkspace pWS;                        pWSF = new RasterWorkspaceFactoryClass();                        pWS = pWSF.OpenFromFile(pathName, 0);                        pRWS = pWS as IRasterWorkspace;//QI                        pRasterDataset = pRWS.OpenRasterDataset(fileName);                        //影像金字塔判断与创建                        IRasterPyramid pRasPyrmid;                        pRasPyrmid = pRasterDataset as IRasterPyramid;                        if (pRasPyrmid != null)                        {                            if (!(pRasPyrmid.Present))                            {                                pRasPyrmid.Create();                                //在进度条中说明正在创建金字塔                            }                        }                        pRaster = pRasterDataset.CreateDefaultRaster();                        pRasterLayer.CreateFromRaster(pRaster);                        ILayer pLayer = pRasterLayer as ILayer;                        //向主控视图中添加图像                        axMapControl1.AddLayer(pLayer, 0);                        //确定是否加入空间参考                        axMapControl2.ClearLayers();                        //向鹰眼视图中添加图像                        axMapControl2.AddLayer(pLayer, 0);                        axMapControl2.Extent = axMapControl2.FullExtent;                        break;                        break;                    }                case ".mxd":                    {                        if (axMapControl1.CheckMxFile(strFileName))                        {                            axMapControl1.LoadMxFile(strFileName);                        }                        else                            MessageBox.Show("所选择的文件不是Mxd文档文件!", "信息提示");                        break;                    }                default:                    break;            }        }

记录:

  1. PageLayout是封装在PageLayoutControl中的一个组件类,组件类是可以直接实例化对象的,它提供了在布局视图中控制元素属性的方法
  2. IMap接口主要用于管理Map队形中的layer对象、要素选择集、MapSurroundd对象,标注引擎和空间参考对象。Map对象用来显示数据,Map对象是一个存放layer对象的容器,IMap接口定义了方法来操作Map对象中的图层对象
    这里写图片描述
  3. IActiveView接口定义了Map对象的数据显示功能,PageLayout和Map都实现了该接口,前者为布局视图,后者为数据视图,但在任何一个时刻只有一个保持活跃
    这里写图片描述
  4. WorkSpace及相关对象

函数学习

  • 加载矢量数据:

    1. axMapControl1.AddShapeFile(strPath, strNmae);
      加载矢量数据,直接传入矢量数据的文件路径和文件名
    2. axMapControl2.Extent = axMapControl2.FullExtent;
      在鹰眼图上全图显示
  • 加载栅格数据:
    这里写图片描述

  • 加载地图文档:
    1. axMapControl1.CheckMxFile(strFileName)
      检查地图文档
    2. axMapControl1.LoadMxFile(strFileName);
      加载地图文档
原创粉丝点击