繁体   English   中英

使用填充有PostGIS WKB坐标的Postgres array []会导致“函数st_dwithin(文本,几何,整数)不是唯一的”

[英]Using a Postgres array[] filled with PostGIS WKB coordinates results in “function st_dwithin(text, geometry, integer) is not unique”

我正在使用Postgres 9.1和PostGIS 2。

示例查询不起作用

SELECT
  *
FROM measurement m
JOIN (SELECT unnest(array['002000000100000000404ff25e353f7cee401d01da7b0b3919']) AS p) AS ps
  ON ST_DWithin(ps.p, m.groundtruth, 5)

示例查询有效

SELECT
  *
FROM measurement m
JOIN (SELECT 1) AS foo
  ON ST_DWithin('002000000100000000404ff25e353f7cee401d01da7b0b3919', m.groundtruth, 5)

也可行

SELECT unnest(array['002000000100000000404ff25e353f7cee401d01da7b0b3919'])

但是,当然,我需要数组正常工作的查询。

我从Rails调用此查询,该查询会自动插入WKB格式(意味着:如果重要的话,我不知道如何将其更改为WKT)。

完整的示例Rails代码如下所示:

x = [RGeo::Geos.factory.point(63.8935, 6.25181)]
@measurement = Measurement.find_by_sql([radius_search_query, x])

def radius_search_query
  SELECT
    *
  FROM measurement m
  JOIN (SELECT unnest(array[?]) AS p) AS ps
    ON ST_DWithin(ps.p, m.groundtruth, 5)
end

但是我也从上面测试了该查询(不使用? ),并且由于相同的错误消息而不断失败:

ERROR:  function st_dwithin(text, geometry, integer) is not unique
LINE 5:       ON ST_DWithin(ps.p, m.groundtruth, 5)
                 ^
HINT:  Could not choose a best candidate function. You might need to add explicit type casts.

我以为我可能不得不告诉数组它是geometry类型而不是text类型(如错误消息中所示)。 但是我还没有找到一种方法。

谢谢!!


更多信息:

这不起作用:

SELECT
  *
FROM measurement m
JOIN (SELECT '002000000100000000404ff25e353f7cee401d01da7b0b3919' as bar) AS foo
  ON ST_DWithin(foo.bar, m.groundtruth, 5)

错误消息: failed to find conversion function from unknown to geometry

这有效:

SELECT
  *
FROM measurement m
JOIN (SELECT '002000000100000000404ff25e353f7cee401d01da7b0b3919'::geometry(Point) as bar) AS foo
  ON ST_DWithin(foo.bar, m.groundtruth, 5)

在我找到一种解决方案后,使查询变得非常慢(由于强制转换值):

SELECT
  *
FROM measurement m
JOIN (SELECT unnest(array['002000000100000000404ff25e353f7cee401d01da7b0b3919']) AS p) AS ps
  ON ST_DWithin(ps.p::geometry(Point), m.groundtruth, 5)

我环顾四周,偶然发现PostGIS的linestring 现在一切正常!

SELECT
  *
FROM ST_DumpPoints('00200000020000000000000002404ff25e353f7cee401901da7b0b3919404ff25e353f7cee401d01da7b0b3919') AS ps
JOIN measurement m
  ON ST_DWithin(ps.geom, m.groundtruth, 5)

好极了! :-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM