Note that there are some explanatory texts on larger screens.

plurals
  1. POMS SQL - Is using geometry data type to find distance significantly faster?
    primarykey
    data
    text
    <p>I have a database which contains a lot of geospatial data ... basically information on 10s of thousands of people, with coordinates for each of them. </p> <p>The coordinates are currently stored as two floats for latitude and longitude, and I use a function to determine the distance between the coordinates in that record and a coordinate I pass in ... basically to sort and limit the results I get by distance. This is roughly the code used in the function. </p> <pre><code>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) </code></pre> <p>The stored procedure is taking 4 or 5 seconds to run. </p> <p>I've noticed that SQL Azure now supports the geometry data type .. (it didn't when I created the database).</p> <p>So my question is ... would I experience a significant increase in the speed that my stored procedure would run that would make it worthwhile me investing the time it would take to change things over to using the geometry data type?</p> <p>Thanks!</p> <p>Steven</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload