ArcGIS for iOS series (7)-basics-spatial elements-geometric shapes

Source: Internet
Author: User

Loading data is boring. More often, interaction is required to allow users to control the visual effect of maps. For example: add tags to the map, highlight the queried streets, modify the rendering style of the chemical contaminated area, and so on. The basic process is like painting. First, find a blank sheet of paper, and then draw the house, garden, and road in different colors. The paper is the graphic layer (agsgraphiclayer), and the house and other features are the space elements (agsgraphic ).

Graphic Layer(Agsgraphiclayer) has previously been introduced. It is a dynamic Layer Created by the client and carries and manages the space elements in it:


// Create a new graphic layer: agsgraphicslayer * mygraphicslayer = [agsgraphicslayer graphicslayer]; uiview * graphicsview = [self. mapview addmaplayer: mygraphicslayer withname: @ "graphics layer"]; // find the Drawing Layer nsdictionary <agslayerview> * mylayerviewdict = self. mapview. maplayerviews; id <agslayerview> mygraphicslayerview = [mylayerviewdict objectforkey: @ "graphics layer"]; agsgraphicslayer * mygraphicslayer = (agsgraphicslayer *) mygraphicslayerview. agslayer;

Spatial Elements(Agsgraphic) is a standard description of spatial objects, including: geometric shapes (agsgeometry), symbols (agssymbol), attributes (attributes), etc, therefore, the input and output items of many methods in the SDK are spatial elements. The geometric shapes of spatial elements (agsgeometry) must be available. By default, symbols (agssymbol) are simple symbol styles, while attributes (attributes) are optional.


// Create the dot symbol agssimplemarkersymbol * mymarkersymbol = [agssimplemarkersymbol simplemarkersymbol]; mymarkersymbol. color = [uicolor bluecolor]; // create an agspoint * mymarkerpoint = [agspoint pointwithx: 112.2984 Y: 34.9409 spatialreference: Self. mapview. spatialreference]; // agsgraphic * mygraphic = [agsgraphic graphicwithgeometry: mymarkerpoint Symbol: mymarkersymbol attributes: Nil infotemplatedelegate: Nil]; // Add the vertex element to the graphic layer [mygraphicslayer addgraphic: mygraphic]; // refresh the graphic layer [mygraphicslayer datachanged];

1. Geometric Shape

Two-dimensional geometric shapes include three categories: point, line, and surface. Each type has two types: single and multi. There is no arc in the GIS data type. Therefore, CAD users often joke: "Arc GIS" does not actually have an arc ?! Currently, mobile terminals support the following geometric shapes:

· Point)

· Multipoint)

· Line (polyline)

· Polygon)

· Envelope)

Agsgeometry is the base class of all geometric shapes, which defines the basic attributes: The smallest envelope rectangle envelope and spatial reference (ArcGIS
The android SDK does not require spatial reference when defining elements. Therefore, you must specify spatial references before the elements are involved in spatial operations ). Because object-C has a mutable variable design, each geometric shape also extends the corresponding editable type (mutable ).

Figure 3-3-1-1 Inheritance of geometric shapes

Agsgeometry inherits agscoding, which encapsulates the JSON parsing method. When you need to interact with other systems, convert the geometric object to a JSON string using the encodetojson and agsjsonrepresentation methods.

AGSPoint* point = …NSDictionary* json = [point encodeToJSON];  NSString* jsonPointAsString = [json AGSJSONRepresentation];
1.1 o'clock

A point (agspoint) is composed of X, Y, and spatailreference. It is usually initialized using a static method (pointwithx: Y: spatialreference :) and cannot be modified:


Figure 3-3-1-2 main attributes and methods of agspoint

When creating a new vertex or modifying an existing vertex, you must use the agsmutabelpoint statement to provide updatewithx: Y: method or offsetbyx: Y: to modify the vertex coordinate.

