ArcGIS Runtime SDK for iOS (6) --- geospatial Geometric Analysis and Operations (medium)

Source: Internet
Author: User

ArcGIS Runtime SDK for iOS (6) --- geospatial Geometric Analysis and Operations (medium)

2016.4.18 Wuhan yinqing
By SevenJohs.

Overview
Implement the buffer and cut operations. Content:
Buffer cut

-Buffer [buffer]:-
In the last section, the buffer analysis is one of the basic spatial operations functions of GIS. It refers to a polygon with a certain width automatically created around the point, line, and surface entity.
For example, if a dangerous goods warehouse exists in a certain area, it is necessary to analyze the scope of the warehouse explosion.
In the last section, the buffer analysis is one of the basic spatial operations functions of GIS. It refers to a polygon with a certain width automatically created around the point, line, and surface entity.
  
ZoomToEnvelope (scale/PAN ing to the specified Envelope Graph) is used to fit the ing position ). Note that the spatialReference must be the same.

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

-Interface:

// Copyright distribute by SevenJohs // @ property (nonatomic, strong) IBOutlet AGSMapView * mapView; // start the buffer OPERATION button @ property (strong, nonatomic) IBOutlet UIButton * btnToStartBuffer; // control the buffer's Slider @ property (strong, nonatomic) IBOutlet UISlider * bufferDegreeSlider; // select the draw type button (vertex/line/surface) @ property (strong, nonatomic) IBOutlet UISegmentedControl * geometrySelectSegment; // reset the button @ property (strong, nonatomic) IBOutlet UIButton * btnToReset;

-Click Event operations

# Pragma MARK -- Button Click Methods/*** start the buffer operation on the geometry object **/-(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; // judgment type, add a specific style 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]; // the newly created buffer graphic and add AGSGraphic * newBufferGraphic = [self createBufferGraphicByGeometry: sketchGeo]; // The array [_ lastBufferArr addObject: newBufferGraphic]; [_ graphicLayer addGraphic: newBufferGraphic]; [_ skechLayer clear];}-(IBAction) reset :( id) sender {_ lastBufferArr = [NSMutableArray array]; [_ graphicLayer removeAllGraphics]; [_ skechLayer clear];}/*** when the Slider Value is changed, synchronously update the buffer value **/-(IBAction) slider :( id) sender {int value = (int) self. bufferDegreeSlider. value; _ bufferDistance = value; // remove the old buffer and create a new bufferGraphic for (AGSGraphic * oldGraphic in _ lastBufferArr) {[self. graphicLayer removeGraphic: oldGraphic];} NSMutableArray * newGraphicsArr = [NSMutableArray array]; for (AGSGraphic * graphic in _ graphicLayer. graphics) {AGSGeometryEngine * geometryEngine = [AGSGeometryEngine defaultryengine]; AGSGeometry * newGeometry = [geometryEngine bufferGeometry: graphic. geometry byDistance: _ bufferDistance]; AGSGraphic * newGraphic = [AGSGraphic identifier: newGeometry symbol: [self setBufferSymbol] attributes: nil identifier: nil]; [newGraphicsArr addObject: newGraphic];} // easy to remove _ lastBufferArr = newGraphicsArr; [_ graphicLayer addGraphics: newGraphicsArr];}/*** select the corresponding geometry and draw **/-(IBAction) on the sketchLayer) geometryChoose :( id) sender {switch (_ geometrySelectSegment. selectedSegmentIndex) {case 0: _ skechLayer. geometry = [[AGSMutablePoint alloc] initwitheat atialreference: _ mapView. spatialReference]; break; case 1: _ skechLayer. geometry = [[AGSMutablePolyline alloc] initwitheat atialreference: _ mapView. spatialReference]; break; case 2: _ skechLayer. geometry = [[AGSMutablePolygon alloc] initwitheatatialreference: _ mapView. spatialReference]; break; default: break;} [_ skechLayer clear];}

-Custom Method

/*** Set the buffer style ** @ return AGSSimpleFillSymbol * buffer style **/-(optional *) setBufferSymbol {AGSSimpleFillSymbol * bufferSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; bufferSymbol. color = [[UIColor brownColor] colorWithAlphaComponent: 0.4]; bufferSymbol. outline. color = [UIColor darkGrayColor]; return bufferSymbol;}/*** create a buffer graphic using the engine ** @ return new buffer graphic */-(AGSGraphic *) createBufferGraphicByGeometry :( AGSGeometry *) sketchGeometry {AGSGeometryEngine * geometryEngine = [AGSGeometryEngine ryengine]; AGSGeometry * newGeometry = [geometryEngine bufferGeometry: sketchGeometry byDistance: _ bufferDistance]; AGSGraphic * newGraphic = [geometgraphicwithgeometry ry symbol: [self setBufferSymbol] attributes: nil identifier: nil]; return newGraphic;}/*** create envelope */-(AGSEnvelope *) createEnvelope {AGSSpatialReference * sr = [AGSSpatialReference identifier: SPATIAL_REFERENCE_WKID]; AGSEnvelope * envelope = [AGSEnvelope envelopeWithXmin: X_MIN ymin: Y_MIN xmax: X_MAX ymax: Y_MAX spatialReference: sr]; return envelope ;}

