Search code examples
sql-serverc#-3.0geospatialquadtree

Spatial Indexing


I want to create a large database of GPS coordinates that can be queried by saying "Return all coordinates that are within 'n' metres of [this coordinate]".

I would like to know how to implement Quadtree Indexing in Sqlserver2008?

I want to write a .net module that calls the query which uses quad tree so that i can retrieve the objects so quickly.

How can i implement the above functionality?

Thanks in advance


Solution

  • CREATE TABLE mytable (id INT NOT NULL, mypoint GEOGRAPHY NOT NULL, ...)
    
    CREATE SPATIAL INDEX SX_mytable_mypoint ON mytable (mypoint)
    
    SELECT  *
    FROM    mytable
    WHERE   mypoint.STDistance(geography::STGeomFromText(N'POINT (latitude longitude)', 4326) <= @N