Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What units does the PostgreSQL "earthdistance" module use?

I'm guessing that the units it uses is meters (m), but it doesn't seem clear from the documentation I've found. Is this correct?

If so, just to verify, in order to convert between miles/meters, I presume these functions should do the trick:

public static function mi2m($mi) {  // miles to meters
    return $mi * 1609.344;
}
public static function m2mi($m) {  // meters to miles
    return $m * 0.000621371192;
}
like image 736
Matt Huggins Avatar asked Mar 01 '23 03:03

Matt Huggins


2 Answers

The documentation seems unambiguous. Most of the module uses metres by default. But you can change that to any units you like by modifying a single function, earth. Presumably all the other functions use this function so your units are able to be arbitrary if this is overriden.

Note though that the point <@> point operator always works in miles, and this can't be adjusted.

Your conversion functions are correct, but that's easy to check as well:

  • 1 mile in metres
  • 1 metre in miles
like image 73
ire_and_curses Avatar answered Mar 05 '23 16:03

ire_and_curses


The radius of the Earth is obtained from the earth() function. It is given in meters

If the radius of the Earth is in meters, I'm gonna guess that your math is going to be wrong unless you also use meters.

like image 44
Ana Betts Avatar answered Mar 05 '23 16:03

Ana Betts