-ViewDidLoad & MapViewDidLoad

-(Void) viewDidLoad {[super viewDidLoad]; self. mapView. layerDelegate = self; self. mapView. touchDelegate = self; self. mapView. showMagnifierOnTapAndHold = YES; [self. mapView enableWrapAround]; [self addTiledLayer]; [self addGraphicsLayer]; int value = (int) self. bufferDegreeSlider. value; _ bufferDistance = value; // create envelope, centralized target AGSEnvelope * envelope = [self createEnvelope]; [_ mapView zoomToEnvelope: envelope animated: YES]; _ lastBufferArr = [NSMutableArray array];} # pragma mark using methods-(void) mapViewDidLoad :( AGSMapView *) mapView {_ skechLayer = [using graphicsLayer]; _ skechLayer. geometry = [[AGSMultipoint alloc] initwitheat atialreference: _ mapView. spatialReference]; [_ mapView addMapLayer: _ skechLayer withName: @ "Sketch Layer"]; _ mapView. touchDelegate = _ skechLayer ;}

-Result:

========================================================== ==============

========================================================== ==============
-Cut [Cut]:-

-Interface:

// Copyright 2016/4/18 by SevenJohs // @ property (nonatomic, strong) IBOutlet AGSMapView * mapView; // The button event for creating a polygon @ property (strong, nonatomic) IBOutlet UIButton * btnToDrawPolygon; // composite the sketch image to facilitate observation @ property (strong, nonatomic) IBOutlet UIButton * btnToAdd; // The button event @ property (strong, nonatomic) IBOutlet UIButton * btnToDrawCutLine; // click the event to start cropping @ property (strong, nonatomic) IBOutlet UIButton * btnToCut; // reset @ property (strong, nonatomic) IBOutlet UIButton * btnToReset;

-Click Event operations

# Pragma MARK -- Button Click Methods/*** start to draw a polygon **/-(IBAction) polygonDraw :( id) sender {_ btnToDrawPolygon. enabled = NO; _ btnToAdd. enabled = YES; _ btnToCut. enabled = NO; _ btnToDrawCutLine. enabled = YES; [_ skechLayer clear]; _ skechLayer. geometry = [[AGSMutablePolygon alloc] initwitheatatialreference: _ mapView. spatialReference];}/*** draws a composite image style for the graphics on the sketchLayer and fills in style consistency **/-(IBAction) add :( id) sender {_ BtnToDrawCutLine. enabled = YES; _ btnToCut. enabled = YES; AGSGeometry * sketchGeo = [_ skechLayer. geometry copy]; AGSGraphic * graphic = [AGSGraphic graphicWithGeometry: sketchGeo symbol: nil attributes: nil infoTemplateDelegate: nil]; // create a CompositeSymbol for the new geometry AGSCompositeSymbol * compositeSymbol = [AGSCompositeSymbol compositeSymbol]; [compositeSymbol addSymbol: [self setLineSymbol]; [compositeSym Bol addSymbol: [self setFillSymbol]; graphic. symbol = compositeSymbol; [_ graphicLayer addGraphic: graphic]; [_ skechLayer clear];}/*** draw line **/-(IBAction) cutLineDraw :( id) sender {_ btnToDrawPolygon. enabled = YES; _ btnToCut. enabled = YES; _ btnToAdd. enabled = NO; _ btnToDrawCutLine. enabled = NO; _ skechLayer. geometry = [[AGSMutablePolyline alloc] initwitheat atialreference: _ mapView. spatialReference];}/** * Start cropping **/-(IBAction) startToCut :( id) sender {// create a CompositeSymbol for the new geometry component * compositeSymbol = [AGSCompositeSymbol compositeSymbol]; [compositeSymbol addSymbol: [self increment]; [increment addSymbol: [self setFillSymbol]; AGSGeometryEngine * geoEngine = [AGSGeometryEngine defaultryengine]; NSMutableArray * newGraphicsArr = [NSMutableArray array]; // traverse the drawn image fo R (AGSGraphic * graphic in _ graphicLayer. graphics) {NSArray * partition = [geoEngine cutGeometry: graphic. geometry withCutter :( agspolympus line *) _ skechLayer. geometry]; if (newGeometryArr. count! = 0) {for (AGSGeometry * geometry in newGeometryArr) {AGSGraphic * newGraphic = [[AGSGraphic alloc] initWithGeometry ry symbol: compositeSymbol attributes: nil metadata: nil]; [newGraphicsArr addObject: newGraphic] ;}} else {[newGraphicsArr addObject: graphic] ;}} [_ skechLayer clear]; [_ graphicLayer removeAllGraphics]; [_ graphicLayer addGraphics: newGraphicsArr];} /*** reset **/-(IBAction) reset :( id) sender {_ btnToDrawPolygon. enabled = NO; _ btnToAdd. enabled = YES; _ btnToDrawCutLine. enabled = YES; _ btnToCut. enabled = NO; [_ graphicLayer removeAllGraphics]; [_ skechLayer clear]; _ skechLayer. geometry = [[AGSMutablePolygon alloc] initwitheatatialreference: _ mapView. spatialReference];}

-Custom Method

/*** Set the buffer style ** @ return AGSSimpleFillSymbol * buffer style **/-(optional *) setBufferSymbol {AGSSimpleFillSymbol * bufferSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; bufferSymbol. color = [[UIColor brownColor] colorWithAlphaComponent: 0.4]; bufferSymbol. outline. color = [UIColor darkGrayColor]; return bufferSymbol;}/*** create a buffer graphic using the engine ** @ return new buffer graphic */-(AGSGraphic *) createBufferGraphicByGeometry :( AGSGeometry *) sketchGeometry {AGSGeometryEngine * geometryEngine = [AGSGeometryEngine ryengine]; AGSGeometry * newGeometry = [geometryEngine bufferGeometry: sketchGeometry byDistance: _ bufferDistance]; AGSGraphic * newGraphic = [geometgraphicwithgeometry ry symbol: [self setBufferSymbol] attributes: nil identifier: nil]; return newGraphic;}/*** create envelope */-(AGSEnvelope *) createEnvelope {AGSSpatialReference * sr = [AGSSpatialReference identifier: SPATIAL_REFERENCE_WKID]; AGSEnvelope * envelope = [AGSEnvelope envelopeWithXmin: X_MIN ymin: Y_MIN xmax: X_MAX ymax: Y_MAX spatialReference: sr]; return envelope ;} /*** base map loading */-(void) addTiledLayer {AGSTiledMapServiceLayer * tiledLayer = [[initalloc] initWithURL: [NSURL URLWithString: kTiledMapServiceURL]; [self. mapView addMapLayer: tiledLayer withName: @ "Tiled Layer"];}/*** element Layer initialization and loading */-(void) addGraphicsLayer {_ graphicLayer = [AGSGraphicsLayer graphicsLayer]; _ graphicLayer. visible = YES; [self. mapView addMapLayer: _ graphicLayer withName: @ "Graphic layer"];}

-ViewDidLoad & MapViewDidLoad

-(Void) viewDidLoad {[super viewDidLoad]; self. mapView. layerDelegate = self; self. mapView. touchDelegate = self; self. mapView. showMagnifierOnTapAndHold = YES; [self. mapView enableWrapAround]; [self addTiledLayer]; [self addGraphicsLayer]; // create envelope, centralized target AGSEnvelope * envelope = [self createEnvelope]; [_ mapView complete: envelope animated: YES] ;}# pragma mark AGSMapViewLayerDelegate methods-(void) mapViewDidLoad :( AGSMapView *) mapView {_ skechLayer = [AGSSketchGraphicsLayer graphicsLayer]; _ skechLayer. geometry = [[AGSMultipoint alloc] initwitheat atialreference: _ mapView. spatialReference]; [_ mapView addMapLayer: _ skechLayer withName: @ "Sketch Layer"]; _ mapView. touchDelegate = _ skechLayer ;}

-Result:

========================================================== ==============

========================================================== ==============
-Intersection and Difference set: [Union & Difference]

-Interface:

// Copyright identified by SevenJohs // @ property (nonatomic, strong) IBOutlet AGSMapView * mapView; // select the function button @ property (strong, nonatomic) IBOutlet UISegmentedControl * chooseSegment; // Add a graph and perform operations @ property (strong, nonatomic) IBOutlet UIButton * btnToAdd; @ property (strong, nonatomic) IBOutlet UIButton * btnToReset;

-Click Event operations

# Pragma MARK -- Button Click Methods-(IBAction) segmentChoose :( UISegmentedControl *) sender {if (_ unionGraphic & _ differenceGraphic) {if (sender. selectedSegmentIndex = 0) {[_ graphicLayer removeAllGraphics]; [_ graphicLayer addGraphic: _ unionGraphic];} else {[_ graphicLayer removeAllGraphics]; [_ graphicLayer addGraphic: _ differenceGraphic] ;}}- (IBAction) btnToAddNewGeometry :( id) sender {// obtain the sketch, and add AGSGeometry * sketchGeometry = [_ skechLayer. geometry copy]; AGSGraphic * sketchGraphic = [AGSGraphic attributes: sketchGeometry symbol: nil attributes: nil]; [_ graphicLayer addGraphic: sketchGraphic]; [_ skechLayer clear]; // when graphic has two graphs, create an engine and perform geometric analysis if (_ graphicLayer. graphicsCount = 2) {_ btnToAdd. enabled = NO; AGSGeometryEngine * geoEngine = [AGSGeometryEngine defaultryengine]; // delegates an object (copy) AGSGeometry * geometry1 = [[_ graphicLayer. graphics objectAtIndex: 0] geometry]; AGSGeometry * geometry2 = [[_ graphicLayer. graphics objectAtIndex: 1] geometry]; _ identifier = [AGSGraphic graphicWithGeometry: [geoEngine differenceOfGeometry: geometry1 andGeometry: geometry2] symbol: nil attributes: nil identifier: nil]; _ unionGraphic = [AGSGraphic graphicWithGeometry: [geoEngine unionGeometries: [NSArray attributes: geometry1, geometry2, nil] symbol: nil attributes: nil]; [self attributes: _ chooseSegment] ;}}- (IBAction) btnToResetData :( id) sender {[_ graphicLayer removeAllGraphics]; [_ skechLayer clear]; _ unionGraphic = nil; _ differenceGraphic = nil; _ btnToAdd. enabled = YES ;}

-Custom Method

# Pragma mark Privated Method-(void) addTiledLayer {AGSTiledMapServiceLayer * tiledLayer = [[initalloc] initWithURL: [NSURL URLWithString: kTiledMapServiceURL]; [self. mapView addMapLayer: tiledLayer withName: @ "Tiled Layer"];}-(void) addGraphicsLayer {// render your * compositeSymbol = [Your compositeSymbol]; [compositeSymbol addSymbol: [self setLineSymbol]; [Your addSymbol: [self setFillSymbol]; [Your addSymbol: [self setPointSymbol]; AGSSimpleRenderer * simpleRenderer = [AGSSimpleRenderer identifier: identifier]; _ graphicLayer = [AGSGraphicsLayer graphicsLayer]; _ graphicLayer. visible = YES; _ graphicLayer. renderer = simpleRenderer; [_ mapView addMapLayer: _ graphicLayer withName: @ "Graphics Layer"];}-(response *) setLineSymbol {response * lineSymbol = [[callback alloc] init]; lineSymbol. color = [UIColor brownColor]; lineSymbol. width = 4; return lineSymbol;}-(AGSSimpleFillSymbol *) setFillSymbol {AGSSimpleFillSymbol * innerSymbol = [AGSSimpleFillSymbol simpleFillSymbol]; innerSymbol. color = [[UIColor greenColor] colorWithAlphaComponent: 0.40]; innerSymbol. outline = nil; return innerSymbol;}-(AGSSimpleMarkerSymbol *) setPointSymbol {AGSSimpleMarkerSymbol * pointSymbol = [[agssimplemarkersymloc alloc] init]; pointSymbol. color = [UIColor orangeColor]; pointSymbol. style = AGSSimpleMarkerSymbolStyleCircle; return pointSymbol ;}

-ViewDidLoad & MapViewDidLoad

- (void)viewDidLoad {    [super viewDidLoad];    self.mapView.layerDelegate = self;    self.mapView.callout.delegate = self;    self.mapView.touchDelegate = self;    self.mapView.showMagnifierOnTapAndHold = YES;    [self.mapView enableWrapAround];    [self addTiledLayer];    [self addGraphicsLayer];}#pragma mark AGSMapViewLayerDelegate methods-(void) mapViewDidLoad:(AGSMapView*)mapView {    _skechLayer = [AGSSketchGraphicsLayer graphicsLayer];    _skechLayer.geometry = [[AGSMutablePolygon alloc]initWithSpatialReference:_mapView.spatialReference];    [_mapView addMapLayer:_skechLayer withName:@"Sketch Layer"];    _mapView.touchDelegate = _skechLayer;    _skechLayer.geometry = [[AGSMutablePolygon alloc]initWithSpatialReference:_mapView.spatialReference];}

-Result:


END.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.