Reputation: 515
I have searched high and low for a clue to or even the answer to the following question and have got nowhere so hence me asking on here.
Basically, I'm trying to populate a Geometry column in MySQL with a polygon. But whatever i try, the column end up with a value of NULL rather than what it is supposed to be.
It looks to me like the points for a Polygon cannot contain decimals such as Latitude and Longitude but that seems completely illogical if that really is the case! What good is this type if you cant put latitude and longitude data in it?!?!
For this reason, I'm asking to see if I'm missing something simple. Here is what I have to show this:
SELECT GEOMFROMTEXT('POLYGON((52.29600522644751 0.05256918782038156,52.29168750609503 0.04999426716608468,52.29425981571103 0.06121662968439523))');
Returns:
(NULL)
Whereas, if I create a point Geometry type:
SELECT GEOMFROMTEXT('POINT(52.29600522644751 0.05256918782038156)');
This returns a blank value which does actually contain the X and Y points.
Any help would be greatly appreciated.
Upvotes: 5
Views: 1894
Reputation: 76
GEOMFROMTEXT returns null if the geometry is invalid. The linear ring that you're using to build your polygon is invalid. The ring start and termination points must be equal to complete the ring.
A valid polygon in this case would be:
SELECT GEOMFROMTEXT('POLYGON((52.29600522644751 0.05256918782038156,52.29168750609503 0.04999426716608468,52.29425981571103 0.06121662968439523,52.29600522644751 0.05256918782038156))')
This returns the expected value instead of NULL.
Upvotes: 6