Skip to content

Instantly share code, notes, and snippets.

@alrocar
Last active April 30, 2017 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alrocar/90c984800eb0846bc87a052bc2ec5796 to your computer and use it in GitHub Desktop.
Save alrocar/90c984800eb0846bc87a052bc2ec5796 to your computer and use it in GitHub Desktop.
Segment a line with PostGIS
insert into SEGMENTED_DATASET SELECT cartodb_id+n, ST_LineSubstring(the_geom, 100.00*n/length,
CASE
WHEN 100.00*(n+1) < length THEN 100.00*(n+1)/length
ELSE 1
END) As the_geom
FROM
(SELECT TRACK_GPS.cartodb_id,
ST_LineMerge(TRACK_GPS.the_geom) AS the_geom,
ST_Length(TRACK_GPS.the_geom::geography) As length
FROM TRACK_GPS
) AS t
CROSS JOIN generate_series(0,length*10) AS n
WHERE n*100.00/length < 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment