我正在使用postgresql版本:"在x86_64-unknown-linux-gnu上的PostgreSQL 9.3.1,由gcc(GCC)4.6.3 20120306(Red Hat 4.6.3-2)编译,64位"
我创建了2个表A和B,其中点和多边形作为数据类型.现在我想知道点是否在多边形内部.为此,我试图使用ST_Intersect(A.point_LatLong,B.polygon_abc); 我的查询是:
SELECT A.id
FROM A, B
WHERE A.name = 'callifornia'
AND ST_Intersect(A.point_LatLong , B.polygon_abc);
Run Code Online (Sandbox Code Playgroud)
在这里point_latLong
,并polygon_abc
在具有表A和B的数据类型点和多边形列名
但是这个查询给出了一个错误:
错误:函数st_intersect(point,polygon)不存在第
3行:WHERE city.city_name ='callifornia'和ST_intersect(city.c ...
提示:没有函数匹配给定的名称和参数类型.您可能需要添加
显式类型演员.
我怎么解决这个问题?我甚至无法在postgresql中使用任何其他空间方法,如st_contains()等,如果您有任何解决方案,请告诉我.
我试图在 Rails 应用程序中使用空间距离,但当我尝试使用 order 方法时,我不断遇到“ActiveRecord::UnknownAttributeReference: 使用非属性参数调用的查询方法”错误。
这是我的代码:
def nearby_locations
third_party_location_query = ThirdPartyLocation.where(id: id).select('geom').to_sql
third_party.organisation.locations.active.
select("locations.*, ROUND(ST_DistanceSphere(locations.geom, (#{third_party_location_query}))::numeric, 0)::integer distance").
order("locations.geom <-> (#{third_party_location_query})").
limit(10).as_json(methods: [:distance])
end
Run Code Online (Sandbox Code Playgroud)
我知道该错误是由于将非属性值传递给 order 方法而引起的,但我不确定在这种情况下如何避免它。如何在查询中使用空间距离而不会遇到此错误?
我有一组line和polygon对象(SqlGeometry类型)和一个点对象(SqlGeometry类型).如何从给定的点对象中找到每条线上最近的点?有没有用于执行此操作的API?
我在SDO_INSIDE
and之间有这种混淆SDO_CONTAINS
,难道这两个查询都需要返回相同的结果吗?
我正在尝试执行 Postgres 查询:
SELECT a.a_geom
FROM a
WHERE
ST_within(a.a_geom::geometry,ST_GeomFromText('Polygon((1,1),(4,1),(4,4),(4,1))'));
Run Code Online (Sandbox Code Playgroud)
但是这个查询给出了错误:
错误:解析错误 - 无效的几何
SQL 状态:XX000
提示:“多边形((1,1”<--解析几何中位置 12 处的错误)