南京价格网站建设,软件开发需求分析模板,做企业网站需要买什么,燕郊seoServer操作Mxd文件详细讲解Server发布地图都是基于Mxd去发布的#xff0c;这点与IMS使用axl文件差不多。一般来说#xff0c;发布后mxd尽可能不要修改#xff0c;或者在通过使用arcMap进行编辑后在重新发布。修改mxd会导致地图服务发生变化#xff0c;因此#xff0c;相对…Server操作Mxd文件详细讲解Server发布地图都是基于Mxd去发布的这点与IMS使用axl文件差不多。一般来说发布后mxd尽可能不要修改或者在通过使用arcMap进行编辑后在重新发布。修改mxd会导致地图服务发生变化因此相对来说是一种危险的操作。但有时客户需要对Mxd进行修改自定义的添加修改图层并重新发布服务。当然这些苛刻的需求server同样可以应付但懒羊羊还是不建议这样做。方法总是有的越危险的事也就越有趣。懒羊羊还是跟大家分享一下这方面的心得吧。下面函数实现添加一个图层到mxd文件并设置样式。为更好的表达函数使用返回操作结果的字符串。/// summary /// 添加图层到Mxd文件 /// /summary /// param nameserverContextIServerContext/param /// param namenfc新图层对应的要素集/param /// param namegroupIndex复合图层的序号/param /// param namemxdPathmxd所在的路径/param /// param namepicPath用于对图层渲染的图片/param /// returns/returns public string addLayerInMxd(IServerContext serverContext, IFeatureClass nfc, int groupIndex, string mxdPath,string picPath) { IMapServer pMapServer serverContext.ServerObject as IMapServer; IMapServerObjects pMapServerObjs pMapServer as IMapServerObjects; IMap pMap pMapServerObjs.get_Map(pMapServer.DefaultMapName); bool hasLayer hasTheLayer(pMap, nfc.AliasName); if (hasLayer) return 已存在该命名图层,操作未能完成; //如果图层已经存在了那就不添加 if (groupIndex pMap.LayerCount) return 组合图层序号越界,操作未能完成; IMapLayers mapLayer pMap as IMapLayers; IGroupLayer gLayer pMap.get_Layer(groupIndex) as IGroupLayer; IFeatureLayer fl serverContext.CreateObject(esriCarto.FeatureLayer) as IFeatureLayer; fl.FeatureClass nfc; fl.Name nfc.AliasName; //设置样式 ISimpleRenderer pRen serverContext.CreateObject(esriCarto.SimpleRenderer) as ISimpleRenderer; IGeoFeatureLayer pGeoLayer fl as IGeoFeatureLayer; IPictureMarkerSymbol picMark serverContext.CreateObject(esriDisplay.PictureMarkerSymbol) as IPictureMarkerSymbol; picMark.Size 20; picMark.CreateMarkerSymbolFromFile(esriIPictureType.esriIPictureBitmap, picPath); pRen.Symbol (ISymbol)picMark; pGeoLayer.Renderer (IFeatureRenderer)pRen; mapLayer.InsertLayerInGroup(gLayer, pGeoLayer as ILayer, false, 3); //获取pMapDocument对象 IMxdContents pMxdC; 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 namepMap/param /// param namelayerName/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; }下面是根据图层名删除图层的操作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 namepMap/param /// param namelayerName/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;当然通过代码对服务器文件进行读写还必须要注意网络的安全设置。首先要确保有足够的权限对Mxd进行修改。懒羊羊要指出所谓的权限第一是确保你的Server具有足够的授权。第二服务器文件必须有足够的写入权限。对于第二点主要是考虑磁盘格式。网络开发人员都知道NTFS格式下面要访问文件必须设置安全属性。设置方法如下。1。在服务器Mxd文件右键属性--点击安全标签2.查找soc用户3.给soc用户写入的权限。懒羊羊这里只是举个例子看官们只管使用自己的soc用户就行了。 下载 (35.63 KB)2008-10-22 20:29 下载 (34.97 KB)2008-10-22 20:29 下载 (36.99 KB)2008-10-22 20:29如果是fat格式就不用上述设置毕竟NTFS格式安全系数比较高。至于Linux懒羊羊没有做过尝试过的朋友可以发表一下心得体会。还有一点必须主要的Mxd更改以后地图服务是没有发生变化的所发布的地图一直驻留在内存中。因此这时候需要更新一下地图服务。方法有很多最傻瓜最直接的方法就是跑到机房去重启mxd所对应的service。但是懒羊羊比较懒所以还是希望通过代码去控制update一下。下面是更新地图服务的函数private void updateService(string serviceName,string serverName) { ServerConnection pServerConnection new ESRI.ArcGIS.Server.WebControls.ServerConnection(serverName);//地图服务机器名 pServerConnection.Connect(); IServerObjectAdmin pServerSOA pServerConnection.ServerObjectAdmin; IServerObjectConfiguration pConfig pServerSOA.GetConfiguration(serviceName, MapServer); pServerSOA.UpdateConfiguration(pConfig); }细心的朋友应该注意到了这里面主要是使用了IServerObjectAdmin 接口IServerObjectAdmin 接口功能十分强大建议去查一下帮助对其加深了解。 下载 (35.46 KB)2008-10-22 20:42 下载 (155.91 KB)2008-10-22 20:42 描述RemarksAny application that runs as a user account in the agsadmin user group on the ArcGIS Server can use the IGISServerConnection interface to connect to the ArcGIS Server and to get a reference to the ServerObjectAdmin. If the user account is not part of the agsadmin user group the ServerObjectAdmin property on IServerConnection will return an error. Applications that are running as accounts that can connect to the server but are not part of the agsadmin user group can use the ServerObjectManager property on IGISServerConnection to get a reference on the ServerObjectManager. The IServerObjectAdmin interface has the necessary methods for an application to adminstrate both the set of server object configurations and types associated with the server, and to administer aspects of the server itself. The following administration functionality of the ArcGIS Server is exposed by methods and properties on IServerObjectAdmin :Adminster server object configurations: Add and delete server object configurationsUpdate a server object configurations propertiesStart, stop and pause server object configurationsReport the status of a server object configurationGet all server object configurations and their propertiesGet all server object types and their propertiesAdminister aspects of the server itself: Add and remove server container machinesGet all server container machinesAdd and remove server directoriesGet all server directoriesConfigure the servers logging properties实际上上述的操大多数都是常规的操作AE程序员都能轻松搞定。但细微的地方还是要注意的例如Server环境下创建新对象文件的权限设置等等对server的一些特性也必须了解。例如mxd更新以后必须重启服务确保当前服务与地图文档一致不然就可能导致灾难性的出错。前面漏掉的一个函数现在补上/// summary /// 通过图层名称返回图层 /// /summary /// param namepSOC地图控件/param /// param nameLayerName图层名称/param /// returns/returns public static ILayer getLayerByName(IServerContext pSOC, string LayerName) { IMapServer pMapServer pSOC.ServerObject as IMapServer; IMapServerObjects pMapServerObjs pMapServer as IMapServerObjects; IMap pMap pMapServerObjs.get_Map(pMapServer.DefaultMapName); //获取所有的图层 for (int i 0; i pMap.LayerCount; i) { ILayer lyr pMap.get_Layer(i); if (lyr.Name LayerName) { return lyr; } else if (lyr is ICompositeLayer) { //图层为复合图层查找其子图层 ICompositeLayer comLayer lyr as ICompositeLayer; for (int j 0; j comLayer.Count; j) { ILayer cLayer comLayer.get_Layer(j); if (cLayer.Name layerName) return cLayer; } } } return null; }转载于:https://www.cnblogs.com/liuyang-1037/archive/2009/08/11/1543481.html