Questions  /  Working with Data  /  PostGIS

How to create straight lines between points

Use SQL to connect points with straight lines.

You can use the ST_MakeLine PostGIS function to connect points with lines using SQL:

SELECT a.cartodb_id,
       ST_MakeLine(
           a.the_geom_webmercator,
           b.the_geom_webmercator
       ) as the_geom_webmercator,
       a.name as origin,
       b.name as destination
  FROM ( SELECT *
           FROM populated_places
          WHERE name = 'Paris'
       ) as a,
       ( SELECT *
           FROM populated_places
          WHERE name = 'Madrid'
       ) as b

lines