MS SQL - Uses a geometry data type to find distance significantly faster?

I have a database containing a lot of geospatial data ... basically information about 10 thousand people with coordinates for each of them.

The coordinates are currently stored as two floats for latitude and longitude, and I use the function to determine the distance between the coordinates in this record and the coordinate I pass ... mainly to sort and limit the results that I get the distance. This is roughly the code used in the function.

DECLARE @earthSphereRadiusKilometers as float
DECLARE @kilometerConversionToMilesFactor as float
SELECT @earthSphereRadiusKilometers = 6366.707019
SELECT @kilometerConversionToMilesFactor = .621371

-- convert degrees to radians
DECLARE @lat1Radians float
DECLARE @lon1Radians float
DECLARE @lat2Radians float
DECLARE @lon2Radians float
SELECT @lat1Radians = (@lat1Degrees / 180) * PI()
SELECT @lon1Radians = (@lon1Degrees / 180) * PI()
SELECT @lat2Radians = (@lat2Degrees / 180) * PI()
SELECT @lon2Radians = (@lon2Degrees / 180) * PI()

-- formula for distance from [lat1,lon1] to [lat2,lon2]
RETURN ROUND(2 * ASIN(SQRT(POWER(SIN((@lat1Radians - @lat2Radians) / 2) ,2) + COS(@lat1Radians) * COS(@lat2Radians) * POWER(SIN((@lon1Radians - @lon2Radians) / 2), 2))) * (@earthSphereRadiusKilometers * @kilometerConversionToMilesFactor), 4)

A stored procedure takes 4 or 5 seconds to start.

I noticed that SQL Azure now supports the geometry data type .. (this was not when I created the database).

, ... , , , , ?

!

+3
3

"/", , .

:

-: , , . SQL Server 2008 , . MSDN . , , , .
STDistance (STDistance ( )), , SP , lat1, lon1 lat2, lon2. , , , .

MS buzzwords, . ( SP ), . :

SQL Server 2008. , SQL .

, ( ?) :

, , ... ( Spatial Index SQL Server 2008)

, : SQL Server 2008 Spatial - ?

, : WILL . , .

: , : SQL Server 2008.

0

: " ... [] ?" , , . , .

-, , , . , , , . , , lat, . , / , float.

, :

1.) (.. UTM, National Grid State Plane), (x, y) . , : Dist (xy) = SQRT ((x2 - x1) 2 + (y2 - y1) 2) , , , .

2.) ( /), angular . WGS84, WGS84. , , . - ​​ , , . SRID, , .

, , , , .

+3

, SQL Server 2008. Lat Lng (WGS 84), (OSM EPSG: 900913), .

( ), . EPSG: 900913, , , ( ).

, SQL Server, Oracle. , , , . ( , ), , .

So the questions should be then, did you switch to the native distance function that moontear mentioned, and if so, how did it implement Microsoft? After all, calculating the distance should be much easier in a rectangular system, or am I embarrassed?

0
source

Source: https://habr.com/ru/post/1770310/


All Articles