Linestring Data Type
A Linestring is a set of points joined sequentially together, optionally with an SRID.
This data type can be used to map items such as roads, rivers, trails, and circuit paths.
Examples:
Without specifying SRID:
CREATE TABLE trails (name VARCHAR(30), path LINESTRING);
With specifying SRID:
CREATE TABLE trails (name VARCHAR(30), path LINESTRING SRID 26911);
Use linestrings to represent the path of travel from one point to another:
CREATE TABLE paths (id INTEGER PRIMARY KEY, path LINESTRING NOT NULL);
INSERT INTO paths (id, path) VALUES (1, LINEFROMTEXT('LINESTRING(0 0, 10 0, 10 10)'));
INSERT INTO paths (id, path) VALUES (2, LINEFROMTEXT('LINESTRING(0 0, 10 10)'));
INSERT INTO paths (id, path) VALUES (3, LINEFROMTEXT('LINESTRING(0 0, 10 0)'));
Calculate length of paths that start at point (0, 0) and end at point (10, 10):
SELECT id, ST_LENGTH(path) FROM paths WHERE EQUALS(STARTPOINT(path), POINTFROMTEXT('POINT(0 0)')) = 1 AND EQUALS(ENDPOINT(path), POINTFROMTEXT('POINT(10 10)')) = 1;
--------------------------
id col2
--------------------------
1 20.000
2 14.142
--------------------------
Last modified date: 08/28/2024