PHP MySQL – How to Add a Polygon in MySQL Database

MySQLPHP

I have a table which contains an field zoneShape of the type Polygon.

When inserting some geometry in this field, in phpmyadmin it says: affected 1 row. The row is added, but the geometry field says it's size is 0B. Which can't be accurate, cause it has multiple points.

This is the Insertion code:

SET @g = 'POLYGON(50.866753 5.686455, 50.859819 5.708942, 50.851475 5.722675, 50.841611 5.720615, 50.834023 5.708427, 50.840744 5.689373, 50.858735 5.673923, 50.866753 5.686455)';
INSERT INTO zone SET zoneShape = PolygonFromText(@g)

As you can see; the first and last point are the same, so the polygon is closed.

Can anyone help me with adding this polygon to the database?
Thanx

Best Answer

Try changing your Polygon WKT to this (note the extra parens):

POLYGON((50.866753 5.686455, 50.859819 5.708942, 50.851475 5.722675, 50.841611 5.720615, 50.834023 5.708427, 50.840744 5.689373, 50.858735 5.673923, 50.866753 5.686455))

That's off the cuff and I haven't tried it yet, but well-formed WKT for Polygons has to support both the outer and inner rings (aka "islands", aka "holes"). I see your text there isn't supporting convention for inner rings --even though you don't have any. So you may just need to add these extra parens. If that doesn't work, I'll return later and take another look, assuming someone doesn't beat me to it. :)

Related Question