对我有以下简单的表:SQL查询点在多边形使用PostgreSQL
CREATE TABLE tbl_test
(
id serial NOT NULL,
poly polygon NOT NULL
)
WITH (OIDS=FALSE);
然后我尝试插入一行多边形:
insert into tbl_test values(1, PolyFromText('POLYGON((0 0, 10 10, 10 0, 0 0))'))
碰上这个错误:
column "poly" is of type polygon but expression is of type geometry
这是跛脚。所以我的第一个问题是:
- 我是否真的必须施放?
无论如何,铸造后它的工作原理。现在我试图做一个简单的ST_Contains查询:
select id, poly from tbl_test where ST_Contains(poly, Point(GeomFromText('POINT(9 2)')))
这给错误:
ERROR: function st_contains(polygon, point) does not exist
LINE 1: select id, poly from tbl_test where ST_Contains(poly, Point(...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
那我该怎么办?
以下工作:
select st_contains(st_geomfromtext('POLYGON((0 0, 10 10, 10 0, 0 0))'), st_geomfromtext('POINT(0 0)'))
但是,这可能是因为这两个参数的数据类型的几何形状。对表格数据的实际查询不起作用。
答:
土井!问题是我创建的数据库不是基于postgis模板数据库(因此没有相关的函数和几何列表等)。 最后,我只想说PostGIS要求您将数百个函数,行和几张表添加到您的数据库中,这样您才能拥有GIS支持是完全跛脚的。它使模式的备份变得复杂得多,而且非常容易出错(如果你忽略调用AddGeometryColumn并且只是自己添加一个几何列)那么天堂禁止。
如果在聚合物中聚合,为什么不用你想要找到的点来制作一个“1角”多边形? – 2009-06-18 13:01:54
我不确定postgres支持1点的多边形。此外,这是一个问题的解决方法,我不知道是否存在.. – 2009-06-18 13:05:35