无法在Mysql 5.6中为空间数据类型存储double值

时间:2014-02-28 09:18:40

标签: mysql-5.6 hibernate-spatial

我正在尝试在mysql数据库中插入多边形。多边形形状的顶点由双精度值组成。要使用以下查询插入我尝试过的值。但我得到以下错误。

INSERT INTO HIBERNATE_SPATIAL 
(PRD_GEO_REGION_ID,OWNER_ID,GEO_REGION_NAME,GEO_REGION_DESCRIPTION,GEO_REGION_DEFINITION) 
VALUES (8,1,'POLYGON8','SHAPE8',Polygon(LineString(10.12345612341243,11.12345612341234),LineString(10.34512341246,11.4123423456),LineString(10.31423424456,11.34123423456),LineString(10.341234256,11.3412342456),LineString(10.11423423456,11.123424)));

表格说明

+------------------------+--------------+------+-----+---------+----------------+
| Field                  | Type         | Null | Key | Default | Extra          |
+------------------------+--------------+------+-----+---------+----------------+
| PRD_GEO_REGION_ID      | int(11)      | NO   | PRI | NULL    | auto_increment |
| OWNER_ID               | decimal(3,0) | NO   |     | NULL    |                |
| GEO_REGION_NAME        | varchar(50)  | NO   | UNI | NULL    |                |
| GEO_REGION_DESCRIPTION | varchar(70)  | YES  |     | NULL    |                |
| GEO_REGION_DEFINITION  | geometry     | YES  |     | NULL    |                |
+------------------------+--------------+------+-----+---------+----------------+

错误:_:

ERROR 1367(22007):解析期间发现非法非几何'10 .12345612341243'值

此致 ArunRaj。

1 个答案:

答案 0 :(得分:1)

解决了这个问题。存储的十进制值成功。我犯了两个错误。

1)LineString只能存储Points数据类型(不是十进制值或坐标)。修正后的语法如下。

INSERT INTO HIBERNATE_SPATIAL 
(PRD_GEO_REGION_ID,OWNER_ID,GEO_REGION_NAME,GEO_REGION_DESCRIPTION,GEO_REGION_DEFINITION) 
VALUES (8,1,'POLYGON8','SHAPE8',Polygon(LineString(POINT(10.12345612341243,11.12345612341234)),LineString(POINT(10.34512341246,11.4123423456)),LineString(POINT(10.31423424456,11.34123423456)),LineString(POINT(10.341234256,11.3412342456)),LineString(POINT(10.11423423456,11.123424))));

2)如果是多边形。 必须关闭形状(起点和终点应相同)。   这就是问题所在。

工作查询

INSERT INTO HIBERNATE_SPATIAL 
(PRD_GEO_REGION_ID,OWNER_ID,GEO_REGION_NAME,GEO_REGION_DESCRIPTION,GEO_REGION_DEFINITION) 
VALUES (8,1,'POLYGON8','SHAPE8',Polygon(LineString(POINT(10.12345612341243,11.12345612341234)),LineString(POINT(10.34512341246,11.4123423456)),LineString(POINT(10.31423424456,11.34123423456)),LineString(POINT(10.341234256,11.3412342456)),LineString(POINT(10.12345612341243,11.12345612341234))));