This project is read-only.

Distance calculations in metres

Topics: Developer Forum, User Forum
Apr 13, 2007 at 8:10 AM
Hello, is it possible to return the distance in a specified unit of measure?

I've got data for Australia stored in GDA1994 (SRID=4283) - but i don't want to deal with distances in decimal degrees...because they don't mean much to the average person

I can get the distance in metres if I transform to SRID=28354 - (a UTM metre based projection). However i can't get this to work in a table valued function

the following code works and gives me the distance from all the places to Melbourne

DECLARE @point varbinary(max)
SELECT NAME, ST.Distance(ST.Transform(PLACES.thegeom, 28354), ST.Transform(@point, 28354)) AS distm FROM dbo.PLACES

SELECT FROM ST.IsWithinDistanceQuery('PLACES', 'the_geom', @point, 0.05) as dist
inner join dbo.PLACES pl on pl.oid = dist.oid

this gives me a list of all the places within 0.05 degrees from Melbourne (assuming @point is the same variable as before)

Is it possible to modify the 0.05 so that i can enter a distance in metres? Or do I need to reproject all my source data into a metre based projection system?

It would be great if i could do something like this

SELECT FROM ST.IsWithinDistanceQuery('PLACES', 'the_geom', @point, 10, 'km') as dist
inner join dbo.PLACES pl on pl.oid = dist.oid
Apr 13, 2007 at 8:27 AM
You shouldn't measure distances in UTM, unless you are very careful and incorporate the scale-distortion of UTM, especially if you measure over great distances, or are far away from the center of the two places where the scale distortion are zero. Instead, you should use the long/lat values on the from and to points to calculate the distance using spherical coordinates. There's plenty of webpages that describe the formulas for doing this (google for it).