Moak Moak - 2 months ago 6
MySQL Question

Trouble inserting polygon to mysql database

I tried inserting

PolygonFromText("POLYGON((121.44842136764532 31.22119260287111,
121.45076025390631 31.221990825071376,
121.45402182006842 31.218366658611853,
121.45091045761114 31.217054584347302))")


as a value into a a field of both type Polygon and of type Geometry.

When I run

SELECT PolygonFromText("POLYGON((121.44842136764532 31.22119260287111,
121.45076025390631 31.221990825071376,
121.45402182006842 31.218366658611853,
121.45091045761114 31.217054584347302))")


it returns
NULL


My Mysql Version is 5.1.41 - I find the MySql documentation very poor and not user friendly in these cases

Answer

I think a Polygon has to close so the last set of coordinates should be same as first one. This will return following

SELECT  PolygonFromText("POLYGON((121.44842136764532 31.22119260287111,121.45076025390631 31.221990825071376,121.45402182006842 31.218366658611853,121.45091045761114 31.217054584347302,121.44842136764532 31.22119260287111))");
Comments