polygonBarriers Route Analysis Problem

771
2
Jump to solution
07-30-2012 10:09 AM
SpencerV
New Contributor III
Hello,

We are trying to implement the route analysis tool in our app. So far we can complete routes when there are just stops put into the analysis but as soon as we add barriers we get the following error:

Error Domain=NSCocoaErrorDomain Code=400 "Unable to complete operation." UserInfo=0xfe93f20 {NSLocalizedFailureReason='polygonBarriers' parameter is invalid, NSURL=http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route/solve?f=json, NSLocalizedDescription=Unable to complete operation.}

Below is the code we are attempting to use to add barriers which is slightly based off of the routing sample online.

 NSMutableArray *barrierGraphics = [[NSMutableArray alloc] init ];         incidents_barriers = [[AGSGraphicsLayer alloc] init ];         [self.mapView addMapLayer:incidents_barriers withName:@"Incident Barriers"];         for(i=0;i<[incidents.graphics count];i++)         {             double x = ((AGSGraphic *)[incidents.graphics objectAtIndex:i]).geometry.envelope.center.x;             double y = ((AGSGraphic *)[incidents.graphics objectAtIndex:i]).geometry.envelope.center.y;             AGSSymbol *symbol;             symbol = [self barrierSymbol];             NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];             [attributes setValue:[NSNumber numberWithInt:i+1] forKey:@"barrierNumber"];             AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:x-0.001 ymin:y-0.001 xmax:x+0.001 ymax:y+0.001 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];             AGSGraphic *tempBarrier = [AGSGraphic graphicWithGeometry:env symbol:symbol attributes:nil infoTemplateDelegate:self];             tempBarrier.attributes = attributes;             [incidents_barriers addGraphic:tempBarrier];             [barrierGraphics addObject:tempBarrier];             [incidents_barriers dataChanged];         }         [params setPolygonBarriersWithFeatures:barrierGraphics];         params.ignoreInvalidLocations = YES;         [task solveWithParameters:params];
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
It is failing because you are setting the barrier's geometry as AGSEnvelope. Since, you want to set the polygon barrier, it's geometry must be AGSPolygon.

Hope this helps!

Regards,
Nimesh

View solution in original post

0 Kudos
2 Replies
NimeshJarecha
Esri Regular Contributor
It is failing because you are setting the barrier's geometry as AGSEnvelope. Since, you want to set the polygon barrier, it's geometry must be AGSPolygon.

Hope this helps!

Regards,
Nimesh
0 Kudos
SpencerV
New Contributor III
That worked! If anyone has a similar issue this will fix the problem:

        NSMutableArray *barrierGraphics = [[NSMutableArray alloc] init ];
        incidents_barriers = [[AGSGraphicsLayer alloc] init ];
        [self.mapView addMapLayer:incidents_barriers withName:@"Incident Barriers"];
        for(i=0;i<[incidents.graphics count];i++)
        {
            double x = ((AGSGraphic *)[incidents.graphics objectAtIndex:i]).geometry.envelope.center.x;
            double y = ((AGSGraphic *)[incidents.graphics objectAtIndex:i]).geometry.envelope.center.y;
            AGSSymbol *symbol;
            symbol = [self barrierSymbol];
            NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
            [attributes setValue:[NSNumber numberWithInt:i+1] forKey:@"barrierNumber"];
            AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:x-0.001 ymin:y-0.001 xmax:x+0.001 ymax:y+0.001 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];
            AGSMutablePolygon *poly = [[AGSMutablePolygon alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];
            [poly addRingToPolygon];
            [poly addPointToRing:[AGSPoint pointWithX:x-0.0005 y:y-0.0005 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]];
            [poly addPointToRing:[AGSPoint pointWithX:x+0.0005 y:y-0.0005 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]];
            [poly addPointToRing:[AGSPoint pointWithX:x+0.0005 y:y+0.0005 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]];
            [poly addPointToRing:[AGSPoint pointWithX:x-0.0005 y:y+0.0005 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]];
            [poly closePolygon];
            AGSGraphic *tempBarrier = [AGSGraphic graphicWithGeometry:poly symbol:symbol attributes:nil infoTemplateDelegate:self];
            tempBarrier.attributes = attributes;
            [incidents_barriers addGraphic:tempBarrier];
            [barrierGraphics addObject:tempBarrier];
            [incidents_barriers dataChanged];
        }
        [params setPolygonBarriersWithFeatures:barrierGraphics];
        params.ignoreInvalidLocations = YES;
        [task solveWithParameters:params];


Thank you!
0 Kudos