当前位置:网站首页>ArcEngine服务数据加载
ArcEngine服务数据加载
2022-04-22 14:22:00 【ShirmyMao】
ArcEngine服务数据加载
/// <summary>
/// 地图服务
/// </summary>
public static class MapServer
{
/// <summary>
/// 读取WMTS(Web Map Tile Service)服务数据.
/// 缓存技术标准。服务器端把地图切割为一定不同级别大小的瓦片,降低了服务器端的载荷
/// 示例:http://222.240.228.72:8060/arcgis/rest/services/yingxiang2016/MapServer/WMTS/1.0.0/WMTSCapabilities.xml
/// </summary>
/// <param name="url"></param>
/// <param name="layerName"></param>
/// <returns></returns>
public static ILayer ReadWmtsServer(string url, string layerName)
{
IPropertySet propertySet = new PropertySetClass();
propertySet.SetProperty("url", url);
//TODO 属性名称是layerName?
if (layerName != "")
propertySet.SetProperty("layerName", layerName);
IWMTSConnectionFactory wmtsConnectionfactory = new WMTSConnectionFactory();
var con = wmtsConnectionfactory.Open(propertySet, 0, null);
IWMTSLayer wmtsLayer = new WMTSLayer();
var n = con.FullName;
wmtsLayer.Connect(n);
var layer = wmtsLayer as ILayer;
layer.Cached = true;
layer.Name = layerName;
return layer;
}
/// <summary>
/// 读取WMS(WebMapService)服务数据
/// </summary>
/// <param name="url"></param>
/// <param name="layerName"></param>
/// <returns></returns>
public static ILayer ReadWmsServer(string url, string layerName)
{
IPropertySet propertyset = new PropertySetClass();
propertyset.SetProperty("url", url);
IWMSConnectionFactory pWmsFac = new WMSConnectionFactory();
var pWmsC = pWmsFac.Open(propertyset, 0, null);
var pWmsConnectionName = pWmsC.FullName as IWMSConnectionName;
//下面的也可以
//IWMSConnectionName pWmsConnectionName = new WMSConnectionNameClass();
//pWmsConnectionName.ConnectionProperties = pPropertyset;
ILayerFactory pLayerFactory = new EngineWMSMapLayerFactoryClass();
ILayer target = null;
if (pLayerFactory.get_CanCreate(pWmsConnectionName))
{
var pEnumLayer = pLayerFactory.Create(pWmsConnectionName);
pEnumLayer.Reset();
var pLayer = pEnumLayer.Next();
while (pLayer != null)
{
//IWMSMapLayer pWmsMapLayer = pLayer as IWMSMapLayer;
//IWMSGroupLayer pWmsGroupLayer = pWmsMapLayer as IWMSGroupLayer;
//IGroupLayer pGroupLayer = new GroupLayerClass();
//pGroupLayer.Add(pLayer);
if (pLayer is IWMSMapLayer && pLayer.Name == layerName)
{
target = pLayer;
break;
}
pLayer = pEnumLayer.Next();
}
Marshal.ReleaseComObject(pEnumLayer);
}
return target;
}
/// <summary>
/// 读取WCS(Web Coverage Service)服务数据(WCS对应基于栅格数据的功能,与WMS基于矢量数据的特点相对应)
/// </summary>
/// <param name="url"></param>
/// <param name="layerName"></param>
/// <returns></returns>
public static ILayer ReadWcsServer(string url, string layerName)
{
IPropertySet propertyset = new PropertySetClass();
propertyset.SetProperty("url", url);
IWCSConnectionFactory wcsConnectionFactory = new WCSConnectionFactory();
var wcsConnection = wcsConnectionFactory.Open(propertyset, 0, null);
var wcsConnectionName = wcsConnection.FullName as IWCSConnectionName;
//下面的也可以
//IWMSConnectionName pWmsConnectionName = new WMSConnectionNameClass();
//pWmsConnectionName.ConnectionProperties = pPropertyset;
WCSLayerFactory wCSLayerFactory = new WCSLayerFactoryClass();
ILayer target = null;
if (wCSLayerFactory.get_CanCreate(wcsConnectionName))
{
var pEnumLayer = wCSLayerFactory.Create(wcsConnectionName);
pEnumLayer.Reset();
var layer = pEnumLayer.Next();
while (layer != null)
{
if (layer is IWCSLayer && layer.Name == layerName)
{
target= layer;
break;
}
layer = pEnumLayer.Next();
}
}
return target;
}
/// <summary>
/// 获取ArcGISServer服务图层
/// </summary>
/// <param name="hostOrUrl"></param>
/// <param name="serviceName">服务名称</param>
/// <param name="isLAN">是否直连</param>
/// <param name="layerName">图层名称</param>
/// <returns></returns>
public static ILayer ReadMapServer(string hostOrUrl, string serviceName, bool isLAN, string layerName)
{
ILayer target = null;
IMapServer mapServer;
//获得服务对象名称
var pServerObjectName = GetMapServer(hostOrUrl, serviceName, isLAN); //获取地图
var pName = (IName)pServerObjectName;
//访问地图服务
var pServerObject = (IAGSServerObject)pName.Open();
var pMapServer = (IMapServer)pServerObject;
mapServer = pMapServer; //获取地图服务对象
var pMapServerLayer = new MapServerLayer() as IMapServerLayer;
//连接地图服务
pMapServerLayer.ServerConnect(pServerObjectName, pMapServer.DefaultMapName);
//添加数据图层
target = pMapServerLayer as ILayer;
target.Cached = true;
if (!string.IsNullOrEmpty(layerName))
target.Name = layerName;
return target;
}
/// <summary>
/// 读取image server
/// </summary>
/// <param name="url"></param>
/// <param name="layerName"></param>
/// <returns></returns>
public static ILayer ReadImageServer(string url, string layerName)
{
IImageServerLayer imageServerLayer = new ImageServerLayerClass();
imageServerLayer.Initialize(url);
var raster = imageServerLayer.Raster;
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromRaster(raster);
rasterLayer.Name = layerName;
return rasterLayer;
}
/// <summary>
/// 获取ArcGisServer地图服务标识,连接服务器
/// </summary>
/// <param name="pHostOrUrl"></param>
/// 服务器主机URL
/// <param name="pServiceName"></param>
/// 服务名称
/// <param name="pIsLAN"></param>
/// 主机是否是在局域网或者是互联网
/// <returns></returns>
private static IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN)
{
try
{
//设置连接属性
IPropertySet pPropertySet = new PropertySet();
if (pIsLAN)
pPropertySet.SetProperty("machine", pHostOrUrl);
else
pPropertySet.SetProperty("url", pHostOrUrl);
//打开连接
IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory();
//创建服务器连接工作空间
var pConnection = pFactory.Open(pPropertySet, 0);
//打开获取服务器
var pServerObjectNames = pConnection.ServerObjectNames;
//获取服务器上所有服务的标识属性,即服务标识集合
pServerObjectNames.Reset();
//使指针指向服务开头
var ServerObjectName = pServerObjectNames.Next();
//获取服务标识
while (ServerObjectName != null)
{
if (ServerObjectName.Name.ToLower() == pServiceName.ToLower() &&
ServerObjectName.Type == "MapServer")
//判断获取所需服务
break;
ServerObjectName = pServerObjectNames.Next();
}
//返回对象
return ServerObjectName; //返回服务标识
}
catch
{
return null;
}
}
}
版权声明
本文为[ShirmyMao]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_36047595/article/details/124278549
边栏推荐
- 双指针 同向双指针、滑动窗口3、594、|27、26、80、83、82、611、187、643、674、209、438、567、424、76、30
- BitMap BloomFilter BitSet详解
- Apache IoTDB’s UDF源碼分析(1)
- MariaDB is configured as master-slave (dual master mode) to each other
- Live classroom system platform software source code available for personal testing
- Binary Tree练习二叉树遍历递归257、100、222、101、226、437、563、617、572、543、|687
- Blocking queue-
- 华为云媒体査勇:华为云在视频AI转码领域的技术实践
- Spark code spark submit submit submit yarn cluster mode
- 获取数据库中数值时,数据库有值,却为空??
猜你喜欢

