Decimal Values ​​in MySQL Polygon Geometry

I searched high and low for a hint or even an answer to the next question and did not get anywhere, so I ask here.

Basically, I am trying to fill a Geometry column in MySQL with a polygon. But no matter what I try, the column ends up being NULL, not what it should be.

It seems to me that points for a polygon cannot contain decimals, such as latitude and longitude, but it seems completely illogical if this is true! What good is this type if you cannot insert latitude and longitude data into it?!?!

For this reason, I ask you to find out if I have something simple. Here is what I have to show:

SELECT GEOMFROMTEXT('POLYGON((52.29600522644751 0.05256918782038156,52.29168750609503 0.04999426716608468,52.29425981571103 0.06121662968439523))'); 

Return:

 (NULL) 

Whereas if I create a point geometry type:

 SELECT GEOMFROMTEXT('POINT(52.29600522644751 0.05256918782038156)'); 

This returns an empty value that actually contains points X and Y.

Any help would be greatly appreciated.

+4
source share
1 answer

GEOMFROMTEXT returns null if geometry is not valid. The linear ring that you use to create your polygon is incorrect. The start and end points of the ring must be equal to the end of the ring.

The valid polygon in this case will 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.

+5
source

Source: https://habr.com/ru/post/1399351/


All Articles