How to use Geometry Buffer Service on a Polyline?

736
0
10-02-2012 10:25 AM
Labels (1)
TimB
by
New Contributor III
Hello,
I am able to use the geometry service buffer functionality on a MapPoint and a List of MapPoints. However, I can not seem to get it to work with a polyline geometry (see code attempt below).  It will result into the failed callback with an innerException: "Unable to complete operation".

Can we buffer a polyline using the geometry service?  If so, any examples on how to do so? I'd prefer not to use a GP tool if possible. 

My current workaround (although inefficient) is to geodesify the polyline and create a list of graphics from each path's point collection of the geodesified geometry.  I then pass that list to the buffer operation and it works fine. 


            Polyline myLine = new Polyline();
            PointCollection myPC = new PointCollection();
            foreach (MapPoint refMP in myMapPoints) myPC.Add(refMP);
            myLine.Paths.Add(myPC);
          

            Geometry myRoute = _mercator.FromGeographic(myLine);
            myRoute.SpatialReference = MyMap.SpatialReference;
            Graphic graphicToBuffer = new Graphic()
            {
                Geometry = myRoute,
                Symbol = LayoutRoot.Resources["RouteLineSymbol"] as LineSymbol
            };

            BufferParameters bufferParams = new BufferParameters()
            {
                Unit = LinearUnit.NauticalMile,
                BufferSpatialReference = new SpatialReference(4326), //WGS 1984
                OutSpatialReference = MyMap.SpatialReference,
                UnionResults=true
            };
            bufferParams.Distances.Add(1000);
            bufferParams.Features.Add(graphicToBuffer);
           
           
            LocalGeometryService myGS = LocalGeometryService.GetService();
            GeometryService myTask = new GeometryService();
            myTask.Url = myGS.UrlGeometryService;
            myTask.BufferCompleted += new EventHandler<GraphicsEventArgs>(myTask_BufferCompleted);
            myTask.Failed += new EventHandler<TaskFailedEventArgs>(myTask_Failed);
           
            myTask.BufferAsync(bufferParams);
0 Kudos
0 Replies