Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimals in MySQL Polygon Geometry

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.

like image 840
JohnHenry Avatar asked Mar 02 '12 09:03

JohnHenry


People also ask

Can Smallint have decimals?

Unsigned SMALLINT provides exact numeric integers from 0 to 65,536. It uses 2 bytes of storage and has 4 digits of decimal precision.

What is a decimal in MySQL?

In Transact-SQL statements, a constant with a decimal point is automatically converted into a numeric data value, using the minimum precision and scale necessary. For example, the constant 12.345 is converted into a numeric value with a precision of 5 and a scale of 3.

What is the range of decimal in MySQL?

It has a range of 1 to 65. D is the number of digits to the right of the decimal point (the scale).


1 Answers

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.

like image 91
LithiumIon Avatar answered Sep 16 '22 23:09

LithiumIon