# GetFeaturesNearestTo is not working properly when FeatureIdsToExclude is set

**URL:** <https://community.thinkgeo.com/t/getfeaturesnearestto-is-not-working-properly-when-featureidstoexclude-is-set/1229>\
**Category:** WinForms\
**Created:** [May 13, 2010, 12:39pm UTC](https://community.thinkgeo.com/t/getfeaturesnearestto-is-not-working-properly-when-featureidstoexclude-is-set/1229 "2010-05-13T12:39:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ching](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@Ching](https://community.thinkgeo.com/u/Ching)\
**Post date:** [May 13, 2010, 12:39pm UTC](https://community.thinkgeo.com/t/getfeaturesnearestto-is-not-working-properly-when-featureidstoexclude-is-set/1229/1 "2010-05-13T12:39:24Z")

</div>

Hi,

I&nbsp;am&nbsp;setting&nbsp;shape&nbsp;file's&nbsp;FeatureSource.FeatureIdsToExclude&nbsp;to&nbsp;add&nbsp;some&nbsp;feature&nbsp;ids&nbsp;to&nbsp;exclude&nbsp;some&nbsp;features&nbsp;when&nbsp;I&nbsp;load&nbsp;the&nbsp;shape&nbsp;file.&nbsp;On&nbsp;the&nbsp;map,&nbsp;I&nbsp;have&nbsp;a&nbsp;map\_click&nbsp;event&nbsp;to&nbsp;highlight&nbsp;the&nbsp;closest&nbsp;feature&nbsp;that&nbsp;near&nbsp;the&nbsp;point&nbsp;user&nbsp;clicked&nbsp;on.

It&nbsp;has&nbsp;been&nbsp;working&nbsp;&nbsp;fine&nbsp;if&nbsp;this&nbsp;property&nbsp;is&nbsp;not&nbsp;set.&nbsp;However,&nbsp;when&nbsp;some&nbsp;featureIds&nbsp;added&nbsp;to&nbsp;FeatureIdsToExclude,&nbsp;GetFeaturesNearestTo&nbsp;is&nbsp;not&nbsp;working&nbsp;properly.&nbsp;It's&nbsp;always&nbsp;at&nbsp;specific&nbsp;features&nbsp;on&nbsp;the&nbsp;map&nbsp;I&nbsp;click,&nbsp;GetFeaturesNearestTo&nbsp;function&nbsp;is&nbsp;returning&nbsp;0&nbsp;feature.&nbsp;It&nbsp;is&nbsp;happenning&nbsp;like&nbsp;for&nbsp;5%&nbsp;of&nbsp;the&nbsp;features&nbsp;on&nbsp;the&nbsp;map.&nbsp;By&nbsp;the&nbsp;way,&nbsp;every&nbsp;features&nbsp;in&nbsp;this&nbsp;shape&nbsp;file&nbsp;layer&nbsp;is&nbsp;PointShape.&nbsp;If&nbsp;I&nbsp;use&nbsp;GetFeaturesWithinDistanceOf&nbsp;function,&nbsp;it's&nbsp;returnning&nbsp;the&nbsp;features&nbsp;that&nbsp;were&nbsp;having&nbsp;problem&nbsp;in&nbsp;GetFeaturesNearestTo&nbsp;function,&nbsp;but&nbsp;I&nbsp;don't&nbsp;want&nbsp;to&nbsp;use&nbsp;this&nbsp;function&nbsp;because&nbsp;it&nbsp;is&nbsp;not&nbsp;returning&nbsp;the&nbsp;closest&nbsp;feature.

I&nbsp;have&nbsp;tried&nbsp;the&nbsp;extension&nbsp;method&nbsp;in&nbsp;the&nbsp;other&nbsp;post&nbsp;that&nbsp;allow&nbsp;you&nbsp;to&nbsp;pass&nbsp;distance&nbsp;parameter&nbsp;to&nbsp;GetFeaturesNearestTo&nbsp;function,&nbsp;it&nbsp;is&nbsp;also&nbsp;having&nbsp;the&nbsp;same&nbsp;problem.

Any&nbsp;idea&nbsp;how&nbsp;to&nbsp;fix&nbsp;this?

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [May 13, 2010, 10:03pm UTC](https://community.thinkgeo.com/t/getfeaturesnearestto-is-not-working-properly-when-featureidstoexclude-is-set/1229/2 "2010-05-13T22:03:45Z")

</div>

Ching,

Thanks&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;questions.  
&nbsp;  
For&nbsp;the&nbsp;featuresIdsToExclude&nbsp;property&nbsp;,if&nbsp;you&nbsp;add&nbsp;some&nbsp;Ids&nbsp;to&nbsp;it,&nbsp;the&nbsp;final&nbsp;result&nbsp;of&nbsp;query&nbsp;will&nbsp;filter&nbsp;out&nbsp;those&nbsp;ids.&nbsp;So&nbsp;for&nbsp;the&nbsp;API&nbsp;GetFeaturesNearestTo&nbsp;function,&nbsp;its&nbsp;returning&nbsp;result&nbsp;may&nbsp;not&nbsp;equals&nbsp;to&nbsp;numberOfItemsToFind.&nbsp;See&nbsp;following&nbsp;examples:  
  
&nbsp;  
`InMemoryFeatureLayer inmemorFeatureLayer = new InMemoryFeatureLayer();inmemorFeatureLayer.InternalFeatures.Add(new Feature(0, 0,"Point1"));inmemorFeatureLayer.InternalFeatures.Add(new Feature(0, 10,"Point2"));inmemorFeatureLayer.InternalFeatures.Add(new Feature(20, 10,"Point3"));inmemorFeatureLayer.InternalFeatures.Add(new Feature(20, 0, "Point4"));inmemorFeatureLayer.Open();Collection<Feature> allFeatures1 = inmemorFeatureLayer.QueryTools.GetFeaturesNearestTo(new PointShape(20, 9), GeographyUnit.DecimalDegree, 1, ReturningColumnsType.NoColumns);if (allFeatures1.Count > 0){    // Return "PointShape3"    PointShape pointShape = (PointShape) allFeatures1[0].GetShape();} inmemorFeatureLayer.FeatureIdsToExclude.Add("Point3");inmemorFeatureLayer.FeatureIdsToExclude.Add("Point1");Collection<Feature> allFeatures2 = inmemorFeatureLayer.QueryTools.GetFeaturesNearestTo(new PointShape(20, 9), GeographyUnit.DecimalDegree, 1, ReturningColumnsType.NoColumns);// Return number is 0.if (allFeatures2.Count > 0){                PointShape pointShape = (PointShape)allFeatures2[0].GetShape();} Collection<Feature> allFeatures3 = inmemorFeatureLayer.QueryTools.GetFeaturesNearestTo(new PointShape(20, 9), GeographyUnit.DecimalDegree, 2, ReturningColumnsType.NoColumns);if (allFeatures3.Count > 0){    // Return "PointShape4"    PointShape pointShape = (PointShape)allFeatures3[0].GetShape();}`  
  
Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.  
&nbsp;  
Thanks.  
&nbsp;  
Yale

---

<div class="post-metadata">

**Author:** ![Ching](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@Ching](https://community.thinkgeo.com/u/Ching)\
**Post date:** [May 14, 2010, 7:07am UTC](https://community.thinkgeo.com/t/getfeaturesnearestto-is-not-working-properly-when-featureidstoexclude-is-set/1229/3 "2010-05-14T07:07:42Z")

</div>

got&nbsp;it!&nbsp;thanks.

---

<div class="post-metadata">

**Author:** ![ThinkGeo](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/thinkgeo/32/25029_2.png) [@ThinkGeo](https://community.thinkgeo.com/u/ThinkGeo)\
**Post date:** [May 16, 2010, 7:02pm UTC](https://community.thinkgeo.com/t/getfeaturesnearestto-is-not-working-properly-when-featureidstoexclude-is-set/1229/4 "2010-05-16T19:02:27Z")

</div>

Ching,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;your&nbsp;inputs.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Any&nbsp;more&nbsp;questions&nbsp;just&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;me&nbsp;know.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Yale&nbsp;
