sql - 为 PostGIS 编写原始 SQL

标签 sql spatial postgis postgresql

我正在尝试使用 PostGIS 模板将一些数据输入到 PostgreSQL 8.4 数据库中。我无法更新多边形:

> UPDATE my_table SET coords = POINT(1, 1)
UPDATE 0 1

> UPDATE my_table SET box = POLYGON(((1, 1), (2, 3), (3, 3), (1, 1)))
ERROR:  function polygon(record) does not exist

> UPDATE my_table SET box = POLYGON((1, 1), (2, 3), (3, 3), (1, 1))
ERROR:  function polygon(record, record, record, record) does not exist

> UPDATE my_table SET box = POLYGON(1, 1, 2, 3, 3, 3, 1, 1)
ERROR:  function polygon(numeric, numeric, numeric, numeric, numeric, numeric, numeric, numeric) does not exist

> UPDATE my_table SET box = ((1, 1), (2, 3), (3, 3), (1, 1))
ERROR:  column "box" is of type polygon but expression is of type record

如何插入多边形?请注意,数据已存在于表中,并且用 NULL 字段代替了空间数据。我需要 UPDATE,而不是 INSERT,但这不会有什么不同。

最佳答案

你应该使用 Geometry constructors在表中加载新几何图形,特别是 St_GeomFromText功能:

UPDATE my_table SET box = ST_GeomFromText('POLYGON ((1 1), (2 3), (3 3), (1 1))');

几何以 WKT ( Well-Known Text ) 格式定义。

关于sql - 为 PostGIS 编写原始 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3384527/

相关文章:

sql-server - SQL Server 几何 : intersection of multiple polygons

SQL几何查找半径中的所有点

python - 如何调试 : Internal Error current transaction is aborted, 命令在事务 block 结束之前被忽略

python - 在 GeoDjango 中将多多边形层与多边形相交

postgresql - Postgis最近的坐标

php - SQL查询查找有多少天的博客文章

mysql - 如何编写以下涉及子查询的 SQL 查询

javascript - 由 window.location.href 调用时 SQL 查询不起作用

r - Kest (spatstat) 中的 r 是如何计算的?

mysql - 使用 Week No 在 MySql 中获取一周的第一天