How can I create a line, with Python functions, with many points that are records in PostGIS?


Not 100% what you are asking for, but why not creating the line in PostGIS first?

SELECT gps.gps_track, ST_MakeLine(gps.the_geom ORDER BY gps_time) As newgeom
FROM gps_points As gps
GROUP BY gps.gps_track;

That will create a different line for each gps track and order them by time. I use that to create bus routes, ordered by stop sequence.

Really fast too.

(from: http://postgis.net/docs/ST_MakeLine.htm)

|improve this answer|||||
  • Does not work, gives error in "order by" – user1573901 May 9 '13 at 16:46
  • Could you post your code? I'm not a PostGIS expert, I just happened to use that function 2-3 weeks ago, but it would help. – fgcartographix May 10 '13 at 17:44
  • I used it to create line from shapes points from gtfs: CREATE TABLE cit.ligne_tr AS SELECT p.shape_id, ST_MakeLine(geom) As geom FROM (SELECT * FROM cit.shapes ORDER BY shape_pt_sequence) p GROUP BY p.shape_id; – fgcartographix May 10 '13 at 18:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.