Create geometry (f.e. LineString()) from stored points. MySQL spatial

3.2k Views Asked by At

Is there any way to create some Geometry (f.e. LineString(pt1,pt2,...)) from MySQL query (where pt1,pt2,... is a result of another query, in other words pt1,pt2,... stored in MySQL table)?

Example: SELECT LineString(SELECT point FROM points) AS line; Thanks!

2

There are 2 best solutions below

0
On BEST ANSWER

I had a similar problem and solved it in this way:

SELECT pt1, pt2, pt3, pt4, @Line_string := GEOMFROMTEXT(CONCAT('LINESTRING(',pt1,' ',pt2,', ',pt3,' ',pt4,')')) FROM table;
0
On

LineString(pt1,pt2)

MySQL and MariaDB both support this now with LineString(pt1,pt2,...)

> SELECT ST_AsText( LineString( Point(0,0), Point(1,1) ) );
+---------------------------------------------------+
| ST_AsText( LineString( Point(0,0), Point(1,1) ) ) |
+---------------------------------------------------+
| LINESTRING(0 0,1 1)                               |
+---------------------------------------------------+