{"id":183,"date":"2011-12-10T10:12:03","date_gmt":"2011-12-10T16:12:03","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=183"},"modified":"2011-12-10T10:12:03","modified_gmt":"2011-12-10T16:12:03","slug":"midpoint-of-a-linestring","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=183","title":{"rendered":"MidPoint of a LineString"},"content":{"rendered":"<p><code>CREATE FUNCTION MidPoint(ls LINESTRING)<br \/>\nRETURNS POINT<br \/>\nDETERMINISTIC<br \/>\nBEGIN<br \/>\n  DECLARE len double;<br \/>\n  DECLARE workLength double DEFAULT 0;<br \/>\n  DECLARE workPoint int DEFAULT 1;<br \/>\n  DECLARE point0 POINT;<br \/>\n  DECLARE point1 POINT;<br \/>\n  DECLARE distanceOver double;<br \/>\n  DECLARE segmentLength double;<\/p>\n<p>  IF (NumPoints(ls) = 1) THEN return PointN(ls, 1); END IF;<\/p>\n<p>  -- find half the length of the linestring<br \/>\n  SET len := GLength(ls) \/ 2;<\/p>\n<p>  -- walk the linestring until we exceed the distance<br \/>\n  WHILE (workLength < len) DO\n    SET point0 = PointN(ls, workPoint);\n    SET workPoint := workPoint + 1;\n    SET point1 = PointN(ls, workPoint);\n    SET segmentLength = GLength(LineString(point0, point1));\n    SET workLength := workLength + segmentLength;\n  END WHILE;\n\n  -- distance to backup\n  SET distanceOver = workLength - len;\n\n  -- midpoint is distanceOver back down the last segement\n  RETURN POINT(\n      X(point1) - distanceOver \/ segmentLength * (X(point1) - X(point0)),\n      Y(point1) - distanceOver \/ segmentLength * (Y(point1) - Y(point0))\n    );\n\nEND<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>CREATE FUNCTION MidPoint(ls LINESTRING) RETURNS POINT DETERMINISTIC BEGIN DECLARE len double; DECLARE workLength double DEFAULT 0; DECLARE workPoint int DEFAULT 1; DECLARE point0 POINT; DECLARE point1 POINT; DECLARE distanceOver double; DECLARE segmentLength double; IF (NumPoints(ls) = 1) THEN return PointN(ls, 1); END IF; &#8212; find half the length of the linestring SET len := GLength(ls) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_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}},"categories":[4],"tags":[],"class_list":["post-183","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-2X","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/183","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=183"}],"version-history":[{"count":2,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":185,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions\/185"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}