Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble inserting polygon to mysql database

Tags:

mysql

gis

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

like image 370
Moak Avatar asked Jan 20 '23 09:01

Moak


1 Answers

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))");
like image 77
mikeq Avatar answered Feb 02 '23 12:02

mikeq