Simple filter expression not working

Developer
Nov 19, 2010 at 5:48 PM

DS version 377.

I have a line of code that creates simple expression filter:

List<IFeature> shps = stateFeatures.SelectByAttribute("[" + fieldStateValue + "]='" + stID + "'");

Which resolves to:

List<IFeature> shps = stateFeatures.SelectByAttribute("[st]='Al'");

 

Whenever it goes over that line of code it throws this error:

System.Collections.Generic.KeyNotFoundException was unhandled
  Message=The given key was not present in the dictionary. 

on line 1087 of FeatureSet.cs:

result.AddRange(rows.Select(dr => FeatureLookup[dr]));

The dr in that line seems to be the dataRow i'm interested in.

 

What am I doing wrong here?

 

Thanks

Aaron Parks

RTI International

 

Feb 25, 2011 at 5:41 PM

Hi Aaron,

Did you find a solution ? I'm encoutering same problem.

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

Developer
Feb 25, 2011 at 5:49 PM

I have never been able to get this to work.  Have a look at bug 161 to see the discussion.

 

Aaron Parks

RTI International

Developer
Feb 25, 2011 at 5:50 PM

Try it without the square brackets around the field name, e.g.

List<IFeature> shps = stateFeatures.SelectByAttribute("st='Al'");

Kurt

Feb 25, 2011 at 6:11 PM
Edited Feb 26, 2011 at 1:17 PM

Thanks for your answers.

Kurt, I got the same result with or without square brackets.


Feb 26, 2011 at 1:18 PM

After more investigations, I found that the problem seems to come from featurelookup table that has no key. Don't understand why so far.

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

Mar 1, 2011 at 3:10 PM

I've found several bugs related to this problem; basically the DataRow in the Feature does not contain the same object reference as the DataRow in the FeatureSet used in the lookup table (FeatureLookup). 

I was to get my code working by modifying FeatureList.IncludeFeature(IFeature item) and FeatureList.Add(IFeature item) to make sure the FeatureList and IFeature always point to the same DataRow instance.  I suspect there are other code snippets that would need to be modified to completely fix the problem, but it at least worked well enough to get labeling working.

 

- Tim

Apr 12, 2011 at 3:41 PM
tgustafson wrote:

I've found several bugs related to this problem; basically the DataRow in the Feature does not contain the same object reference as the DataRow in the FeatureSet used in the lookup table (FeatureLookup). 

I was to get my code working by modifying FeatureList.IncludeFeature(IFeature item) and FeatureList.Add(IFeature item) to make sure the FeatureList and IFeature always point to the same DataRow instance.  I suspect there are other code snippets that would need to be modified to completely fix the problem, but it at least worked well enough to get labeling working.

 

- Tim

I don't understand... Can you show us pseudo - code o something like that?

Thank you!

Jun 13, 2011 at 11:11 PM

It seems that the FeatureLookup dictionary of a FeatureSet is not being populated properly.  One workaround is to loop through the features and add them to the FeatureLookup:

 

                foreach (Feature f in FeatureSet.Features)
                {
                    FeatureSet.FeatureLookup.Add(f.DataRow, f);
                }

 

 

Hope that helps.  It's a time consuming loop though.

Jun 14, 2011 at 7:40 AM
dslamb5736 wrote:

It seems that the FeatureLookup dictionary of a FeatureSet is not being populated properly.  One workaround is to loop through the features and add them to the FeatureLookup:

 

                foreach (Feature f in FeatureSet.Features)
                {
                    FeatureSet.FeatureLookup.Add(f.DataRow, f);
                }

 

 

Hope that helps.  It's a time consuming loop though.

Thank you!!!

I was thinking about it, and I think it's best to add the "featurelookupwhile adding "features".

Jun 22, 2011 at 2:34 AM

stateFeatures.SelectByAttribute("[" + fieldStateValue + "]='" + stID + "'");

you should think of your field type,if it is a string then the expression is right,else you should write the code like this:stateFeatures.SelectByAttribute("[" + fieldStateValue + "]=" + stID );