How to insert data inside a polygon column in mysql table

wrrgggsh  于 2022-12-22  发布在  Mysql
关注(0)|答案(1)|浏览(116)

How can i insert a geo co-ordinates data inside a polygon field in mysql , Here is a sample query am using for test

INSERT INTO `zones` (`polygon`) VALUES 
('POLYGON(34.44 33.56,32.22 31.34,30.23 26.33,34.44 33.56)')

I keep getting this error when i try to submit the query #1416 - Cannot get geometry object from data you send to the GEOMETRY field

jchrr9hc

jchrr9hc1#

You need to convert the string to proper statial typ in your case ST_GeomFromText

CREATE TABLE zones (`polygon` GEOMETRY);
INSERT INTO `zones` (`polygon`) VALUES 
(ST_GeomFromText('POLYGON((34.44 33.56,32.22 31.34,30.23 26.33,34.44 33.56))'))
SELECT * FROM zones
polygon
0000000001030000000100000004000000b81e85eb5138414048e17a14aec740405c8fc2f5281c4040d7a3703d0a573f407b14ae47e13a3e4014ae47e17a543a40b81e85eb5138414048e17a14aec74040

fiddle

相关问题