I'm new to postgresql/postgis and trying to measure a distance. So st_distance()
may be the most accurate, it's the slowest too (as I've read). I read that one can use geometric (instead of geographic) measuring with less accuracy, but the numbers I get don't make sense. This is what I've got:
(all points are geography(Point,4326))
select
st_astext(point),
st_astext(point2),
round(st_distance(point, point2)),
round(point::geometry <#> point2::geometry) -- cast to geometry and use distance operator
from testgeo2 limit 50
"POINT(53.887 54.043)","POINT(70.764 80.922)","3053406","32" -- ok
"POINT(93.262 59.546)","POINT(84.331 84.334)","2774883","26" -- ok
"POINT(99.624 67.098)","POINT(95.718 85.252)","2027908","19" -- ok
"POINT(54.406 84.531)","POINT(80.27 83.385)", "326308","26" -- hm?!
So I don't get how this can be right. Any suggestions?
One more example
-- new york, tokyo
insert into testgeo2(point, point2) values (
st_geographyfromtext('point(-74.007873 40.717602)'),
st_geographyfromtext('point(139.754333 35.675853)'))
-- get distance
select
st_astext(point),
st_astext(point2),
-- km, most accuracy
round(st_distance(point, point2)) / 1000,
-- km, with less accuracy
round(st_distance(point, point2, false)) / 1000,
-- km, Lambert
round(st_distance(
st_transform(point::geometry, 3587),
st_transform(point2::geometry, 3587))) / 1000,
-- km, from degree
round(point::geometry <#> point2::geometry) * 111
from testgeo2
-- results
POINT(-74.007873 40.717602) POINT(139.754333 35.675853),
10871, 10847, 11224, 23754
is geometry just not working on a larger scale?
geometry
vs.geography
type behaviour, read more about it here