简体   繁体   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”

I'm using Postgres 9.1 and PostGIS 2. 我正在使用Postgres 9.1和PostGIS 2。

Example query which doesn't work : 示例查询不起作用

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

Example query which works : 示例查询有效

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

And this works, too : 也可行

SELECT unnest(array['002000000100000000404ff25e353f7cee401d01da7b0b3919'])

But of course I need the query with the array working. 但是,当然,我需要数组正常工作的查询。

I call this query from Rails which automatically inserts WKB format (means: I don't know how to change it to WKT, if that's important). 我从Rails调用此查询,该查询会自动插入WKB格式(意味着:如果重要的话,我不知道如何将其更改为WKT)。

The complete sample Rails code looks like this: 完整的示例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

But I've also tested the query from above (without use of ? ) and it keeps failing with the same error message: 但是我也从上面测试了该查询(不使用? ),并且由于相同的错误消息而不断失败:

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.

I thought that I maybe have to tell the array that it's of type geometry and not text (as displayed in the error message). 我以为我可能不得不告诉数组它是geometry类型而不是text类型(如错误消息中所示)。 But I haven't found a way to do this. 但是我还没有找到一种方法。

Thank you!! 谢谢!!


More information: 更多信息:

This doesn't work: 这不起作用:

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

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

This works: 这有效:

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

After I just found one solution which made the query pretty slow (because of casting values): 在我找到一种解决方案后,使查询变得非常慢(由于强制转换值):

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

I looked around and stumbled across PostGIS' linestring . 我环顾四周,偶然发现PostGIS的linestring And now everything is working! 现在一切正常!

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

Yay! 好极了! :-) :-)

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

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