Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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