To make it easier to get Nth line from the LineString, we use this function (similar to PointN):
DELIMITER // DROP FUNCTION IF EXISTS LineN; // CREATE FUNCTION LineN(ls LINESTRING, n INT) RETURNS LINESTRING NO SQL DETERMINISTIC BEGIN IF n >= numPoints(ls) THEN RETURN NULL; END IF; RETURN LineString(PointN(ls, n), PointN(ls, n+1)); END; //
User Comments
We work a lot with LineString columns in our project (http://www.sunnyrentals.com).
To make it easier to get Nth line from the LineString, we use this function (similar to PointN):
DELIMITER //
DROP FUNCTION IF EXISTS LineN; //
CREATE FUNCTION LineN(ls LINESTRING, n INT) RETURNS LINESTRING NO SQL DETERMINISTIC
BEGIN
IF n >= numPoints(ls) THEN
RETURN NULL;
END IF;
RETURN LineString(PointN(ls, n), PointN(ls, n+1));
END; //
Add your own comment.