现在的位置: 首页 > 综合 > 正文

ArcGIS API for iOS 中的几何对象

2013年09月16日 ⁄ 综合 ⁄ 共 3858字 ⁄ 字号 评论关闭

http://www.giser.net/?p=262

ArcGIS API for iOS 中的几何对象
ArcGIS API for iOS包含5种轻量级的几何对象类,这些类用来在地图上显示几何对象的形状,同时可以传送给ArcGIS Server用来进行空间分析。虽然ArcGIS Desktop支持3D几何坐标(x,y,z),但ArcGIS API for iOS只支持2D几何坐标(x,y),并且对M值和ID值也暂不支持。
1 ArcGIS API for iOS中的五种基本几何类型为:
point
Multipoint
polyline
polygon
Envelope
2 ArcGIS API for iOS 中的几何对象都具有空间参考属性,并可以 通过两种方式来定义:
well-known ID (WKID)
well-known text (WKT)
3 可变与不可变对象
Objective-C中的对象都有两种,即可变与不可变对象,可变对象可以用来编辑,不可变对象不能够编辑,因此ArcGIS API for iOS 中的几何对象也存在可变与不可变对象,对照表如下:
Geometry type            Immutable object    Mutable object

Point                AGSPoint        AGSMutablePoint
Multipoint            AGSMultipoint        AGSMutableMultipoint
Polyline            AGSPolyline        AGSMutablePolyline
Polygon                AGSPolygon        AGSMutablePolygon
Envelope            AGSEnvelope        AGSMutableEnvelope

在ArcGIS Server发布的web服务中返回的几何对象绝大多数为不可变对象,但是可以通过使用mutableCopy 方法方便的将不可变对象转换成为可变对象,示例代码如下:
AGSPoint* point = …;
AGSMutablePoint* mutable = [point mutableCopy];
[mutable updateWithX:20 y:20];
4 点对象(Point)
点对象的构造方法比较简单,只有x,y坐标和参考系信息,如下:
AGSPoint* point = [AGSPoint pointWithX:10 y:10 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326 WKT:nil]];
5 多点对象(Multipoint)
多点是点对象的集合,同时具有空间参考信息,构造方法如下:
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]];
6 线(Polyline)
线是由path组成,path是连续的线段,同时具有空间参考信息,构造方法如下:
AGSMutablePolyline* poly = [[AGSMutablePolyline alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326 WKT:nil]];

[poly addPathToPolyline];
[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]];

[poly addPathToPolyline];
[poly addPointToPath:[AGSPoint pointWithX:20 y:10 spatialReference:nil]];
[poly addPointToPath:[AGSPoint pointWithX:20 y:-10 spatialReference:nil]];
7 多边形(polygon)
多边形对象由环(ring)组成,ring是连续闭合的线段,同时具有空间参考信息,构造方法如下:
AGSMutablePolygon* poly = [[AGSMutablePolygon alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326 WKT:nil]];

[poly addRingToPolygon];
[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]];

[poly addRingToPolygon];
[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]];

8 矩形对象
矩形对象存储两对坐标,分别为(xmin,ymin)和(xmax,ymax),同时具有空间参考信息,存储范围信息,构造方法如下:
AGSEnvelope env = [AGSEnvelope envelopeWithXmin:10 ymin:10 xmax:30 ymax:30 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326 WKT:nil]];
9 几何对象与JSON
ArcGIS API for iOS 中的几何对象提供了从JSON格式文本构造的方法initWithJSON,和将几何对象转换成JSON格式的方法encodeToJSON,使用方法如下:
// from json to object
NSString* jsonPoint = @”{ /”x/” : -118.4 , /”y/” : -45.2 , /”spatialReference/” : {/”wkid/” : 4326} }”;
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *json = [parser objectWithString:jsonPoint];
AGSPoint* point = [[AGSPoint alloc] initWithJSON:json];

// from object to json
NSDictionary *json = [point encodeToJSON];
SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSString* jsonPoint = [writer stringWithObject:json];

参考资料:http://help.arcgis.com/en/arcgismobile/10.0/apis/iPhone/concepts/index.html#/Geometry_Objects/00pw0000004r000000/

抱歉!评论已关闭.