原文:动态创建地图文档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. LA 4080 (多源最短路径+边修改+最短路径树)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=32266 题目大意:①先求任意两点间的最短路径累加和,其中不连通的边 ...

  2. javascript为元素绑定事件响应函数

    javascript中为元素设置响应时间有两种方法. (1):object.onclick=functionName; 这种方法不可以传递参数. (2):object.onclick=function ...

  3. 【BZOJ】1818: [Cqoi2010]内部白点(树状数组+离散+特殊的技巧)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1818 这一题一开始我就看错了,bzoj的那个绝对值109简直坑人,应该是10^9,我直接写了个暴力. ...

  4. maven工程代码关联源代码配置

    最近在学习dubbo,在maven构建完成后,需要关联查看一些依赖jar的源码,配置很简单,如下: 勾选windows-Preferences-Maven- Download Artifact Sou ...

  5. 我装GitHub的过程

    GitHub是老师推荐的没正真的使用过,这次安装也是按提示的,不知对否,且还没使用,只是记录一下自己的过程.我是在线安装的. 1.下载GitHub安装问价,双击开始安装 2.出现的可能是系统相关配置吧 ...

  6. jQuery组件系列:封装标签页(Tabs)

    我自己封装的组件,你也行,静态链接地址 http://www.cnblogs.com/leee/p/5190489.html 声明.最好,先把代码拷过去运行一下,其实特别丑~再往下看 我没优化,因为我 ...

  7. c3p0配置 initialPoolSize 和minPoolSize 可以设为0吗?设0有坏处吗?

    c3p0配置 initialPoolSize 和minPoolSize 可以设为0吗?设0有坏处吗? c3p0配置 initialPoolSize 和minPoolSize 可以设为0吗?设0有坏处吗 ...

  8. 关于Shader的跨平台方案的考虑

      Apple 推出 metal后,除了新的metal framewrok外,也多了一种新的shader语言,最近工作也做了一些metal移植的测试,主要还是现有引擎如何可以快速支持metal的解决方 ...

  9. 状态模式 java && php

    状态模式 java && php     状态模式 输入信号是事件:输出是状态结果,状态模式状态机就是一个黑盒子.状态模式主要突出了两个字:”改变”,对象的状态决定了状态的行为,事物的 ...

  10. memcached学习笔记1--概念

    1.memcached是danga的一个项目,最早是LiveJournal服务的,最初为了加速LiveJournal访问速度而开发,后来被很多大型网站采用 官网: http://www.danga.c ...