ThinkGeo.com    |     Documentation    |     Premium Support

GetFeaturesNearestTo is not working properly when FeatureIdsToExclude is set

Hi,


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


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


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


Any idea how to fix this?



Ching,


Thanks for your post and questions.
 
For the featuresIdsToExclude property ,if you add some Ids to it, the final result of query will filter out those ids. So for the API GetFeaturesNearestTo function, its returning result may not equals to numberOfItemsToFind. See following examples:

 

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 more questions just feel free to let us know.
 
Thanks.
 
Yale

got it! thanks.

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