博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
动态创建地图文档MXD并发布地图服务
阅读量:6155 次
发布时间:2019-06-21

本文共 7984 字,大约阅读时间需要 26 分钟。

原文:

 1、动态创建MXD

private bool CreateMxd(string MxdPath, string MxdName)      {          IMapDocument pMapDocument = CreateObject("esriCarto.MapDocument") as IMapDocument;          if (MxdPath.Substring(MxdPath.Length - 1) != @"\")              MxdPath += @"\";          pMapDocument.New(MxdPath + MxdName + ".mxd");          AddLayerToMxd(pMapDocument, MxdName);          if (pMapDocument == null)              return false;          if (pMapDocument.get_IsReadOnly(MxdPath + MxdName + ".mxd") == true)          {              return false;          }          pMapDocument.Save(true, false);          return true;      }

2、动态创建地图服务

private bool CreateServices(string MapPath, string ServerName)      {          //IGISServerConnection pGISServerConnection;          //pGISServerConnection = new GISServerConnectionClass();          //pGISServerConnection.Connect(HostName);          ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity(MapServerUserName, MapserverPass, "");          ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(HostName, identity);          agsConnection.Connect();          IServerObjectAdmin pServerObjectAdmin;          pServerObjectAdmin = agsConnection.ServerObjectAdmin;          IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();          configuration.Name = ServerName;//发布Service的名称,必填          configuration.TypeName = "MapServer";//发布服务的类型,如:MapServer,GeocodeServer          IPropertySet props = configuration.Properties;          props.SetProperty("FilePath", MapPath);//设置MXD的路径          #region 一下的property并非必须,只要一个filepath就可以发布          props.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");//图片的输出目录          props.SetProperty("VirtualOutPutDir", "http://" + HostName + "/arcgisoutput");//图片输出的虚拟路径          props.SetProperty("SupportedImageReturnTypes", "URL");//支持的图片类型          props.SetProperty("MaxImageHeight", "2048");//图片的最大高度          props.SetProperty("MaxRecordCount", "500");//返回记录的最大条数          props.SetProperty("MaxBufferCount", "100");//缓冲区分析的最大数目          props.SetProperty("MaxImageWidth", "2048");//图片的最大宽度          props.SetProperty("IsCached", "false");//是否切片          props.SetProperty("CacheOnDemand", "false");//是否主动切片          props.SetProperty("IgnoreCache", "false");//是否忽略切片          props.SetProperty("ClientCachingAllowed", "true");//是否允许客户端缓冲          props.SetProperty("CacheDir", "c:\\arcgisserver\\arcgiscache\\NewService");//切片的输出路径          props.SetProperty("SOMCacheDir", "c:\\arcgisserver\\arcgiscache");//som的切片输出路径            //configuration.Description = "NewService";//Service的描述          configuration.IsolationLevel = esriServerIsolationLevel.esriServerIsolationHigh;//或者esriServerIsolationLow,esriServerIsolationAny          configuration.IsPooled = true;//是否池化          configuration.MaxInstances = 2;//最多的实例数          configuration.MinInstances = 1;//最少的实例数            设置刷新          IPropertySet recycleProp = configuration.RecycleProperties;          recycleProp.SetProperty("StartTime", "00:00");//刷新开始时间          recycleProp.SetProperty("Interval", "3600");//刷新间隔            设置是否开启REST服务          IPropertySet infoProp = configuration.Info;          infoProp.SetProperty("WebEnabled", "true");//是否提供REST服务          infoProp.SetProperty("WebCapabilities", "Map,Query,Data");//提供何种服务            //configuration.StartupType = esriStartupType.esriSTAutomatic;//或者esriSTManual          //configuration.UsageTimeout = 120;//客户端占用一个服务的最长时间          //configuration.WaitTimeout = 120;//客户端申请一个服务的最长等待时间          #endregion            //添加服务到Server          pServerObjectAdmin.AddConfiguration(configuration);            //启动服务          pServerObjectAdmin.StartConfiguration(ServerName, "MapServer");          return true;        }

3. 动态创建影像服务

private bool CreateServices(string ImagePath, string ServerName)    {         ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity(MapServerUserName, MapserverPass, "");        ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(HostName, identity);        agsConnection.Connect();        IServerObjectAdmin pServerObjectAdmin;        pServerObjectAdmin = agsConnection.ServerObjectAdmin;        IServerObjectConfiguration2 configuration = (IServerObjectConfiguration2)pServerObjectAdmin.CreateConfiguration();        configuration.Name = ServerName;//发布Service的名称,必填        configuration.TypeName = "ImageServer";//发布服务的类型,如:MapServer,GeocodeServer        IPropertySet propertySet = configuration.Properties;        propertySet.SetProperty("Path", ImagePath);//设置Image的路径        propertySet.SetProperty("Start", "00:00");        propertySet.SetProperty("Interval", "24");        propertySet.SetProperty("SupportedImageReturnTypes", "URL");	propertySet.SetProperty("OutputDir", "c:\\arcgisserver\\arcgisoutput");//图片的输出目录	propertySet.SetProperty("VirtualOutPutDir", "http://" + HostName + "/arcgisoutput");//图片输出的虚拟路径        //propertySet.SetProperty("MaxImageHeight", 4100);//4100       // propertySet.SetProperty("MaxImageWidth", 15000);//15000        //propertySet.SetProperty("AllowedCompressions", "None,JPEG,LZ77");//"None,JPEG,LZ77"        //propertySet.SetProperty("DefaultResamplingMethod", 0);//0        //propertySet.SetProperty("DefaultCompressionQuality", 75);//75        //propertySet.SetProperty("MaxRecordCount", 500);//500        //propertySet.SetProperty("MaxMosaicImageCount", 1);//20        //propertySet.SetProperty("MaxDownloadImageCount", 20);//20        //propertySet.SetProperty("AllowedFields","Name,MinPS,MaxPS,LowPS,HighPS,CenterX,CenterY");//"Name,MinPS,MaxPS,LowPS,HighPS,CenterX,CenterY"        //propertySet.SetProperty("AllowedMosaicMethods","Center,NorthWest,LockRaster,ByAttribute,Nadir,Viewpoint,Seamline");//"Center,NorthWest,LockRaster,ByAttribute,Nadir,Viewpoint,Seamline"        //propertySet.SetProperty("AllowedItemMetadata", "Full");//"Full"        //ImageServiceInfo pImageSerivce = new ImageServiceInfo();        configuration.StartupType = esriStartupType.esriSTAutomatic;        configuration.MinInstances = 1;        configuration.MaxInstances = 2;	configuration.IsPooled = true;        configuration.Info.SetProperty("WebEnabled", "true");        configuration.Info.SetProperty("WebCapabilities", "Image,Catalog,Metadata,Download,Pixels");        pServerObjectAdmin.AddConfiguration(configuration);        //启动服务        pServerObjectAdmin.StartConfiguration(ServerName, "ImageServer");        return true;    }

3、相关方法

private IServerContext CreateServerContext(string ServerName, string UserName, string PassWord)      {          ESRI.ArcGIS.ADF.Identity identity = new ESRI.ArcGIS.ADF.Identity(UserName, PassWord, "");          ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection agsConnection = new ESRI.ArcGIS.ADF.Connection.AGS.AGSServerConnection(ServerName, identity);          agsConnection.Connect();          if (agsConnection.IsConnected)          {              try              {                  IServerObjectManager som = agsConnection.ServerObjectManager;                  IServerContext pServerContext = som.CreateServerContext("Geometry", "GeometryServer");                  return pServerContext;              }              catch (Exception e)              {                  return null;              }          }          return null;      }       #region  ServerContext CreateObject函数      private object CreateObject(string ObjectCLSID)      {          IServerContext pServerContext = CreateServerContext(HostName,MapServerUserName,MapserverPass);          if (pServerContext == null) return null;          try          {              return pServerContext.CreateObject(ObjectCLSID);          }          catch          {              return null;          }          finally          {              pServerContext.ReleaseContext();          }      }

转载地址:http://ejbfa.baihongyu.com/

你可能感兴趣的文章
利用FIFO进行文件拷贝一例
查看>>
Ecshop安装过程中的的问题:cls_image::gd_version()和不支持JPEG
查看>>
resmgr:cpu quantum等待事件
查看>>
一个屌丝程序猿的人生(六十六)
查看>>
Java 编码 UTF-8
查看>>
SpringMVC实战(注解)
查看>>
关于静态属性和静态函数
查看>>
进程的基本属性:进程ID、父进程ID、进程组ID、会话和控制终端
查看>>
spring+jotm+ibatis+mysql实现JTA分布式事务
查看>>
MyBatis启动:MapperStatement创建
查看>>
调查问卷相关
查看>>
eclipse启动无响应,老是加载不了revert resources,或停留在Loading workbench状态
查看>>
1. Git-2.12.0-64-bit .exe下载
查看>>
怎样关闭“粘滞键”?
查看>>
[转]React 教程
查看>>
拓扑排序介绍
查看>>
eclipse打开工作空间(workspace)没有任务反应
查看>>
使用Sybmol模块来构建神经网络
查看>>
字符串去分割符号
查看>>
WPF中,多key值绑定问题,一个key绑定一个界面上的对象
查看>>