Select to view content in your preferred language

Select the Features within the Buffer Distance

1512
2
03-15-2011 03:33 AM
GirishS1
Emerging Contributor
Hi,

I created the buffer and it is working fine and now i have to select the other features which are falling within the buffer distance.. and i need to display those features with other symbols... currently i m using SL 3.0.. Its bit urgent...

Thanks in Advance..
0 Kudos
2 Replies
JMcNeil
Deactivated User
Girish,

Can you provide some more informaton maybe some of your code?  It is hard to figure out what you need and what you doing based off the limited information in your post.

Here's my code behind for a buffer point query...hope this helps.


  private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            if (BufferPointSelect.IsExpanded == true)
            {

                _geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
                _geometryService.BufferCompleted += GeometryService_BufferCompleted;
                _geometryService.Failed += GeometryService_Failed;


                
                _queryTask = new QueryTask((Layers.SelectedItem as FeatureLayer).Url);
               // _queryTask = new QueryTask("http://servername/ArcGIS/rest/services/MS4/MapServer/4");
                _queryTask.ExecuteCompleted += BuffPointQueryTask_ExecuteCompleted;
                _queryTask.Failed += BuffPointQueryTask_Failed;

                _pointAndBufferGraphicsLayer = Map.Layers["MyGraphicsLayer"] as GraphicsLayer;
                GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;

                _geometryService.CancelAsync();
                _queryTask.CancelAsync();

                Graphic clickGraphic = new Graphic();
                clickGraphic.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                clickGraphic.Geometry = e.MapPoint;
                // Input spatial reference for buffer operation defined by first feature of input geometry array
                clickGraphic.Geometry.SpatialReference = Map.SpatialReference;

                _pointAndBufferGraphicsLayer.ClearGraphics();
                graphicsLayer.ClearGraphics();

                clickGraphic.SetZIndex(2);
                _pointAndBufferGraphicsLayer.Graphics.Add(clickGraphic);

                // If buffer spatial reference is GCS and unit is linear, geometry service will do geodesic buffering
                ESRI.ArcGIS.Client.Tasks.BufferParameters bufferParams = new ESRI.ArcGIS.Client.Tasks.BufferParameters()
                {
                    BufferSpatialReference = new SpatialReference(4326),
                    OutSpatialReference = Map.SpatialReference,
                    Unit = LinearUnit.Meter,
                };
                bufferParams.Distances.Add(100);
                bufferParams.Features.Add(clickGraphic);

                _geometryService.BufferAsync(bufferParams);
            }
        }

        void GeometryService_BufferCompleted(object sender, GraphicsEventArgs args)
        {
            Graphic bufferGraphic = new Graphic();
            bufferGraphic.Geometry = args.Results[0].Geometry;
            bufferGraphic.Symbol = LayoutRoot.Resources["BufferSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
            bufferGraphic.SetZIndex(1);

            _pointAndBufferGraphicsLayer.Graphics.Add(bufferGraphic);

            ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.ReturnGeometry = true;
            query.OutSpatialReference = Map.SpatialReference;
            query.Geometry = bufferGraphic.Geometry;
            query.OutFields.Add("*");
            _queryTask.ExecuteAsync(query);
        }

        private void BuffPointQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {

            FeatureSet featureSet = args.FeatureSet;

            if (featureSet == null || featureSet.Features.Count < 1)
            {
                MessageBox.Show("No features retured from query");
                return;
            }

            GraphicsLayer graphicsLayer = Map.Layers["MySelectionGraphicsLayer"] as GraphicsLayer;


            if (featureSet != null && featureSet.Features.Count > 0)

            {
                foreach (Graphic feature in featureSet.Features)
                {

                    switch (featureSet.GeometryType.ToString())
                    {
                        case "Polygon":
                            feature.Symbol = LayoutRoot.Resources["ResultsFillSymbol"] as FillSymbol;
                            break;
                        case "Polyline":
                            feature.Symbol = LayoutRoot.Resources["CustomGrowLineSymbol"] as LineSymbol;
                            break;
                        case "Point":
                            feature.Symbol = LayoutRoot.Resources["ResultsMarkerSymbol"] as SimpleMarkerSymbol;
                            break;
                    }

                    graphicsLayer.Graphics.Insert(0, feature);

                }
              
                ResultsDisplay.IsExpanded = true;
            }
            MyDrawSurface.IsEnabled = false;

        
        }

        private void GeometryService_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Geometry service failed: " + args.Error);
        }

        private void BuffPointQueryTask_Failed(object sender, TaskFailedEventArgs args)
        {
            MessageBox.Show("Query failed: " + args.Error);
        }



J
0 Kudos
JenniferNery
Esri Regular Contributor
You can refer to this SDK sample for BufferAsync: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#BufferPoint.

You can use the GraphicEventArgs.Result[0].Geometry to make your selection.

You can look at the SpatialQuery sample here:http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SpatialQuery and use the result from BufferAsync instead of using DrawEventArgs.Geometry.

You can look at Selectons sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#SelectGraphics to change the graphic symbol.
0 Kudos