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