Last active
April 30, 2017 19:16
-
-
Save alrocar/90c984800eb0846bc87a052bc2ec5796 to your computer and use it in GitHub Desktop.
Segment a line with PostGIS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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