- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想按距离排序,但出现错误
UndefinedFunction: ERROR: function st_distance(geography, geometry, numeric) does not exist
按 .order("ST_Distance(lonlat, ST_Geomfromtext('#{point}'), #{radius}) ")
如果我删除上面的行,它工作正常。
这是怎么回事?
scope :nearby, lambda { |radius_in_km, lon, lat|
point = GEOG_FACTORY.point(lon, lat)
radius = radius_in_km.to_f*1000
where("ST_DWithin(lonlat, ST_GeomFromText('#{point}'), #{radius} ) ")
.order("ST_Distance(lonlat, ST_Geomfromtext('#{point}'), #{radius}) ")
}
PG::UndefinedFunction: ERROR: function st_distance(geography, geometry, numeric) does not exist
LINE 1: ...4028 6.530438999999999)'), 100000.0 ) ) ORDER BY ST_Distanc...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
: SELECT "weather_logs".* FROM "weather_logs" WHERE (ST_DWithin(lonlat, ST_GeomFromText('POINT (101.3034028 6.530438999999999)'), 100000.0 ) ) ORDER BY ST_Distance(lonlat, ST_Geomfromtext('POINT (101.3034028 6.530438999999999)'), 100000.0) , "weather_logs"."datetime" ASC LIMIT 20000
Completed 200 OK in 161ms (Views: 0.2ms | ActiveRecord: 5.4ms)
最佳答案
您正在混合地理和几何类型,这就是错误消息的含义。如果您查看 ST_DWithin docs,你会看到签名是ST_DWithin (geometry, geometry, distance) 或者ST_DWithin (geography, geography, distance)。
我不太了解 Ruby,所以我不确定是否有一个 GEOM_Factory
与您使用的 GEO_Factory
等效,但是如果您使用 ST_GeogFromText而不是在您的 where 和 order by 子句中使用 ST_GeomFromText
,那么您将处理两个地理区域,这应该可以解决您的问题。
由于您的坐标是纬度/经度 4326,因此使用地理数据类型是合适的。如果您想了解更多关于几何与地理学的实用性,请参阅 this gis.stackexchange question .
关于postgresql - UndefinedFunction : ERROR: function st_distance(geography, 几何、数字)不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26935060/
在 Cosmos DB 中,ST_DISTANCE 函数返回值的单位是什么? docs在这方面没有帮助: Returns the distance between the two GeoJSON Po
在 Cosmos DB 中,ST_DISTANCE 函数返回值的单位是什么? docs在这方面没有帮助: Returns the distance between the two GeoJSON Po
我在 postgis 中遇到 st_distance 函数的问题。它返回错误的结果——对于小距离,误差不大——10 米,也许 20 米,但对于更大的距离,我的结果与例如谷歌地图结果之间的差异太大——7
我正在尝试找出一种将 presto 地理空间函数 ST_DISTANCE 的结果转换为米的方法。 如果我运行此示例查询: 选择 ST_Distance(ST_Point(0.3476, 32.5825
我怎样才能在 postgresql 中运行这个查询并让它工作? SELECT ST_Distance( SELECT coordinates FROM points WHERE id = 1, ST_
我正在运行一个包含大量公司地址表的数据库服务器。连接到它的应用程序接收用户坐标和他们正在寻找的业务类型,并返回离该用户最近的业务。 最初,我的应用程序使用一个简单的 SELECT 语句来查找最近的企业
我有一个多边形类型的几何体,我正在使用 postgis 的 ST_Distance 方法计算 POINT 的最小距离,它可能在多边形几何体内部(由 360 个点组成封闭几何体)或在多边形几何体外部,我
我正在使用 postgis 来计算 2 个地理坐标之间的距离。 select st_distance( 'POINT(15.651955 73.712769)'::geography, 'PO
我正在使用以下查询从 postgresql 数据库中检索记录 @services = Service.select("*, ST_Distance(services.lon_lat, ST_GeomF
我看过关于此主题的类似帖子(例如,参见 here 和 here),但不是特定于 sf-tidyverse 生态系统的帖子。 我有一系列湖泊,每个湖泊内有一系列样本点,每个湖泊中都有一个“焦点”,表示船
我们正在开发一个应用程序,该应用程序涉及根据存储在 PostgreSQL 表中的多边形计算给定点的最短距离。 我们正在使用 PostgreSQL 数据库中的 ST_Distance 函数。 当我们将计
我写了这个查询并且它有效,虽然它有点慢: SELECT name, (ST_Distance( ST_Transform( way,900913 ),ST_Transform( ST_GeomFrom
我想找到区域点和我的点之间的最小距离。我搜索它并找到 ST_CONTAIN ,但是当我使用这个函数时,我得到一个错误: Expected known function, got 'ST_Distanc
我有一个规划应用程序表,我正在尝试将最近的 5 个应用程序返回到一个属性,通过 PHP 返回的 Postgres 查询按最近到最远的距离排序作为 JSON 数组。 结果已成功返回,但它们的排序似乎不正
我想使用 hibernate 对距离进行排序,但“st_distance”不起作用。日志: ----- org.hibernate.QueryException: No data type for n
我的数据库中有一个表,它存储谷歌地图中的位置以及它们返回的坐标。之前我将 lat 和 lng 存储为小数点,在我将 MySQL 版本升级到 8 后,发现有预定义的数据类型和函数来处理坐标和距离计算。我
我想按距离排序,但出现错误 UndefinedFunction: ERROR: function st_distance(geography, geometry, numeric) does not
我正在开发一个使用 PostgreSQL 作为数据库的应用程序;我的目标是以地理格式存档多边形数据,以便在进行查询时使用 pgAdmin OpenStreetMap 集成轻松可视化它们。我的问题是,当
根据文档和其他问题,按距离对 GeoQuerySet 进行排序应该很简单,但我无法让它正常工作。下面举例说明问题的情况: 假设我在两个不同的应用程序中有两个模型。 appA 中的一个模型和 appB
我是一名优秀的程序员,十分优秀!