Feature de-selection

Developer
May 9, 2011 at 2:45 PM

I programatically select a feature for a layer on the map and it works great, but when I go to clear that selection the feature is still drawn as though it were selected.  So far I've tried:

impointl.ClearSelection();

where impointl is the layer I did the intial selection on and

MapArgs.Map.ClearSelection();

where that is the whole map.  Neither seems to have any effect.  Is there something else i need to deactivate?

 

Thanks

Aaron Parks

RTI International

May 9, 2011 at 11:08 PM

Hi Aaron,

I´m using mapwindow6 and vb 2008. When I need to clear all selecction, define my layer as feature layer, this works fine to me,

dim sel as  MapWindow.Drawing.FeatureLayer

 

sel = FindMyLayer("name of your layer")

sel.UnSelectAll()

where FindMyLayer is my function to find the layer I need to clear, I hope this con help you

I was trying to select feature programatically without success, if you can help me whit some code to do this I appreciate you in advance

Javier Serrano

 

 

 

 

May 10, 2011 at 9:41 AM

Hi, 

I am having a closely related problem. I use Mapwindow6 and Dotspacial indedendently. How can I get the index of a selected feature, or its FID, or any of its attributes. I need a unique ID from the selected feature that I could use to query an external databse.

> I am trying to read the attributes of features whenever I click on

> them (by code in C# or VB). Here is my code:

 

private void map1_SelectionChanged(object sender, EventArgs e)

 {

MapWindow.Data.IFeature feat = map1.GetFeatureLayers()[layer1].DataSet.GetFeature(index)

}

 

> the problem is that the eventArgs - e, does not give me the selected

> index of the feature that was clicked upon. If I change the value of

> 'index' above to a number, say 21, I actually get the feature with

> index of 21 and from them I could get the recordset to display on a

> form; which is really what I am interested in. PLZ help. I am stuck.

Developer
May 10, 2011 at 1:06 PM

UnselectAll does the trick.  Thanks for the tip.

 

But what then is ClearSelection() for?

 

To do the selection I hold a pointer to the IMapPointLayer I have added to the map (impointl) and have added all the features that are in it into a dictionary for quick lookup (quickSelectedLookup).  Once the user selects a row of interest from a table I get the id for the dictionary (idFromTable) and use the dictionary to lookup the feature, then use this code to select it (impointl.Select(selecteRowFeat);

 

                 IFeature selecteRowFeat=quickSelectedLookup[idFromTable];
                if (selecteRowFeat != null)
                {
                    impointl.Select(selecteRowFeat);
                }else
                {
                    MessageBox.Show("The selected ID: " + s + " does not appear to be on the map.");
                }

 

If this seems roundabout it is because I have never been able to get feature selection to work in DS.  The DS way to do the above would be something like:

impointl.SelectByAttribute("idField=87776");

However SelectByAttribute doesn't work, see:

http://dotspatial.codeplex.com/workitem/161

Also:

http://dotspatial.codeplex.com/discussions/235353

 

Aaron Parks

RTI International

May 11, 2011 at 4:30 AM

Hi Aaron, thanks for the tip to select features, I'm new user with mapwindow and don't know too much, when try to select features by atrribute got the same result, after many intents, finally it works, the tips I find are:

layer define as MapWindow.Drawing.FeatureLayer, fields between square brackets and the name most be exactly as you define in your layer with capital and small letters.

in the next code show what I do and it´s working in my project

dim layer as MapWindow.Drawing.FeatureLayer

layer = FindMyLayer("locs") 'My function to find layers

layer.SelectByAttribute("[NOM_MPIO] = '" & cboMpio.Text & "' and [NomLoc] = '" & cboLocs.Text & "'")  

layer.ZoomToSelectedFeatures()

Hope this can help you