ThinkGeo.com    |     Documentation    |     Premium Support

QueryTools GetFeaturesNearestTo performance

Hi,


I'm using the QueryTools.GetFeaturesNearestTo, providing a PointShape.  I have ~34,000 point features loaded into my layer.


It is taking about 1.3 seconds to return the nearest features.  Since I am using this method for selection, context menus, etc, 1.3 seconds seems pretty slow.


Is there a way to speed this up?  I have tried using a QuadTree, and that hasn't seemed to help.


Usually, the user is zoomed in when they are selecting, so is there a way to reduce the query set to just the features within the displayed screen view, and then use those to query for the one closest to the PointShape I specify?  I'm thinking the QueryTools is searching through all Features, and I don't need that.  I'm thinking of a new version of GetFeaturesNearestTo like this:


GetFeaturesNearestTo(BaseShape targetShape, RectangleShape searchArea, GeographyUnit unit, int numItems, ReturningColumnTypes types)


Thanks,


Greg



Greg, 
  
 Thanks for your post. 
  
 I am in vacation so I don’t have environment to check out the detail solution, but I can give you some suggestion that you can try. 
  
 First of all, I want to know which kind of layer you use? If you use InMemoryFeatureLayer, it has a method BuildIndex to build spatial index, that can speed up. 
  
 If you fell GetFeaturesNearestTo slow, you can try to do like this: 
 first, you call GetFeaturesInsideBoundingBox to get features only in the specific extent. It will use spatial index, so this step the performance is good. 
 second, for each feature and compare the distance to specific shape. 
 finally, you can choose the shortest distance one. 
 note: this way works when the inside features are not many. 
  
 And I think your suggestion that add a new method is very good, I will discuss this with our team member. 
  
 Thanks 
 James

Hi James,


Thanks for responding during your vacation!  That was awesome.  


I'm just using a plain old FeatureLayer.  I'll try using the InMemoryFeaturLayer.


I tried to use the field, CurrentExtent, when calling GetFeaturesInsideBoundingBox, and it seems like I'm getting way too many features back, so is CurrentExtent the correct field to use to get the zoomed-in extents that the user sees on the screen?


Thanks,


Greg



Hi Greg, 
  
 You’re welcome, Help you solve your problem is my best expectation. 
  
 I think the plain old FeatureLayer is ShapeFileFeatureLayer, right? 
  
 The CurrentExtent of map control is correct which represents the world coordinate of current screen. 
 You can test and verify if it is correct or not. The true thing is the ratio of width and height must be the same, so CurrentExtent.Width/ CurrentExtent.Height == winformsMap1.Width / winformsMap1.Height 
  
 But I think the way using current extent is not very effective. My option is that you enlarge a little bit of your targetShape to a rectangle shape, and use this rectangle to GetFeaturesInsideBoundingBox, if the result collection has some item, the nearest feature must be one of them. If the collection is empty, you enlarge the rectangle shape twice, and repeat the same thing. You keep do as this steps, you always will find the nearest feature, and every step is effective. 
  
 Please let me know if you are not clear. 
  
 James