Last active
July 5, 2018 10:21
-
-
Save alrocar/b864db37fffcf4f7126d2c128d3f31f2 to your computer and use it in GitHub Desktop.
animate lines script
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
with lines as | |
(SELECT cartodb_id, color, ord, ST_Segmentize(ST_MakeLine(st_centroid(the_geom), lead(st_centroid(the_geom)) OVER (ORDER BY ord))::geography, 100000)::geometry as the_geom | |
FROM world_borders_four_colors_1_adjacency_list), | |
tosplit AS ( | |
SELECT * FROM lines | |
WHERE ST_XMax(the_geom) - ST_XMin(the_geom) > 180 | |
), | |
nosplit AS ( | |
SELECT * FROM lines | |
WHERE ST_XMax(the_geom) - ST_XMin(the_geom) <= 180 | |
), | |
split AS ( | |
SELECT | |
cartodb_id, | |
color, ord, | |
ST_Difference(ST_Shift_Longitude(the_geom), | |
ST_Buffer(ST_GeomFromText('LINESTRING(180 90, 180 -90)',4326), | |
0.00001)) AS the_geom | |
FROM tosplit | |
), | |
final AS ( | |
SELECT * FROM split | |
UNION ALL | |
SELECT * FROM nosplit | |
) | |
SELECT row_number() over() as cartodb_id, the_geom, color, ord from final |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment