iPhone的ArcGIS Polygon绘图问题

时间:2015-01-19 20:56:45

标签: ios iphone ipad arcgis

我是ArcGIS iPhone平台的新手。我已经开发了一个iPhone应用程序,app正在使用MapKit框架进行Overlays [Polylines and Polygons]绘图,但由于一些问题,我们正在用ArcGIS IOS地图替换Apple Maps SDK。但是我对ArcGIS IOS Maps的问题很少。

1)我正在尝试在ArcGIS地图上绘制多边形对象,但这些没有以正确的形状和正确的位置出现/绘制。在Apple地图上,多边形绘制为方形,但在ArcGIS上,iPhone地图多边形显示为"无限线"。 [我附上了ArcGIS Map和Apple Maps的输出]

我的代码

- (void)viewDidLoad {

    [super viewDidLoad];   

    NSURL* url = [NSURLURLWithString:@"https://gis.zoetermeer.nl/arcgis/rest/services/Public/GBKZ_Prod/MapServer/"];
    AGSTiledMapServiceLayer *tiledLayer = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:url];
    tiledLayer.delegate = self;
    [self.mapView addMapLayer:tiledLayer withName:@"Basemap Tiled Layer"];
}

- (void)layerDidLoad: (AGSLayer*) layer{

    NSLog(@"Layer added successfully");

    AGSGraphicsLayer* myGraphicsLayer = [AGSGraphicsLayer graphicsLayer];
    [self.mapView addMapLayer:myGraphicsLayer withName:@"Graphics Layer"];
    NSLog(@"%i",myGraphicsLayer.spatialReferenceStatusValid);

    AGSSpatialReference *specailRefference = [AGSSpatialReference spatialReferenceWithWKID: 28992];

    NSString *coordinateString = @"4.4998839821275 52.066336122032, 4.499855 52.066286, 4.499792 52.066176, 4.499696 52.066014, 4.499631 52.066002, 4.499611 52.065966, 4.499604 52.065862, 4.499448 52.065609, 4.499412 52.065552, 4.499407 52.065543, 4.499399 52.065536, 4.499389 52.065529, 4.499378 52.065524, 4.4993733686962 52.065522931238, 4.4993733686962 52.066336122032";

    NSString *coordinateString2 = @"4.4991002778594 52.065436800426, 4.499085 52.065422, 4.499100 52.065386, 4.499177 52.065316, 4.499370 52.065273, 4.499362 52.065259, 4.499053 52.065327, 4.498905 52.065360, 4.498794 52.065385, 4.498657 52.065415, 4.498647 52.065418, 4.498638 52.065423, 4.498632 52.065429, 4.498629 52.065436, 4.498629 52.065436800426";

    NSString *coordinateString3 = @"4.4993733686962 52.075329338091, 4.5008878063918 52.075329338091, 4.5008878063918 52.074430016486, 4.4993733686962 52.074430016486";

    AGSMutablePolygon *polyGon1 = [self getpolygon:coordinateString];
    AGSMutablePolygon *polyGon2 = [self getpolygon:coordinateString2];
    AGSMutablePolygon *polyGon3 = [self getpolygon:coordinateString3];
    CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(52.066002,4.499631);

    AGSPoint* gpsPoint = [[AGSPoint alloc] initWithX:coordinate.longitude
                                                 y:coordinate.latitude                                        spatialReference:[AGSSpatialReference wgs84SpatialReference]];


    AGSGeometryEngine* engine = [AGSGeometryEngine defaultGeometryEngine];

    AGSPoint* mapPoint = (AGSPoint*) [engine projectGeometry:gpsPoint                                              toSpatialReference:specailRefference];

    [self.mapView zoomToGeometry:mapPoint withPadding:100 animated:YES];


    AGSGraphic *graphic1 = [[AGSGraphic alloc] initWithGeometry:polyGon1 symbol:[self barrierSymbol] attributes:nil];
    [myGraphicsLayer addGraphic:graphic1];

    AGSGraphic *graphic2 = [[AGSGraphic alloc] initWithGeometry:polyGon2 symbol:[self barrierSymbol]  attributes:nil];
    [myGraphicsLayer addGraphic:graphic2];

    AGSGraphic *graphic3 = [[AGSGraphic alloc] initWithGeometry:polyGon3 symbol:[self barrierSymbol]  attributes:nil];
    [myGraphicsLayer addGraphic:graphic3];
}


- (AGSCompositeSymbol*)barrierSymbol {

    AGSCompositeSymbol *cs = [AGSCompositeSymbol compositeSymbol];
    AGSSimpleLineSymbol *sls = [AGSSimpleLineSymbol simpleLineSymbol];

    sls.color = [UIColor greenColor];
    sls.style = AGSSimpleLineSymbolStyleSolid;
    sls.width = 20;

    AGSSimpleFillSymbol *sfs = [AGSSimpleFillSymbol simpleFillSymbol];
    sfs.outline = sls;
    sfs.style = AGSSimpleFillSymbolStyleHorizontal;
    sfs.color = [UIColor darkTextColor];
    [cs addSymbol:sfs];

    return cs;
}

- (AGSMutablePolygon*)getpolygon:(NSString*)coordinateString{

    AGSSpatialReference *specailRefference = [AGSSpatialReference spatialReferenceWithWKID: 28992];

    AGSMutablePolygon *polyGon = [[AGSMutablePolygon alloc] initWithSpatialReference:specailRefference];

    [polyGon addRingToPolygon];

    NSArray *tokens = [coordinateString componentsSeparatedByString:@","];

    for (int k=0; k<[tokens count]; k++) {
        NSString *latlong = [tokens objectAtIndex:k];
        NSArray *latlongArray = [latlong componentsSeparatedByString:@" "];

        NSString *longi = [latlongArray objectAtIndex:0];
        double longVal = [longi doubleValue];

        NSString *lati = [latlongArray objectAtIndex:1];
        double latVal = [lati doubleValue];

        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latVal, longVal);

        AGSPoint* gpsPoint = [[AGSPoint alloc] initWithX:coordinate.longitude y:coordinate.latitude spatialReference:[AGSSpatialReference wgs84SpatialReference]];

        AGSGeometryEngine* engine = [AGSGeometryEngine defaultGeometryEngine];
        AGSPoint* mapPoint = (AGSPoint*) [engine projectGeometry:gpsPoint toSpatialReference:specailRefference];

        [polyGon addPointToRing:mapPoint];

    }
    return polyGon;

}

请指导我如何正确地在ArcGIS地图上绘制多边形。谢谢!

enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

我认为对于每个多边形,第一个点坐标和最后一个点坐标应该相同。例如:

如果要从这些点绘制多边形: [1,1], [2,2], [3,2], [4,1]

您应该在坐标字符串中添加的内容是:

NSString *coordinateString = @"1 1, 2 2, 3 2, 4 1, 1 1";