深入理解Condition

Activity preview | on April 23, a number of wonderful openmldb sharing came, which lived up to the good time of the weekend!

Brushless DC motor vector control (I): concept and process combing

图的遍历 深度优先DFS 广度优先BFS
26岁,0基础学软件测试还来得及吗

POM in idea Mysql5. XML file 7 coordinate red error

interrupted()和isInterrupted()详述,百万数据分页查询的方法及其优化方式
![[zeekr_tech] Introduction to ros/ros 2](/img/74/471261d2eb9a41d132dae9af323b7c.png)
[zeekr_tech] Introduction to ros/ros 2

链表 环形链表 链表判环 寻找入环节点141、142

Multithreading primary
随机推荐
LeetCode刷题(04)
Methods of safety testing
@Resource与构造函数踩坑
我为什么那么爱用飞项做任务管理
Activity preview | on April 23, a number of wonderful openmldb sharing came, which lived up to the good time of the weekend!
Deep understanding of read-write lock reentrantreadwritelock and concurrent container copyonwritearraylist
Mysql database transferring SQL file
华为云媒体査勇:华为云在视频AI转码领域的技术实践
Figure keys and rooms
Pratique de l'arbre binaire itération récursive de l'arbre binaire 257, 100, 222, 101, 226, 437, 563, 617, 572, 543, | 687
LeetCode_ 63 different paths II
Binarytree练习二叉树层序遍历 || 用队列实现层序遍历
Ibeacon development summary of Internet of things solution based on tailing micro tlsr825x
图的遍历 深度优先DFS 广度优先BFS
2. Flddler response shows the solution to the problem of garbled code
Hashtable hash table practice finding, inserting, deleting 217, 349, 202, 287, 290, 532, 205, 128
Why do I like to use flying items for task management
多线程进阶
Live classroom system platform software source code available for personal testing
LeetCode_63 不同路径 II