IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发测试 -> ArcEngine服务数据加载 -> 正文阅读

[开发测试]ArcEngine服务数据加载

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;
        }
    }
}
  开发测试 最新文章
pytest系列——allure之生成测试报告(Wind
某大厂软件测试岗一面笔试题+二面问答题面试
iperf 学习笔记
关于Python中使用selenium八大定位方法
【软件测试】为什么提升不了?8年测试总结再
软件测试复习
PHP笔记-Smarty模板引擎的使用
C++Test使用入门
【Java】单元测试
Net core 3.x 获取客户端地址
上一篇文章      下一篇文章      查看所有文章
加:2022-04-22 19:07:17  更:2022-04-22 19:08:12 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 10:36:12-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码