Selecting both point and line features from two feature layer at the same time

Dec 1, 2014 at 10:10 PM
Hi,

I am having trouble with selecting point features from a point layer in the screen whenever I have a line feature layer present in my map and hoping someone could help me to solve it.
Basically, I have several point and line feature layers (i.e., shape files) which I generated and loaded in to the map object. so far everything works perfect. and the layers are displayed without any major issues.
but I want the user to be able to select various features on the screen and the program should be able to list some of non-redundant selected features fields on a list box.

I used the following code to do the above mentioned tasks

I search all of the feature layers and list all of selected features in lists.

This works without any issue if I only have point layers or line layers displayed on the map. But as soon as I have both of them (point layer and line layer) together, the selection list only returns the line features and there is no sign of point features.

I would appreciate if someone could shed light on this issue.
        private void map1_SelectionChanged(object sender, EventArgs e)
        {
            for (int l = 0; l < map1.Layers.Count; l++)
            {
                if (map1.Layers[l].LegendText.Contains ("EN_"))
                {
                    FeatureLayer fl = map1.Layers[l] as FeatureLayer;
                    ISelection iSelection = fl.Selection;
                    List<IFeature> ls1 = new List<IFeature>();
                    ls1 = iSelection.ToFeatureList();

                    for (int i = 0; i < iSelection.Count; i++)
                    {
                        lstSelected.Add(ls1[i]);
                        SelectedFeature sf = new SelectedFeature();
                        string ty = ls1[i].DataRow.Field<string>("Type");
                        sf.IsLink = ((ty == "EN_RESERVOIR" || ty == "EN_TANK" || ty == "EN_JUNCTION") ? false : true);

                        
                        sf.Index = (Int32)ls1[i].DataRow.Field<double>("Index");


                        SelectedFeature res = selectedFeatures.Find(
                            delegate(SelectedFeature tp)
                            {
                                return (sf.IsLink == tp.IsLink && tp.Index == sf.Index) ? true : false;
                            });

                        if (res == null)
                        {
                            selectedFeatures.Add(sf);
                            this.frmSelect.lstLinks.Items.Add((sf.IsLink?"Link : ":"Node : ")+ sf.Index.ToString());
                        }
                    }
                }
            }
        }
Dec 7, 2014 at 1:50 PM
I was not able to solve the issue as is but I found a work around it. which is to limit the user to select the layer in which he/she want to select the features.
This means that users chooses to select from point layers or line layers and not simultaneously.
This seems to work for now.

I would appreciate if someone could help with the original issue.
Developer
Dec 7, 2014 at 5:19 PM
If you are working with a sourcecode version after commit 74998 you should be able to select points and lines at the same time.
The select function was changed a few releases ago to just select features of one layer.
Since I added the SetSelectable-plugin you can choose the layers in which you want to select. This means the select function should select points and lines at the same time.
Marked as answer by Ehsan_Ro on 12/7/2014 at 12:08 PM
Dec 7, 2014 at 7:19 PM
Thanks Jany for your response.

I am not sure if I understood you correctly but if you suggest that in the most recent commit the select function has changed in the way that it only selects features from one layer then this should be the issue with my code. I was using the latest source code and I compiled it with BruTileLayer.

if you could also take a look at my other question I would be grateful


https://dotspatial.codeplex.com/discussions/573443

Regards,
Developer
Dec 7, 2014 at 8:34 PM
No that is not what I said.

I believe that the select function was changed in Dotspatial 1.5 or 1.6. Afterwards it was impossible to select features from more than one layer.

In commit 74998 I changed the select function so that it is possible again to select features from more than one layer. Meaning using the most recent source code you should be able to select lines and points at the same time.

If you're using DotSpatial 1.7 from the download-page this change is not yet included.
Marked as answer by Ehsan_Ro on 12/7/2014 at 2:26 PM
Dec 7, 2014 at 9:26 PM
Thanks again, I used 1.7 from download page.
Will change and let your know the outcomes.

Regards
Dec 11, 2014 at 10:54 AM
Thanks Jany for your responses, much appreciated.

I replaced my DotSpatial dlls with the most recent built 75229 and the issue is solved indeed.