Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Submarine Cable Map Dataviz
library(geojsonsf)
library(sf)
library(rayrender)
#Data source: https://github.com/telegeography/www.submarinecablemap.com
cables = geojson_sf("cable-geo.json")
cablescene = list()
counter = 1
for(i in 1:length(cables$geometry)) {
for(j in 1:length(cables$geometry[[i]])) {
temp = cables$geometry[[i]][[j]]
cableval = data.frame(x=sinpi(temp[,1]/180)*cospi(temp[,2]/180),
y=sinpi(temp[,2]/180),
z=cospi(temp[,1]/180)*cospi(temp[,2]/180))
#Don't lower start of line at the 180/0 longitude border
if(abs(temp[1,1] - 180) > 0.001 && abs(temp[1,1] + 180) > 0.001) {
cableval[1,] = cableval[1,] * 1/1.02
}
nr = nrow(temp)
#Don't lower end of line at the 180/0 longitude border
if(abs(temp[nr,1] - 180) > 0.001 && abs(temp[nr,1] + 180) > 0.001) {
nr = nrow(cableval)
cableval[nr,] = cableval[nr,] * 1/1.02
}
cablescene[[counter]] = path(cableval, width = 0.005,material=diffuse(color=cables$color[i]))
counter = counter + 1
}
}
fullcablescene = do.call(rbind,cablescene)
for(i in seq(1,720,by=1)) {
group_objects(fullcablescene,scale=c(1,1,1)*1.02) %>%
add_object(sphere(radius=0.99,material=diffuse(image_texture = "2k_earth_daymap.jpg"),angle=c(0,-90,0))) %>%
group_objects(angle=c(0,-i/2,0)) %>%
add_object(sphere(y=5,z=5,x=5,material=light(intensity = 80,color="lightblue"))) %>%
add_object(sphere(y=5,z=5,x=-5,material=light(intensity = 10,color="orange"))) %>%
add_object(sphere(y=-10,material=light(intensity = 3,color="white"))) %>%
render_scene(samples=64,width=1200,height=1200,fov=0,aperture=0, ortho_dimensions = c(2.3,2.3),
sample_method = "sobol_blue",filename=sprintf("smallcables%d.png",i))
}
@marisnner7
Copy link

marisnner7 commented Sep 23, 2021

I think the Earth is running in the opposite direction, but I haven't identified where to put the - to push the fix.
Btw: awesome!!!

@erzakiev
Copy link

erzakiev commented Sep 23, 2021

cables = geojson_sf("cable-geo.json")
"Error in rcpp_geojson_to_sf(geojson, expand_geometries) : Invalid JSON"

I guess that you're supposed to do the installation of the cable map first as described here, but after doing so, how do I export this map into a .json file like you did ("cable-geo.json")?
Screen Shot 2021-09-23 at 13 22 25

EDIT: oh boy it was all simple I was supposed to just download & save a file linked here
Screen Shot 2021-09-23 at 13 26 47

@DocMok
Copy link

DocMok commented Sep 23, 2021

I think the Earth is running in the opposite direction, but I haven't identified where to put the - to push the fix.
Btw: awesome!!!

I think need some changes in 32 line:
for(i in seq(1,720,by=1))

but I don't know what exactly :)
maybe seq(720, 1, by=1) or seq(1,720,by=-1) or seq(720,1,by=-1)

@erzakiev
Copy link

erzakiev commented Sep 23, 2021

Error in group_objects(., angle = c(0, -i/2, 0)) :
unused argument (angle = c(0, -i/2, 0))

It's because the function argument is actually called group_angle, not angle

The same goes for argument called "scale" which is in reality called "group_scale"

@erzakiev
Copy link

erzakiev commented Sep 23, 2021

Also worth adding a link (as a comment) to download the 2k_earth_daymap.jpg image texture,
Screen Shot 2021-09-23 at 13 38 02

@tylermorganwall
Copy link
Author

tylermorganwall commented Sep 23, 2021

Error in group_objects(., angle = c(0, -i/2, 0)) :
unused argument (angle = c(0, -i/2, 0))

It's because the function argument is actually called group_angle, not angle

The same goes for argument called "scale" which is in reality called "group_scale"

You just need to update to the latest version of rayrender on github (here, via R-Universe):

options(repos = c(
    tylermorganwall = 'https://tylermorganwall.r-universe.dev',
    CRAN = 'https://cloud.r-project.org'))
install.packages('rayrender')

@erzakiev
Copy link

erzakiev commented Sep 25, 2021

2spoopy4me a skeleton planet!
I guess the texture didn't stick to the sphere, huh? Outdated version os rayrender again, huh?
https://user-images.githubusercontent.com/13952639/134770781-5398924c-02de-4826-929c-42fb9fea4ae5.mov

@tylermorganwall
Copy link
Author

tylermorganwall commented Sep 25, 2021

2spoopy4me a skeleton planet!
I guess the texture didn't stick to the sphere, huh? Outdated version os rayrender again, huh?
https://user-images.githubusercontent.com/13952639/134770781-5398924c-02de-4826-929c-42fb9fea4ae5.mov

Yes, update to the latest version via the code above (JPEG texture support was added after the CRAN upload)

@Aldairg97
Copy link

Aldairg97 commented Sep 25, 2021

Como se puede ejecutar este archivo?

@YoViajo
Copy link

YoViajo commented Sep 30, 2021

Como se puede ejecutar este archivo?

  • Descarga los archivos a los que hace referencia el código R (1 archivo GeoJSON, 1 archivo JPG) usando los enlaces mencionados líneas arriba (en los comentarios)
  • En el código R, ajusta la referencia de ruta de los archivos descargados (según tu definición)
  • Ejecuta el código R en tu ambiente favorito (e.g, R-Studio). Prepárate para esperar. En mi caso tomó 40 horas en completar.
  • La salida es grupo de imágenes PNG que visualizadas juntas pueden animarse como un video. Yo utilicé ffmpeg para hacer esa combinación.

@hominidae
Copy link

hominidae commented Jan 30, 2022

The SFU link for the JPG doesn't work, here's the wikimedia source file.

https://upload.wikimedia.org/wikipedia/commons/c/c3/Solarsystemscope_texture_2k_earth_daymap.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment