ThinkGeo.com    |     Documentation    |     Premium Support

Feature Request for GetFeaturesNearestTo

Hello,


I'm using GetFeaturesNearestTo to retrieve the nearest features to a point within a layer to do a type of basic reverse geocoding.


But, since my layer is big and there a lot of features within it, if the point is far away from any feature, the search time increases without bound. I would like to limit the cost of this search. As far I am aware currently there is no way to do this.


What about a maximum search distance parameter ? This way I could have some control over the search.


First I would call it with a search radius of let's say 50 meters and if I'm not satisfied with the result I could widen the radius. Then I would know that it is not trying find a nearest feature 15 kilometers away from the point.


If I don't want to limit the search, I could just give a very big number and be done with it.


In short, I would like a cross between GetFeaturesNearestTo and GetFeaturesWithinDistanceOf.


What do you think about this, is this possible in short while ?


Regards,




Hakan Çelik






 


Hakan, 


I think that's a good suggestion and very useful. I will report it to the design team and see if we can add an overload with the “length limits”.


 With the scalability of .NET, you can add an overload yourself very easily. You can check whether there are records within that “length limits” first and then get the nearest one. One thing to remind is that it is accurate to use circle to check if there is any records inside certain distance, but I think it's better if we use the rectangleShape, which will be very fast with the Rtree index enabled.


Here is the sample code how to add it. (.Net 3.5 required)\


 



 public static class GetFeaturesExtender
    {
        public static Collection<Feature> GetFeaturesNearestTo(this FeatureSource featureSource,
            PointShape targetPointShape,
            GeographyUnit unitOfFeatureSource,
            int numberOfItemsToFind,
            ReturningColumnsType returningColumnsType,
            double distanceLimits)
        {
            RectangleShape rectangleShape = GetBoundingBox(targetPointShape, distanceLimits);
            Collection<Feature> filterFeatures = featureSource.GetFeaturesInsideBoundingBox(rectangleShape, ReturningColumnsType.NoColumns);
            if (filterFeatures.Count == 0)
            {
                return new Collection<Feature>();
            }
            else if (filterFeatures.Count < numberOfItemsToFind)
            {
                numberOfItemsToFind = filterFeatures.Count;
            }
            return featureSource.GetFeaturesNearestTo(targetPointShape, unitOfFeatureSource, numberOfItemsToFind, returningColumnsType);
        }

        private static RectangleShape GetBoundingBox(PointShape centerPoint, double radius)
        {
            return new RectangleShape(centerPoint.X - radius,
                centerPoint.Y + radius,
                centerPoint.X + radius,
                centerPoint.Y - radius);
        }
    }

Then you can use this API directly in a FeatureSource.



Thanks,


Ben


 



Ben,


Thank you very much :)


Regards,


Hakan



That’s my pleasure. :-)