Agspoint * point = [agspoint pointwithx: 114.0 Y: 30.0 spatialreference: [agsspatialreference Metric: 4326 WKT: Nil]; // update the coordinate of the vertex agsmutablepoint * mutable = [point mutablecopy]; [mutable updatewithx: 120.0 Y: 20.0];
More than 1.2 points

Multi-Point (agsmultipoint) is equivalent to a point array, and is suitable for storing a group of points of the same nature. For example, a tree's LIDAR scan data itself is tens of thousands of points and is imported into the Geodatabase) it is obvious that the multi-point storage is more efficient. The numpoints attribute records the length of the vertex array:


Figure 3-3-1-3 main attributes and methods of agsmultipoint

When creating a new multi-point or modifying an existing multi-point, you must use the agsmutabelmultipoint statement to add and modify the vertex.

AGSMutableMultipoint multiPoint = [[AGSMutableMultipoint alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326 WKT:nil]]; [multiPoint addPoint: [AGSPoint pointWithX:10 y:10 spatialReference:nil]];  [multiPoint addPoint: [AGSPoint pointWithX:20 y:20 spatialReference:nil]];  [multiPoint addPoint: [AGSPoint pointWithX:30 y:30 spatialReference:nil]];
1.3 lines

An agspolympus line is composed of a paths. Each track contains a number of consecutive vertice nodes that can be lifted. In addition, you must specify the spatailreference. The numpointsinpath method records the number of nodes. You can use the pointonpath: atindex method to find the corresponding node.


Figure 3-3-1-4 main attributes and methods of agspolympus

When creating a new line or modifying a wired line, you must use the agsmutabelpolyline statement to add and modify vertices.

Agsmutablepolyline * poly = [[agsmutablepolyline alloc] initwitheat atialreference: [agsspatialreference spatialreferencewithwkid: 4326 WKT: Nil]; // Add track [poly addpathtopolyline]; // Add a node to the trajectory [poly addpointtopath: [agspoint pointwithx: 10 y: 10 spatialreference: Nil]; [poly addpointtopath: [agspoint pointwithx: 30 Y: 10 spatialreference: nil]; [poly addpointtopath: [agspoint pointwithx: 30 Y: 30 spatialreference: Nil];
1.4

"Life 2, life 2, LIFE 3, and life 3 ...", A polygon is composed of a closed ring (rings). Each ring contains several consecutive vertice nodes. The first and last two nodes are the same, so that the closure is ensured. If the closed ring is an inclusive relationship with each other, a hollow surface can be constructed. Note that the topological relationship between rings cannot be touch or intersect ).


Figure 3-3-1-5 main attributes and methods of agspolympus

You must use the agsmutabelpolygon statement to create a new or modify an existing surface to add and modify vertices.

Agsmutablepolygon * poly = [[agsmutablepolygon alloc] initwitheat atialreference: [agsspatialreference encoding: 4326 WKT: Nil]; // Add a ring [poly ignore]; // Add a node [poly addpointtoring: [agspoint pointwithx: 10 y: 10 spatialreference: Nil]; [poly addpointtoring: [agspoint pointwithx: 30 Y: 10 spatialreference: Nil]; [poly addpointtoring: [agspoint pointwithx: 30 Y: 30 spatialreference: Nil]; [poly addpointtoring: [agspoint pointwithx: 10 y: 30 spatialreference: Nil]; [poly addpointtoring: [agspoint pointwithx: 10 y: 10 spatialreference: Nil];
1.5 envelope rectangle

Agsenvelope is a geometric rectangular outer frame that can represent an outer frame ranging from a line to a map (extent ), provides attributes such as the center point, height, width, and four-angle coordinates, as well as an editable version (agsmutableenvelope ).


Figure 3-3-1-6 main attributes and methods of agsenvelope

AGSEnvelope env = [AGSEnvelope envelopeWithXmin:10 ymin:10 xmax:30 ymax:30 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326 WKT:nil]];

Recommended reading:ArcGIS
Runtime SDK for iOS development series tutorial (5) -- Element Information drawing: http://www.cnblogs.com/esrichina/archive/2012/11/05/2753087.html
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.