SET @linestring = LineString(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1));
SELECT ST_AsText(@linestring), ST_IsClosed(@linestring);
+-----------------------------+--------------------------+
| ST_AsText(@linestring) | ST_IsClosed(@linestring) |
+-----------------------------+--------------------------+
| LINESTRING(0 0,1 0,1 1,0 1) | 0 |
+-----------------------------+--------------------------+
WITH RECURSIVE
nums (n) AS (SELECT 0 UNION ALL SELECT n + 1 FROM nums WHERE n < ST_NumPoints(@linestring)),
points (p) AS (SELECT ST_PointN(@linestring, n % ST_NumPoints(@linestring) + 1) FROM nums)
SELECT CAST(ST_COLLECT(p) AS LineString) INTO @linestring FROM points;
SELECT ST_AsText(@linestring), ST_IsClosed(@linestring);
+---------------------------------+--------------------------+
| ST_AsText(@linestring) | ST_IsClosed(@linestring) |
+---------------------------------+--------------------------+
| LINESTRING(0 0,1 0,1 1,0 1,0 0) | 1 |
+---------------------------------+--------------------------+
Leave a Reply