[postgis-users] how to create line segment from point table

Kevin Neufeld kneufeld at refractions.net
Mon May 11 21:33:42 PDT 2009


I'm a little unclear to what you are asking.  Are these queries of any help?

-- create at table of points
CREATE TABLE pts (id serial, geom geometry);
INSERT INTO pts (geom) VALUES ('POINT(0 0)');
INSERT INTO pts (geom) VALUES ('POINT(1 1)');
INSERT INTO pts (geom) VALUES ('POINT(2 2)');
INSERT INTO pts (geom) VALUES ('POINT(3 3)');
INSERT INTO pts (geom) VALUES ('POINT(4 4)');
INSERT INTO pts (geom) VALUES ('POINT(5 5)');

SELECT ST_AsText(ST_MakeLine(geom)) FROM pts;  
          st_astext         
-----------------------------
 LINESTRING(0 0,0 1,1 1,2 2)
(1 row)

SELECT ST_AsText(ST_MakeLine(a.geom, b.geom))
FROM pts a, pts b
WHERE a.id+1 = b.id;

      st_astext     
---------------------
 LINESTRING(0 0,1 1)
 LINESTRING(1 1,2 2)
 LINESTRING(2 2,3 3)
 LINESTRING(3 3,4 4)
 LINESTRING(4 4,5 5)
(5 rows)

Cheers,
Kevin

searchelite wrote:
> Hi all, i have point table consist of GPS point updates. Is there any way to
> create line segments that consists of two points? Right now, what i did is
> to create linestring with ST_makeline and after that i split the line with
> generate_series. Is it possible to create line segment straight from point
> table? how can i do that
>
> Thanks
>   



More information about the postgis-users mailing list