原文:动态创建地图文档MXD并发布地图服务

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();
}
}

动态创建地图文档MXD并发布地图服务的更多相关文章

  1. ArcGIS地图文档MXD效率慢的一点建议(二)

    经常有用户询问,我的MXD图层比较多,而且配置好了相关的符号,但是我的服务器更换了一下,而且两个服务器的要素类名称都是一样的,我想配置一下新的数据源,而且我的这个MXD已经连接不到原来的数据源了,打开 ...

  2. ArcGIS发布地图服务

    一般做完矢量图绘制工作后,生成的.mxd文件只能在ArcMap中查看,为了方便用户进行浏览,我们需要发布地图服务. 目前为止最常用的就是在ArcGIS中发布地图服务. 今天也算是在做“发布地图服务”的 ...

  3. 手把手教你怎么用ArcgisOnline发布地图服务

    Arcgis推出了Arcgis Online,但是大家都不知道这是个什么东西,怎么用这个东西,今天这篇文章手把手的教你如何使用Arcgisonline发布地图服务. 一.ArcgisOnline简介 ...

  4. GeoServer自动发布地图服务

    1 NetCDF气象文件自动发布案例 GeoServer是一个地理服务器,提供了管理页面进行服务发布,样式,切片,图层预览等一系列操作,但是手动进行页面配置有时并不满足业务需求,所以GeoServer ...

  5. JavaWeb和WebGIS学习笔记(六)——使用ArcGIS for Server发布地图服务

    系列链接: Java web与web gis学习笔记(一)--Tomcat环境搭建 Java web与web gis学习笔记(二)--百度地图API调用 JavaWeb和WebGIS学习笔记(三)-- ...

  6. 利用 PortableBasemapServer 发布地图服务

    前段时间需要给自己的C/S系统加一个地图,但是没有数据,于是就想到了使用网上的切片地图,但是C/S系统又不能联网,于是就想本地发布切片服务来使用. 本来想用ArcGIS Server来发布从网上下载的 ...

  7. geoserver 通过代码实现发布地图服务

    GeoServer:代码实现批量发布地图服务 利用GeoServer发布WCS服务,那么如果我有很多数据需要进行发布,这样利用GeoServer提供的UI界面进行操作显然很不显示.那能不能利用GeoS ...

  8. ArcGIS Server 10.1安装、配置、发布地图服务

    先跟大家分享一个esri的学习资料,http://pan.baidu.com/s/1nBzxB,<ArcGIS10.1 for Server 入门教程>.教程讲述的很清楚,下面说说我这次发 ...

  9. arcgis server10.2发布地图服务报错

    发布地图服务时,读取了本机电脑中的切片方案.发布服务,报打包成功,但发布失败错误. 解决办法:给arcgis账户,赋予读写权限即可.重复发布服务,成功发布.

随机推荐

  1. BZOJ3482 : [COCI2013]hiperprostor

    对于每组询问,spfa求出f[i][j]表示从S出发,经过j条x边到达i的最短路. 若f[T][i]都为inf,则无解. 若f[T][0]为inf,则有无穷个解. 否则可以看作若干条直线,$O(n)$ ...

  2. POJ 1155 (树形DP+背包+优化)

    题目链接: http://poj.org/problem?id=1155 题目大意:电视台转播节目.对于每个根,其子结点可能是用户,也可能是中转站.但是用户肯定是叶子结点.传到中转站或是用户都要花钱, ...

  3. TYVJ P1022 进制转换 Label:坑

    背景 太原成成中学第3次模拟赛 第2道 描述 对于十进制整数N,试求其-2进制表示.例如,因为 1*1 + 1*-2 + 1*4 + 0*-8 +1*16 + 1*-32 = -13 ,所以(-13) ...

  4. 【BZOJ】1606: [Usaco2008 Dec]Hay For Sale(背包)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1606 越来越水了T_T 这题两种做法,一个正规01背包,价值就是体积 还有一种是非正规背包,即 if ...

  5. 修改CSV中的某些值 -- 2

    C:\aaa.csv "IPAddress","FullDomainName","RequestedTargetGroupName" &qu ...

  6. Android基础知识

    一.四大组件 Activity(活动).Service(服务).BroadcastReceiver(广播器).Content Provider(内容提供器) 二.五大布局 LinearLayout(线 ...

  7. context:component-scan 分析

    <context:component-scan> Web.xml中 <servlet> <servlet-name>springMVC</servlet-na ...

  8. Nginx 笔记与总结(1)编译安装

    Nginx 可以承受 3 万并发连接数,Apache 默认最大连接数是 256 个. 编译安装 ① 下载 在 Nginx 的主页 http://nginx.org/ 下载最新的 stable vers ...

  9. PHP 开发 APP 接口 学习笔记与总结 - Redis 缓存

    Redis 可以定期将数据备份到磁盘中(持久化),同时不仅仅支持简单的key/value 类型的数据,同时还提供list,set,hash等数据结构的存储:Memcache 只是简单的key/valu ...

  10. GitHub超详细图文攻略

    GitHub超详细图文攻略 - Git客户端下载安装 GitHub提交修改源码工作流程 Git 分类: 转载2014-03-25 21:10 10641人阅读 评论(2) 收藏 举报 GitHubbr ...