{"id":723,"date":"2025-12-23T10:14:23","date_gmt":"2025-12-23T16:14:23","guid":{"rendered":"https:\/\/thenoyes.com\/littlenoise\/?p=723"},"modified":"2025-12-24T15:32:58","modified_gmt":"2025-12-24T21:32:58","slug":"close-linestring-in-mysql","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=723","title":{"rendered":"Close LineString in MySQL"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted has-small-font-size\">SET @linestring = LineString(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1));<br><br>SELECT ST_AsText(@linestring), ST_IsClosed(@linestring);<br>+-----------------------------+--------------------------+<br>| ST_AsText(@linestring)      | ST_IsClosed(@linestring) |<br>+-----------------------------+--------------------------+<br>| LINESTRING(0 0,1 0,1 1,0 1) |                        0 |<br>+-----------------------------+--------------------------+<br><br>WITH RECURSIVE<br>    nums (n) AS (SELECT 0 UNION ALL SELECT n + 1 FROM nums WHERE n &lt; ST_NumPoints(@linestring)),<br>    points (p) AS (SELECT ST_PointN(@linestring, n % ST_NumPoints(@linestring) + 1) FROM nums)<br>SELECT CAST(ST_COLLECT(p) AS LineString) INTO @linestring FROM points;<br><br>SELECT ST_AsText(@linestring), ST_IsClosed(@linestring);<br>+---------------------------------+--------------------------+<br>| ST_AsText(@linestring)          | ST_IsClosed(@linestring) |<br>+---------------------------------+--------------------------+<br>| LINESTRING(0 0,1 0,1 1,0 1,0 0) |                        1 |<br>+---------------------------------+--------------------------+<br><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SET @linestring = LineString(Point(0, 0), Point(1, 0), Point(1, 1), Point(0, 1));SELECT ST_AsText(@linestring), ST_IsClosed(@linestring);+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+| ST_AsText(@linestring) | ST_IsClosed(@linestring) |+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+| LINESTRING(0 0,1 0,1 1,0 1) | 0 |+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+WITH RECURSIVE nums (n) AS (SELECT 0 UNION ALL SELECT n + 1 FROM nums WHERE n &lt; ST_NumPoints(@linestring)), points (p) AS (SELECT ST_PointN(@linestring, n % ST_NumPoints(@linestring) + 1) FROM nums)SELECT [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4],"tags":[],"class_list":["post-723","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-bF","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/723","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=723"}],"version-history":[{"count":2,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/723\/revisions"}],"predecessor-version":[{"id":740,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/723\/revisions\/740"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=723"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=723"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=723"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}