使用PostgreSQL进行多边形点的SQL查询
我有以下简单表:
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))')) 并遇到这个错误:
哪个是蹩脚的.所以我的第一个问题是: >我真的要演员吗? 无论如何,在投射后它起作用.现在我正在尝试做一个简单的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,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,0 0))'),st_geomfromtext('POINT(0 0)')) 但这可能是因为两个参数都是Geometry类型.对表数据的实际查询不起作用. 回答: 土井!问题是我创建的数据库不是基于postgis模板DB(因此没有相关的函数和几何列表等).
多边形是PostGIS基础的基础Postgres类型.使用PostGIS函数启用几何列选择AddGeometryColumn(…).否则你正在使用直的多边形:
=> create table gt (id int,space polygon); => insert into gt values (1,'((2,2),(3,4),6),(1,1))'); INSERT 0 1 => select point(space) from gt where id = 1; point ------------- (2.25,3.25) (1 row) 这是多边形的中心点 => select circle(space) from gt where id = 1; circle -------------------------------- <(2.25,3.25),1.93994028704315> (1 row) 这是多边形的最小边界圆,表示为Postgres圆类型.所有几何运算符都记录在案here: http://www.postgresql.org/docs/8.3/interactive/functions-geometry.html基本多边形没有任何投影数据,SRID等,所以如果它与PostGIS一起使用,它可能只是默认为预设并且变得幸运.但是,当然有很多情况下你只需要子地理空间尺度的几何. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |