• ArcGIS Runtime SDK for iOS中获取ImageServiceLayer的栅格值



    本文原创,转载请注明原创地址 http://blog.csdn.net/dongyu1009/article/details/37697389


            用AGSImageServiceIdentifyTask能够获取ArcGISImageServiceLayer图层中的栅格值。这涉及了三个比較重要的类:AGSImageServiceIdentifyParameters、AGSImageServiceIdentifyTask和AGSImageServiceIdentifyResult,另一个delegate代理类。以下一一简单介绍一下:


    AGSImageServiceIdentifyParameters

    AGSImageServiceIdentifyParameters是用来设置identify參数的。能够用类方法imageServiceIdentifyParameters构造,即

    [AGSImageServiceIdentifyParameters AGSImageServiceIdentifyParameters];

    AGSImageServiceIdentifyParameters共包含以下几个属性

    ---geometry用于指定查询栅格的位置。经常是一个AGSPoint,也能够用AGSPolygon来查询一个区域的栅格值。

    ---mosaicRule是镶嵌规则。默觉得AGSMosaicMethodCenter。

    ---pixelSizeX和pixelSizeY用来设置象元大小,默觉得被查询栅格图层的象元大小。在象元大小范围内的全部镶嵌数据集都会被查询到。


    AGSImageServiceIdentifyTask

    实例化的时候须要设置查询的URL,假设须要验证的话须要设置credential

    其它的没什么可介绍的,在查询的之前已经要为查询设置代理,查询的时候用- (NSOperation*) identifyWithParameters:(AGSImageServiceIdentifyParameters *)      identifyParams方法。

     

    AGSImageServiceIdentifyResult


    catelogItems是返回的栅格文件夹(我也不知道怎么翻译啦,一个Raster Catelog是Raster Dataset栅格数据集的集合)。

    catalogItemVisibilities顾名思义,栅格文件夹是否可见

    location就是identify的查询位置

    name就是identify查询的属性名称

    objectId不解释了。就是一个id

    properties是一个属性的集合

    value就是name相应属性的象元值


    AGSImageServiceIdentifyDelegate

    代理是用来获得查询结果用的。必须实现以下两个方法,第一个是identify查询失败的时候调用的,第二个是identify查询成功调用的,会获得一个AGSImageServiceIdentifyResult对象。

    (void)     - imageServiceIdentifyTask:operation:didFailToIdentifyWithError:

    (void)     - imageServiceIdentifyTask:operation:didIdentifyWithResult:


    以下是详细的用法。

    1、为ViewController设置代理,并实现查询完毕的两个方法:

    在ViewController.h中

    #import <UIKit/UIKit.h>
    #define IMAGE_SERVICE "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/World/MODIS/ImageServer"</p>
    
    @interface ViewController : UIViewController <AGSImageServiceIdentifyDelegate>
    
    @property (strong, nonatomic) AGSImageServiceIdentifyTask *task;
    
    @end

    在ViewController.m中

    - (void)imageServiceIdentifyTask:(AGSImageServiceIdentifyTask*)identifyTask operation:(NSOperation*)op didIdentifyWithResult:(AGSImageServiceIdentifyResult *)result{
        NSLog(@"properties :%@", result.properties);
        NSLog(@"value :%@", result.value);
        NSLog(@"name : %@", result.name);
        NSLog(@"catalogItems count :%d", [[result.catalogItems features] count]);
    }
    
    - (void)imageServiceIdentifyTask:(AGSImageServiceIdentifyTask*)identifyTask operation:(NSOperation*)op didFailToIdentifyWithError:(NSError *)error{
        NSLog(@"fault");
    }


    2、设置AGSImageServiceIdentifyTask:

        self.task = [[AGSImageServiceIdentifyTask alloc] initWithURL:[NSURL URLWithString:IMAGE_SERVICE]];
        self.task.delegate = self;
    
    


    3、设置AGSImageServiceIdentifyParameters:

        
        AGSImageServiceIdentifyParameters *param = [AGSImageServiceIdentifyParameters imageServiceIdentifyParameters];
        
        param.geometry = [AGSPoint pointWithX:116.425541 y:39.969147 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];
        
        [self.task identifyWithParameters:param];


    完整的代码例如以下:

    ViewController.h中

    //  ViewController.h
    //  Wang
    //
    //  Created by dongyu on 14-7-10.
    //  Copyright (c) 2014年 org.reach. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface ViewController : UIViewController <AGSImageServiceIdentifyDelegate>
    
    @property (strong, nonatomic) AGSImageServiceIdentifyTask *task;
    
    @end

    在ViewController.m中

    //  ViewController.m
    //  Wang
    //
    //  Created by dongyu on 14-7-10.
    //  Copyright (c) 2014年 org.reach. All rights reserved.
    //
    
    #import "ViewController.h"
    #define IMAGE_SERVICE @"http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/World/MODIS/ImageServer"
    
    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        self.task = [[AGSImageServiceIdentifyTask alloc] initWithURL:[NSURL URLWithString:IMAGE_SERVICE]];
        self.task.delegate = self;
        
        AGSImageServiceIdentifyParameters *param = [AGSImageServiceIdentifyParameters imageServiceIdentifyParameters];
        
        param.geometry = [AGSPoint pointWithX:116.425541 y:39.969147 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];
        
        [self.task identifyWithParameters:param];
        
    }
    
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    #pragma mark - delegate
    - (void)imageServiceIdentifyTask:(AGSImageServiceIdentifyTask*)identifyTask operation:(NSOperation*)op didIdentifyWithResult:(AGSImageServiceIdentifyResult *)result{
        NSLog(@"properties :%@", result.properties);
        NSLog(@"value :%@", result.value);
        NSLog(@"name : %@", result.name);
        NSLog(@"catalogItems count :%d", [[result.catalogItems features] count]);
    }
    
    - (void)imageServiceIdentifyTask:(AGSImageServiceIdentifyTask*)identifyTask operation:(NSOperation*)op didFailToIdentifyWithError:(NSError *)error{
        NSLog(@"fault");
    }
    
    @end



    demo的下载地址:

    http://download.csdn.net/detail/dongyu1009/7623695


    新手发博文,有不好的地方,望大家批评指正。


  • 相关阅读:
    无题..
    让Windows 2003 Server支持ASP程序
    下雪
    比较经典的.NET基础
    XML几种操作
    某年某月有几天
    .NET操作Word(傻瓜型)
    XML 简单操作
    一首歌
    ASP.NET:掌握Web窗体的生命周期与状态管理(摘自网络)
  • 原文地址:https://www.cnblogs.com/tlnshuju/p/7016169.html
Copyright © 2020-2023  润新知