动态创建地图文档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并发布地图服务的更多相关文章
- ArcGIS地图文档MXD效率慢的一点建议(二)
经常有用户询问,我的MXD图层比较多,而且配置好了相关的符号,但是我的服务器更换了一下,而且两个服务器的要素类名称都是一样的,我想配置一下新的数据源,而且我的这个MXD已经连接不到原来的数据源了,打开 ...
- ArcGIS发布地图服务
一般做完矢量图绘制工作后,生成的.mxd文件只能在ArcMap中查看,为了方便用户进行浏览,我们需要发布地图服务. 目前为止最常用的就是在ArcGIS中发布地图服务. 今天也算是在做“发布地图服务”的 ...
- 手把手教你怎么用ArcgisOnline发布地图服务
Arcgis推出了Arcgis Online,但是大家都不知道这是个什么东西,怎么用这个东西,今天这篇文章手把手的教你如何使用Arcgisonline发布地图服务. 一.ArcgisOnline简介 ...
- GeoServer自动发布地图服务
1 NetCDF气象文件自动发布案例 GeoServer是一个地理服务器,提供了管理页面进行服务发布,样式,切片,图层预览等一系列操作,但是手动进行页面配置有时并不满足业务需求,所以GeoServer ...
- JavaWeb和WebGIS学习笔记(六)——使用ArcGIS for Server发布地图服务
系列链接: Java web与web gis学习笔记(一)--Tomcat环境搭建 Java web与web gis学习笔记(二)--百度地图API调用 JavaWeb和WebGIS学习笔记(三)-- ...
- 利用 PortableBasemapServer 发布地图服务
前段时间需要给自己的C/S系统加一个地图,但是没有数据,于是就想到了使用网上的切片地图,但是C/S系统又不能联网,于是就想本地发布切片服务来使用. 本来想用ArcGIS Server来发布从网上下载的 ...
- geoserver 通过代码实现发布地图服务
GeoServer:代码实现批量发布地图服务 利用GeoServer发布WCS服务,那么如果我有很多数据需要进行发布,这样利用GeoServer提供的UI界面进行操作显然很不显示.那能不能利用GeoS ...
- ArcGIS Server 10.1安装、配置、发布地图服务
先跟大家分享一个esri的学习资料,http://pan.baidu.com/s/1nBzxB,<ArcGIS10.1 for Server 入门教程>.教程讲述的很清楚,下面说说我这次发 ...
- arcgis server10.2发布地图服务报错
发布地图服务时,读取了本机电脑中的切片方案.发布服务,报打包成功,但发布失败错误. 解决办法:给arcgis账户,赋予读写权限即可.重复发布服务,成功发布.
随机推荐
- 我理解的 js 的观察者模式 Observable
我第一次看 四人帮 写的<设计模式>时一头雾水,现在也是,或许其是针对专业的程序员学习使用的. 通过对Ext / Backbone 源码的学习,可总结如下: 模式 - 就是对解决某一类特定 ...
- SQL server 表中如何创建索引?
SQL server 表中如何创建索引?看个示例,你就会了 use master goif db_id(N'zhangxu')is not nulldrop database zhangxugocre ...
- mysql insert插入新形式,再也不需要拼接多重insert啦
注意一下,不能省略表中的任何字段.包括自增id.而且字段的顺序必须和插入表一致 原理是“表插表” INSERT INTO prod_attr select A.* from ( SELECT AS p ...
- [转]C#基础回顾:Asp.net 缓存
本文转自http://www.cnblogs.com/stg609/archive/2009/03/22/1418992.html 缓存的作用 你买电脑的时候,是否会在意CPU的二级缓存?是 ...
- java--测体重练习
public class tz{ public static void main(String[] args){ int sg=165,tz=52;bz = sg-115 if (tz-bz>3 ...
- 《GK101任意波发生器》升级固件发布(版本:1.0.2build690)
一.固件说明: 硬件版本:0,logic.3 固件版本:1.0.2.build690 编译日期:2015年4月24日 ====================================== 二. ...
- shopnc2014年11版数据库字典
shopnc_activity 表注释: 活动表 字段 类型 空 默认 注释 activity_id mediumint(9) 否 id activity_title varchar(255) 否 ...
- HRBUST 1430 矩阵快速幂
没错就是这道模板题我做了一个小时...我居然在看第一眼就认为是快速幂的情况下强行找了一发瞬时求出的规律 每个阶段有黑白两种 a[i].black=a[i-1].black*3+a[i].white ...
- C#安全API
Bouncycastle库C#版 官网地址为:http://www.bouncycastle.org/csharp/. http://blog.csdn.net/popozhu/article/det ...
- coreDate 简化版
建表: 自动生成: 代码: // // RootViewController.m // coreDate 简化版 #import "RootViewController.h" #i ...