Skip to content

Instantly share code, notes, and snippets.

@alrocar
Last active July 5, 2018 10:21
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/b864db37fffcf4f7126d2c128d3f31f2 to your computer and use it in GitHub Desktop.
Save alrocar/b864db37fffcf4f7126d2c128d3f31f2 to your computer and use it in GitHub Desktop.
animate lines script
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