0

我正在尝试使用英国国家网格坐标为多边形创建质心下面是我的代码

CREATE TABLE PROJECT.CINEMAS
(CINEMA_ID INTEGER NOT NULL,
CINEMA_NAME VARCHAR(25) NOT NULL,
ADDRESS_NUMBER INTEGER NOT NULL,
POST_CODE VARCHAR(8) NOT NULL,
STREET VARCHAR (25) NOT NULL,
TOWN VARCHAR (25) NOT NULL,
OPENING_TIME TIME NOT NULL,
CLOSING_TIME TIME NOT NULL,
);

/* Add a geometry column containing point coordinates*/ 

SELECT ADDGEOMETRYCOLUMN('project','cinemas', 'COORDINATES_GEOM', '27700','POLYGON',2);

/* Create a cinema centroid geometry column

SELECT ADDGEOMETRYCOLUMN('project','cinemas', 'CENTROID', '27700','POINT',2);

INSERT INTO PROJECT.CINEMAS 
VALUES
(1,'ODEON LEICESTER SQUARE', 24, 'WC2H 7LQ', 'LEICESTER SQUARE', 'LONDON', '11:00:00 AM','11:00:00 PM',GeometryFromText('POLYGON((529901 180738,529944 180745, 529947 180717, 529906 180710, 529905 180719,529902 180718,529900 180727,529903 180729,529901 180738)',27700),ST_Centroid('POLYGON((529901 180738,529944 180745, 529947 180717, 529906 180710, 529905 180719,529902 180718,529900 180727,529903 180729,529901 180738)'));

任何想法为什么这不起作用?

4

2 回答 2

1

几件事情,

您忘记了 POLYGON 字符串中的关闭 )

应该

GeometryFromText('POLYGON((529901 180738,529944 180745, 529947 180717, 529906 180710, 529905 180719,529902 180718,529900 180727,529903 180729,529901 180738))',27700)

在将值传递给 st_centroid 函数之前,您需要将多边形字符串转换为几何图形

ST_Centroid(GeometryFromText('POLYGON((529901 180738,529944 180745, 529947 180717, 529906 180710, 529905 180719,529902 180718,529900 180727,529903 180729,529901 180738))'))

所以...

INSERT INTO PROJECT.CINEMAS 
VALUES (1,'ODEON LEICESTER SQUARE', 24, 'WC2H 7LQ', 'LEICESTER SQUARE', 'LONDON', '11:00:00 AM','11:00:00 PM',
GeometryFromText('POLYGON((529901 180738,529944 180745, 529947 180717, 529906 180710, 529905 180719,529902 180718,529900 180727,529903 180729,529901 180738))',27700), 
ST_Centroid(GeometryFromText('POLYGON((529901 180738,529944 180745, 529947 180717, 529906 180710, 529905 180719,529902 180718,529900 180727,529903 180729,529901 180738))')));
于 2013-02-15T17:49:51.563 回答
0

如果错误是“解析错误 - 无效几何”,那么您的几何定义无效并且需要修复它。

尝试分离出您的几何图形并执行 SELECT 以查看哪个是错误的。我猜这是 ST_Centroid 的参数。

哦 - 然后,将 PostgreSQL 升级到至少8.3.23 - 这仍然不受支持,但至少它得到了所有的错误修复。理想情况下升级到 9.2。

如果你不能升级,看看你是否不能从这个项目中删除——如果数据库损坏,那么大概你最终会负责。

于 2013-02-15T17:41:41.153 回答