Distance between 2 POINTs in Postgis in srid 4326 in metres

前端 未结 3 1538
我寻月下人不归
我寻月下人不归 2021-01-31 09:58

This is probably a simple question, but I\'m not very good at PostGIS and don\'t fully grok all of this.

Basically I have a table (nodes) with a POINT colum

相关标签:
3条回答
  • 2021-01-31 10:32

    You could use ST_Transform to use meters, also remeber that not all functions are available with geography types but if you really need speed use ST_DWithin, is the fastest way. Here's an aproximation of conversions between degrees and meters:

    | places | degrees    | distance |
    | ------ | ---------- | -------- |
    | 0      | 1.0        | 111 km   |
    | 1      | 0.1        | 11.1 km  |
    | 2      | 0.01       | 1.11 km  |
    | 3      | 0.001      | 111 m    |
    | 4      | 0.0001     | 11.1 m   |
    | 5      | 0.00001    | 1.11 m   |
    | 6      | 0.000001   | 0.111 m  |
    | 7      | 0.0000001  | 1.11 cm  |
    | 8      | 0.00000001 | 1.11 mm  |
    
    0 讨论(0)
  • 2021-01-31 10:46

    Old question but you just have to cast like this: ST_Distance(p.geom::geography, u.geom::geography) where p and u are alias for two tables

    0 讨论(0)
  • 2021-01-31 10:56

    Since writing this, I have discovered the "geographic" as opposed to the "geometry" type in PostGIS, which might do exactly what I want.

    0 讨论(0)
提交回复
热议问题