vir*_*ual 2 postgresql postgis geospatial spatial-query spatial-index
我正在使用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()等,如果您有任何解决方案,请告诉我.
您正在尝试将PostgreSQL的内置(有限但有用)几何类型与PostGIS函数混合使用.听起来你也没有安装PostGIS.你也错了函数名,但事实ST_Intersects并非如此ST_Intersect.
首先,如果要使用PostGIS,请确保已安装,然后:
CREATE EXTENSION postgis;
Run Code Online (Sandbox Code Playgroud)
接下来,你可能会发现你实际上不能ST_Intersects用a point和a 调用polygon.PostGIS使用自己的geometry类型.它有一些PostgreSQL内部类型的转换器,但它们只是有限的.因此,使用原始几何类型调用PostGIS函数可能会导致以下错误:
postgres=# SELECT ST_Intersects( polygon( box(point(0,0), point(10,10)) ), point(5,5) );
ERROR: function st_intersects(polygon, point) does not exist
LINE 1: SELECT ST_Intersects( polygon( box(point(0,0), point(10,10))...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)
您经常需要将它们转换为PostGIS自己的geometry类型.PostGIS为大多数类型提供了一些显式的强制转换,例如:
postgres=# SELECT ST_Intersects(
polygon( box(point(0,0), point(10,10)) )::geometry,
point(5,5)::geometry
);
st_intersects
---------------
t
(1 row)
Run Code Online (Sandbox Code Playgroud)
所以在你的查询中,那将是:
ST_Intersects(A.point_LatLong::geometry , B.polygon_abc::geometry);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2202 次 |
| 最近记录: |