我正在尝试使用英国国家网格坐标为多边形创建一个质心 以下是我的代码
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)'));
为什么这不起作用的任何想法?
答案 0 :(得分: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))'))
... SO
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))')));
答案 1 :(得分:0)
如果错误是“解析错误 - 无效几何”,那么您的几何定义无效,需要修复它。
尝试分离几何体并执行SELECT以查看哪一个是错误的。我猜它是ST_Centroid的参数。
哦 - 然后,将PostgreSQL升级到至少 8.3.23 - 这仍然是不受支持的,但至少它有所有的bug修复。理想情况下升级到9.2。
如果您无法升级,请查看是否无法从此项目中删除 - 如果数据库损坏,那么您可能最终会对此负责。