Pregunta

I am trying to insert a polygon shape in a mysql database. Vertices of Polygon shapes consist of double values. To insert the value I have tried with the following query. But I got the following as my error.

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)));

TABLE DESCRIPTION

+------------------------+--------------+------+-----+---------+----------------+
| 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    |                |
+------------------------+--------------+------+-----+---------+----------------+

THE ERROR :_:

ERROR 1367 (22007): Illegal non geometric '10.12345612341243' value found during parsing

Regards, ArunRaj.

¿Fue útil?

Solución

Solved the issue. Stored Decimal value successfully. I have done two mistakes.

1 ) LineString can only store Points datatype (Not the decimal values or coordinates). Corrected syntax follows.

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 ) If it is a polygon shape. The shape has to be closed ( Starting and Ending point should be the same ). That was the problem.

WORKING QUERY

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))));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top