Vitaly
Vitaly

Reputation: 145

How to calculate a distance between cities by postgis?

I'm trying to use postgis for calculate distance between cities. For example, the distance between Moscow and SPb is ~637 km (via measure distance in Google Maps). When I use postgis:

select ST_Distance(
    ST_Point(59.925632, 30.327239),
    ST_Point(55.750352, 37.615717),
    true
);

then I get 895 km

Can anyone tell me, why such an error in this measurement?

Upvotes: 0

Views: 623

Answers (1)

Leo C
Leo C

Reputation: 22449

I believe you've reversed the lat/lon in the parameters for your ST_Points:

geometry ST_Point(float x_lon, float y_lat);

More details at this PostGIS link.

Upvotes: 1

Related Questions