ST_MakeLine — Creates a LineString from a number of points.
PostgreSQL
geometry ST_MakeLine(
bytea point, bytea point)
;
geometry ST_MakeLine(
bytea[] point
array)
;
geometry ST_MakeLine(
bytea
Aggregate)
;
H2
geometry ST_MakeLine(
bytea point, bytea point)
;
geometry ST_MakeLine(
bytea[] point
array)
;
geometry ST_MakeLineAgg(
bytea
Aggregate)
;
Creates a LineString from a number of points. The function works in three ways.
The first one, takes two points and builds the linestring.
The second one, takes an array.
The last one, is the aggregate version that takes a row or a subselect from a table to build the resulting linestring.
2D | 3D | M |
---|---|---|
![]() | ![]() | ![]() |
OGC SFS for SQL. 1.1 (1999) | OGC SFS for SQL. 1.1.0 (2005) | OGC SFS for SQL. 1.2.0 (2006) | SQL-MM Part 3 |
---|---|---|---|
- | - | - | - |
--2 points SELECT ST_AsEWKT( ST_Makeline(ST_GeomFromEWKT('SRID=25830;POINT(0 0)'), ST_GeomFromEWKT('SRID=25830;POINT(10 10)'))) As myline; --Result SRID=25830;LINESTRING (0 0, 10 10)
--PostgreSQL select asewkt(makeline(Array[ST_MakePoint(0, 0), ST_MakePoint(10, 10),ST_MakePoint(15, 10)])); --Result asewkt -------------------------------- LINESTRING (0 0, 10 10, 15 10) (1 row) --H2 (1st Version)-- SELECT ST_AsText(ST_Makeline(st_accumagg(geom))) as myline from (select array_get( ( st_geomfromtext('POINT(0 0)'), st_geomfromtext('POINT(10 10)'), st_geomfromtext('POINT(15 15)') ),x)::binary as geom from (select x from system_range(1,3) as foo) as tabla); --Result MYLINE LINESTRING (0 0, 10 10, 15 15) --H2 (2nd Version)-- select ST_AsText(ST_Makeline(st_accumagg(geom))) as myline from (select st_geomfromtext('SRID=10;POINT(0 0)') as geom union select st_geomfromtext('SRID=10;POINT(10 10)') union select st_geomfromtext('SRID=10;POINT(15 15)') ) as geom; MYLINE LINESTRING (15 15, 0 0, 10 10)
--Creates a table and populates data into it
create table "gps_points"(id serial PRIMARY KEY);
SELECT AddGeometryColumn ('gps_points','geom',-1,'POINT',2);
INSERT INTO "gps_points" ("geom") VALUES (ST_GeomfromEWKT('SRID=-1;POINT(0 0)'));
INSERT INTO "gps_points" ("geom") VALUES (ST_GeomfromEWKT('SRID=-1;POINT(10 10)'));
INSERT INTO "gps_points" ("geom") VALUES (ST_GeomfromEWKT('SRID=-1;POINT(15 15)'));
--PostgreSQL
select asewkt(ST_Makeline("gps_points"."geom")) from "gps_points";
--H2
select asewkt(ST_MakelineAgg("gps_points"."geom")) from "gps_points";
--Result
asewkt
--------------------------------
LINESTRING (0 0, 10 10, 15 15)
(1 row)
select dropgeometrytable('gps_points');