ArcGIS Runtime SDK for iOS(六) --- 空间几何分析与操作(中)

2016.4.18 武汉 阴晴
by SevenJohs.

  • 概述
    实现缓冲区以及剪切操作。
  • 内容:
    • 缓冲区buffer
    • 剪切cut

缓冲区[buffer]: -
续上节内容,缓冲区分析是GIS的基本空间操作功能之一,是指在点、线、面实体的周围,自动建立的一定宽度的多边形。
  例如,某地区有危险品仓库,要分析一旦仓库爆炸所涉及的范围,这就需要进行点缓冲区分析等等。
  续上节内容,缓冲区分析是GIS的基本空间操作功能之一,是指在点、线、面实体的周围,自动建立的一定宽度的多边形。
  
  为了在合适的映射位置,使用zoomToEnvelope(缩放/平移映射到指定的包络图上)。注意,必须具有相同的spatialReference。

AGSEnvelope* envelope = [self createEnvelope];
[_mapView zoomToEnvelope:envelope animated:YES];

–界面:

// Copyright 2016/4/18 by SevenJohs
//
//
@property (nonatomic , strong)      IBOutlet AGSMapView *mapView;
//开始缓冲区操作按钮
@property (strong, nonatomic) IBOutlet UIButton *btnToStartBuffer;
//控制缓冲区的Slider
@property (strong, nonatomic) IBOutlet UISlider *bufferDegreeSlider;
//选择绘制类型按钮(点/线/面)
@property (strong, nonatomic) IBOutlet UISegmentedControl *geometrySelectSegment;
//重置按钮
@property (strong, nonatomic) IBOutlet UIButton *btnToReset;

-点击事件操作

#pragma MARK -- Button Click Methods
/**
 *  开始对geometry对象进行缓冲区操作
 *
 */
- (IBAction)startBuffer:(id)sender {
    AGSGeometry* sketchGeo = [_skechLayer.geometry copy];

    AGSSimpleMarkerSymbol* pointSymbol = [[AGSSimpleMarkerSymbol alloc]init];
    pointSymbol.color = [UIColor purpleColor];
    pointSymbol.style = AGSSimpleMarkerSymbolStyleCircle;
    AGSSimpleLineSymbol* lineSymbol = [[AGSSimpleLineSymbol alloc]init];
    lineSymbol.color = [UIColor magentaColor];
    lineSymbol.width = 4;

    //判断类型,添加特定样式
    AGSGraphic* graphic = [AGSGraphic graphicWithGeometry:sketchGeo symbol:nil attributes:nil infoTemplateDelegate:nil];
    if ([sketchGeo isKindOfClass:[AGSPoint class]]) {
        graphic.symbol = pointSymbol;

    } else {
        graphic.symbol = lineSymbol;
    }
    [_graphicLayer addGraphic:graphic];

    //新创建的buffer graphic,并添加
    AGSGraphic* newBufferGraphic = [self createBufferGraphicByGeometry:sketchGeo];
    //便于重置或移除操作的数组
    [_lastBufferArr addObject:newBufferGraphic];
    [_graphicLayer addGraphic:newBufferGraphic];

    [_skechLayer clear];   
}
- (IBAction)reset:(id)sender {
    _lastBufferArr = [NSMutableArray array];
    [_graphicLayer removeAllGraphics];

    [_skechLayer clear];
}
/**
 *  Slider Value 改变时,同步更新缓冲区数值
 *
 */
- (IBAction)slider:(id)sender {
    int value = (int)self.bufferDegreeSlider.value;
    _bufferDistance = value;

    //remove old buffer之后再创建新的bufferGraphic
    for (AGSGraphic* oldGraphic in _lastBufferArr) {
        [self.graphicLayer removeGraphic:oldGraphic];
    }
    NSMutableArray* newGraphicsArr = [NSMutableArray array];
    for (AGSGraphic* graphic in _graphicLayer.graphics) {
        AGSGeometryEngine* geometryEngine = [AGSGeometryEngine defaultGeometryEngine];
        AGSGeometry* newGeometry = [geometryEngine bufferGeometry:graphic.geometry byDistance:_bufferDistance];
        AGSGraphic* newGraphic = [AGSGraphic graphicWithGeometry:newGeometry symbol:[self setBufferSymbol] attributes:nil infoTemplateDelegate:nil];
        [newGraphicsArr addObject:newGraphic];
    }
    //便于移除
    _lastBufferArr = newGraphicsArr;
    [_graphicLayer addGraphics:newGraphicsArr];
}
/**
 *  选择对应的geometry,在sketchLayer上绘制
 *
 */
- (IBAction)geometryChoose:(id)sender {
    switch (_geometrySelectSegment.selectedSegmentIndex) {
        case 0:
            _skechLayer.geometry = [[AGSMutablePoint alloc]initWithSpatialReference:_mapView.spatialReference];
            break;
        case 1:
            _skechLayer.geometry = [[AGSMutablePolyline alloc]initWithSpatialReference:_mapView.spatialReference];
            break;
        case 2:
            _skechLayer.geometry = [[AGSMutablePolygon alloc]initWithSpatialReference:_mapView.sp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值