I have a point (lat/lng) and a collection of geofences (polygons / circles / rectangles)

Simply put, I want to know if the point is inside ANY of the geofences, it's not important which one.

I know how to solve this comparing the point against each geofence, the problem is that I'm drawing a heat map with +750000 points that needs to be checked against 800 geofences.

Needless to say, the brute-force approach of comparing each point against each geofence will not cut it.

I was thinking along the lines of drawing all the geofences in a plane (something like a raster but based on X / Y coordinates) and then see if the point touches a painted area, but looks like a long shot and I'm not math oriented enough to write ray-tracing algorithms.

All of this is beign done in SQL Server 2008 R2, no GIS library, just int (point / circle / rect) and varbinary for the polygons

How can I solve this?

  • 1
    SQL Server has built in geographic spatial queries and functions. This website (pardon the tutorial title) may be helpful for you to get up and running with different spatial queries and functions
    – GeoSharp
    Dec 6, 2016 at 19:06


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.