http://www.gissky.net- GIS空间站

我要投稿 投稿指南 RSS订阅 网站资讯通告:
搜索: 您现在的位置: GIS空间站 >> 技术专栏 >> ArcGIS >> ArcGIS Server >> 正文

ArcGIS Server操作Mxd文件详细讲解

作者:liyuanxi…    文章来源:liyuanxiang    点击数:    更新时间:2009-6-20
摘要:

 

下面是根据图层名删除图层的操作
public string removeLayerFromMxd(IServerContext serverContext, layerName,string mxdPath)
        {
            IMapServer pMapServer = serverContext.ServerObject as IMapServer;
            IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;
            IMap pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);
            IMapLayers pMapLayers = pMap as IMapLayers;
            
            ILayer removeLayer = getLayerByName(serverContext, layerName);
            if (removeLayer == null)
                return "操作失败,找不到要删除的图层";
            pMapLayers.DeleteLayer(removeLayer);
            //获取pMapDocument对象
            IMxdContents pMxdC = pMap as IMxdContents; ;
            IMapDocument pMapDocument = serverContext.CreateObject("esriCarto.MapDocument") as IMapDocument;
            pMapDocument.Open(mxdPath, "");
            pMapDocument.ReplaceContents(pMxdC);
            if (pMapDocument == null) return "操作失败,地图文档为空";
            //检查地图文档是否是只读
            if (pMapDocument.get_IsReadOnly(mxdPath) == true)
            {
                return "操作失败,地图文档只读";
            }
            //根据相对的路径保存地图文档
            pMapDocument.Save(pMapDocument.UsesRelativePaths, false);
            return "操作成功";
        }

/// <summary>
        /// 是否存在layerName为别名的图层
        /// </summary>
        /// <param name="pMap"></param>
        /// <param name="layerName"></param>
        /// <returns></returns>
        public bool hasTheLayer(IMap pMap, string layerName)
        {
            for (int i = 0; i < pMap.LayerCount; i++)
            {
                ILayer pLayer = pMap.get_Layer(i);
                if (pLayer.Name == layerName)
                    return true;
                if (pLayer is ICompositeLayer)
                {
                    ICompositeLayer comLayer = pLayer as ICompositeLayer;
                    for (int j = 0; j < comLayer.Count; j++)
                    {
                        ILayer cLayer = comLayer.get_Layer(j);
                        if (cLayer.Name == layerName)
                            return true;
                    }
                }
            }
            return false;
        }


从上面的函数可看出,对添加删除图层这些操作,步骤大概就是 获取图层对要素集,设置图层样式,打开当前地图,插入图层,保存Mxd,
所有的这些都是AO的操作,对于习惯使用AE的人来说,这些都很熟悉,唯一不同的是,Server不能用new去创建对象,细心人会发现在创建
地图文档的时候,使用的是CreateObject的方式,如下面语句
IMapDocument pMapDocument = serverContext.CreateObject("esriCarto.MapDocument") as IMapDocument;

上一页  [1] [2] [3] [4] [5] 下一页

Tags:ArcGIS Server,Mxd  
责任编辑:gissky
关于我们 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 中国地图