Programatically select features from different feature layers

2519
2
09-13-2012 02:26 PM
MichelleMestrovich
New Contributor III
I want to pass an x,y postion from my MouseLeftButtonClickUp event and select any feature that interesects it from multiple featurelayers (there aer ovelapping features between featurelayers). I want to grab all the features from the various featureslayers that interesect a point. I then want to throw them to a datagrid or form so the user can then decide which one they want to actually edit.

Right now event if i have the event on all my featurelayers, it only grabs freatures from layer which is stacked on top and throws tehm to my datagrid.

Thanks
0 Kudos
2 Replies
by Anonymous User
Not applicable
Original User: dbroux

You can use the method GraphicsLayer.FindGraphicsInHostCoordinates.

With multiple feature layers, you'll have to loop over all layers.

There is a sample here (without the loop though).
0 Kudos
by Anonymous User
Not applicable
Original User: mmestrov

Something like this.....

      private void MyMap_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {

            FeatureLayer fl1 = MyMap.Layers["RedlineParkingStalls"] as FeatureLayer;
            FeatureLayer fl2 = MyMap.Layers["RedlineParkingLots"] as FeatureLayer;
            FeatureLayer fl3 = MyMap.Layers["ParkingStalls"] as FeatureLayer;
            FeatureLayer fl4 = MyMap.Layers["ParkingLots"] as FeatureLayer;

            Point Pt = e.GetPosition(MyMap);
            MapPoint newMapPt = MyMap.ScreenToMap(Pt);
            System.Windows.Point screenPnt = MyMap.MapToScreen(newMapPt);

            GeneralTransform generalTransform = MyMap.TransformToVisual(Application.Current.RootVisual);
            System.Windows.Point transformScreenPnt = generalTransform.Transform(screenPnt);
            FeatureLayer[] fllist = new FeatureLayer[] { fl1, fl2, fl3, fl4 };

            foreach (FeatureLayer fl in fllist)
            {
                IEnumerable<Graphic> selected = fl.FindGraphicsInHostCoordinates(transformScreenPnt);
               
                foreach (Graphic g in selected)
                {
                    MyFeatureDataForm.GraphicSource = g;
                }
            }

        }


The problem is my FeatureDataForm is not displaying anything.  My ultimate goal is to take all the graphic select from all the featurelayers that the point intersects and be able to page through the FeatureDataForm to the one I want to update. Hope I'm making sense.
0 Kudos