ThinkGeo.com    |     Documentation    |     Premium Support

Can you find nearby features by pixel distance?

I’m trying to get the nearest feature to where a user clicked within a certain distance. I know there is layer.QueryTools.GetFeaturesWithinDistanceOf but this requires a GeographyUnit and DistanceUnit passed in. The distance won’t be a constant number here, because if the user is zoomed out all the way, and clicks near a point, the point could be 10s of thousands of feet away, whereas if they are zoomed in and click the same “pixel” distance away from the point it might only be 100 feet. Is there a way to use a pixel distance to find nearby features instead?

Hi @Dan_Weaver,

You’re on the right track. You should be able to look at using a combination of MapUtil.GetworldDistanceBetweenTwoScreenPoints and QueryTools.GetFeaturesWithinDistanceOf. So, if you wanted to search a 10 pixel radius, you could get the distance of 10 pixels on the current zoomlevel by passing in (0,0) to (0,10) to the GetWorldDistanceBetweenTwoScreenPoints and use the return distance to pass into the GetFeaturesWithinDistanceOf function.

Thanks,
John

Thanks! That was the function I was looking for. Works well!

Glad it worked out. Let us know if you need anything else @Dan_Weaver