Skip to content

Instantly share code, notes, and snippets.

@SteveUpton
Created March 31, 2015 23:04
Show Gist options
  • Save SteveUpton/50c3819056b4a33e39cb to your computer and use it in GitHub Desktop.
Save SteveUpton/50c3819056b4a33e39cb to your computer and use it in GitHub Desktop.
Converts a CartoDB table generated from YB Tracking YML into a linestring
-- Generate the timestamp from the supplied data
UPDATE yb
SET timestamp=to_timestamp(SUBSTRING(name, 7, 20), 'DD-MM-YYYY HH24:MI:SS');
-- Generate the linestring as a new table
CREATE TABLE yb_linestring AS (
SELECT
ST_MakeLine(the_geom ORDER BY timestamp) AS the_geom
FROM yb);
-- Necessary to make the table appear on your CartoDB dashboard
-- (see: https://github.com/CartoDB/cartodb/wiki/creating-tables-though-the-SQL-API)
SELECT cdb_cartodbfytable('yb_linestring');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment