【问题标题】:postgis: ST_Distance between two geography. Syntax errorpostgis:两个地理位置之间的 ST_Distance。语法错误
【发布时间】:2019-03-31 18:02:18
【问题描述】:

我正在尝试在我的桌子上运行它

select ST_Distance (
    select location from utenti where user_id=464,
    select location from utenti where user_id=474604
);

有一个这种类型的位置列location geography(POINT, 4326)

我遇到语法错误,但我不明白为什么。

我怎样才能实现我的目标?

例如,如果我在两个查询中为每个用户选择该列,我会得到这样的数据 "0101000020E61000001435F98F528125402AE5B512BAA34540"

并运行:

select ST_Distance(%s, %s);

它有效,但距离似乎不正确。嗯

【问题讨论】:

  • 您必须将子查询括在括号中。
  • 你可以测试这个查询:SELECT ST_Distance(a.geom, b.geom) FROM utenti a, utenti b WHERE a.user_id=464 AND b.user_id=474604;

标签: postgresql gis postgis


【解决方案1】:

正如上面 cmets 中指出的,您可以将查询重写为:

SELECT ST_Distance(a.geom, b.geom) FROM utenti a, utenti b WHERE a.user_id=464 AND b.user_id=474604; 

但是这将为您提供以度为单位的距离(因为这就是您的点存储方式)。因此,您需要将功能更改为:

SELECT ST_Distance_Sphere(a.geom, b.geom) FROM utenti a, utenti b WHERE a.user_id=464 AND b.user_id=474604; 

ST_Distance_sphere 将考虑地球的一些曲率,并返回以米为单位的距离。如果您需要绝对精度并且不担心速度,您可以使用st_distance_spheroid 来计算地球的所有曲率。

【讨论】:

    【解决方案2】:

    如果你多边形到点的距离 选择 st_distance( st_geomfromtext('POINT (0 0)'), st_geomfromtext('多边形 ((1 1, 2 1, 2 2, 1 2, 1 1))') )

    相同的基本空间几何列

    select st_distance(
        st_geomfromtext(c.geom), 
        st_geomfromtext(b.geom)
    ) from  city c , build b where b.c_ID=c.ID
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-24
      • 2014-04-12
      相关资源
      最近更新 更多