相关疑难解决方法(0)

使用PostgreSQL进行多边形点的SQL查询

我有以下简单表:

CREATE TABLE tbl_test
(
  id serial NOT NULL,
  poly polygon NOT NULL
)
WITH (OIDS=FALSE);
Run Code Online (Sandbox Code Playgroud)

然后我尝试插入一个带有多边形的行:

insert into tbl_test values(1, PolyFromText('POLYGON((0 0, 10 10, 10 0, 0 0))'))
Run Code Online (Sandbox Code Playgroud)

并遇到这个错误:

列"poly"的类型为polygon,但expression的类型为geometry

哪个是蹩脚的.所以我的第一个问题是:

  1. 我真的要演员吗?

无论如何,在投射后它起作用.现在我正在尝试做一个简单的ST_Contains查询:

select id, poly from tbl_test where ST_Contains(poly, Point(GeomFromText('POINT(9 2)')))
Run Code Online (Sandbox Code Playgroud)

这给出了错误:

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. …
Run Code Online (Sandbox Code Playgroud)

sql gis postgresql rdbms postgis

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

gis ×1

postgis ×1

postgresql ×1

rdbms ×1

sql ×1