Introduction

This tutorial will go through the basic steps that are implemented within rayshaderanimate. The main functionality of the package is animating a GPX line on a 3d shade of an elevation profile.

Thus the tutorial will

  • Read in a GPX line
  • Download elevation data around this GPX file
  • Download a map overlay for the GPX file
  • Plot the elevation map in 2D to check the data
  • Create a 3d animated gif
  • Create a 3d animated mp4 (more frames possible)

Read in a GPX file

Reading in a GPX file is handled by the plotKML::readGPX function. It is automatically loaded by rayshaderanimate and used inside the get_table_from_gpx function. From this table the boundaries of the GPX file will be read in a standard bbox format as used e.g. by ggmap and in a second format used for receiving data from Arcgis.

  1. Get the GPX file location from this package
## Loading required package: rayshader
## Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
## Warning: 'rgl_init' failed, running with rgl.useNULL = TRUE
## Loading required package: ggplot2
## Registered S3 method overwritten by 'xts':
##   method     from
##   as.zoo.xts zoo
  1. Get boundaries from GPX
## Calculating distances may take a while.
## 1/1566 2/1566 3/1566 4/1566 5/1566 6/1566 7/1566 8/1566 9/1566 10/1566
## 11/1566 12/1566 13/1566 14/1566 15/1566 16/1566 17/1566 18/1566 19/1566
## 20/1566 21/1566 22/1566 23/1566 24/1566 25/1566 26/1566 27/1566 28/1566
## 29/1566 30/1566 31/1566 32/1566 33/1566 34/1566 35/1566 36/1566 37/1566
## 38/1566 39/1566 40/1566 41/1566 42/1566 43/1566 44/1566 45/1566 46/1566
## 47/1566 48/1566 49/1566 50/1566 51/1566 52/1566 53/1566 54/1566 55/1566
## 56/1566 57/1566 58/1566 59/1566 60/1566 61/1566 62/1566 63/1566 64/1566
## 65/1566 66/1566 67/1566 68/1566 69/1566 70/1566 71/1566 72/1566 73/1566
## 74/1566 75/1566 76/1566 77/1566 78/1566 79/1566 80/1566 81/1566 82/1566
## 83/1566 84/1566 85/1566 86/1566 87/1566 88/1566 89/1566 90/1566 91/1566
## 92/1566 93/1566 94/1566 95/1566 96/1566 97/1566 98/1566 99/1566 100/1566
## 101/1566 102/1566 103/1566 104/1566 105/1566 106/1566 107/1566 108/1566
## 109/1566 110/1566 111/1566 112/1566 113/1566 114/1566 115/1566 116/1566
## 117/1566 118/1566 119/1566 120/1566 121/1566 122/1566 123/1566 124/1566
## 125/1566 126/1566 127/1566 128/1566 129/1566 130/1566 131/1566 132/1566
## 133/1566 134/1566 135/1566 136/1566 137/1566 138/1566 139/1566 140/1566
## 141/1566 142/1566 143/1566 144/1566 145/1566 146/1566 147/1566 148/1566
## 149/1566 150/1566 151/1566 152/1566 153/1566 154/1566 155/1566 156/1566
## 157/1566 158/1566 159/1566 160/1566 161/1566 162/1566 163/1566 164/1566
## 165/1566 166/1566 167/1566 168/1566 169/1566 170/1566 171/1566 172/1566
## 173/1566 174/1566 175/1566 176/1566 177/1566 178/1566 179/1566 180/1566
## 181/1566 182/1566 183/1566 184/1566 185/1566 186/1566 187/1566 188/1566
## 189/1566 190/1566 191/1566 192/1566 193/1566 194/1566 195/1566 196/1566
## 197/1566 198/1566 199/1566 200/1566 201/1566 202/1566 203/1566 204/1566
## 205/1566 206/1566 207/1566 208/1566 209/1566 210/1566 211/1566 212/1566
## 213/1566 214/1566 215/1566 216/1566 217/1566 218/1566 219/1566 220/1566
## 221/1566 222/1566 223/1566 224/1566 225/1566 226/1566 227/1566 228/1566
## 229/1566 230/1566 231/1566 232/1566 233/1566 234/1566 235/1566 236/1566
## 237/1566 238/1566 239/1566 240/1566 241/1566 242/1566 243/1566 244/1566
## 245/1566 246/1566 247/1566 248/1566 249/1566 250/1566 251/1566 252/1566
## 253/1566 254/1566 255/1566 256/1566 257/1566 258/1566 259/1566 260/1566
## 261/1566 262/1566 263/1566 264/1566 265/1566 266/1566 267/1566 268/1566
## 269/1566 270/1566 271/1566 272/1566 273/1566 274/1566 275/1566 276/1566
## 277/1566 278/1566 279/1566 280/1566 281/1566 282/1566 283/1566 284/1566
## 285/1566 286/1566 287/1566 288/1566 289/1566 290/1566 291/1566 292/1566
## 293/1566 294/1566 295/1566 296/1566 297/1566 298/1566 299/1566 300/1566
## 301/1566 302/1566 303/1566 304/1566 305/1566 306/1566 307/1566 308/1566
## 309/1566 310/1566 311/1566 312/1566 313/1566 314/1566 315/1566 316/1566
## 317/1566 318/1566 319/1566 320/1566 321/1566 322/1566 323/1566 324/1566
## 325/1566 326/1566 327/1566 328/1566 329/1566 330/1566 331/1566 332/1566
## 333/1566 334/1566 335/1566 336/1566 337/1566 338/1566 339/1566 340/1566
## 341/1566 342/1566 343/1566 344/1566 345/1566 346/1566 347/1566 348/1566
## 349/1566 350/1566 351/1566 352/1566 353/1566 354/1566 355/1566 356/1566
## 357/1566 358/1566 359/1566 360/1566 361/1566 362/1566 363/1566 364/1566
## 365/1566 366/1566 367/1566 368/1566 369/1566 370/1566 371/1566 372/1566
## 373/1566 374/1566 375/1566 376/1566 377/1566 378/1566 379/1566 380/1566
## 381/1566 382/1566 383/1566 384/1566 385/1566 386/1566 387/1566 388/1566
## 389/1566 390/1566 391/1566 392/1566 393/1566 394/1566 395/1566 396/1566
## 397/1566 398/1566 399/1566 400/1566 401/1566 402/1566 403/1566 404/1566
## 405/1566 406/1566 407/1566 408/1566 409/1566 410/1566 411/1566 412/1566
## 413/1566 414/1566 415/1566 416/1566 417/1566 418/1566 419/1566 420/1566
## 421/1566 422/1566 423/1566 424/1566 425/1566 426/1566 427/1566 428/1566
## 429/1566 430/1566 431/1566 432/1566 433/1566 434/1566 435/1566 436/1566
## 437/1566 438/1566 439/1566 440/1566 441/1566 442/1566 443/1566 444/1566
## 445/1566 446/1566 447/1566 448/1566 449/1566 450/1566 451/1566 452/1566
## 453/1566 454/1566 455/1566 456/1566 457/1566 458/1566 459/1566 460/1566
## 461/1566 462/1566 463/1566 464/1566 465/1566 466/1566 467/1566 468/1566
## 469/1566 470/1566 471/1566 472/1566 473/1566 474/1566 475/1566 476/1566
## 477/1566 478/1566 479/1566 480/1566 481/1566 482/1566 483/1566 484/1566
## 485/1566 486/1566 487/1566 488/1566 489/1566 490/1566 491/1566 492/1566
## 493/1566 494/1566 495/1566 496/1566 497/1566 498/1566 499/1566 500/1566
## 501/1566 502/1566 503/1566 504/1566 505/1566 506/1566 507/1566 508/1566
## 509/1566 510/1566 511/1566 512/1566 513/1566 514/1566 515/1566 516/1566
## 517/1566 518/1566 519/1566 520/1566 521/1566 522/1566 523/1566 524/1566
## 525/1566 526/1566 527/1566 528/1566 529/1566 530/1566 531/1566 532/1566
## 533/1566 534/1566 535/1566 536/1566 537/1566 538/1566 539/1566 540/1566
## 541/1566 542/1566 543/1566 544/1566 545/1566 546/1566 547/1566 548/1566
## 549/1566 550/1566 551/1566 552/1566 553/1566 554/1566 555/1566 556/1566
## 557/1566 558/1566 559/1566 560/1566 561/1566 562/1566 563/1566 564/1566
## 565/1566 566/1566 567/1566 568/1566 569/1566 570/1566 571/1566 572/1566
## 573/1566 574/1566 575/1566 576/1566 577/1566 578/1566 579/1566 580/1566
## 581/1566 582/1566 583/1566 584/1566 585/1566 586/1566 587/1566 588/1566
## 589/1566 590/1566 591/1566 592/1566 593/1566 594/1566 595/1566 596/1566
## 597/1566 598/1566 599/1566 600/1566 601/1566 602/1566 603/1566 604/1566
## 605/1566 606/1566 607/1566 608/1566 609/1566 610/1566 611/1566 612/1566
## 613/1566 614/1566 615/1566 616/1566 617/1566 618/1566 619/1566 620/1566
## 621/1566 622/1566 623/1566 624/1566 625/1566 626/1566 627/1566 628/1566
## 629/1566 630/1566 631/1566 632/1566 633/1566 634/1566 635/1566 636/1566
## 637/1566 638/1566 639/1566 640/1566 641/1566 642/1566 643/1566 644/1566
## 645/1566 646/1566 647/1566 648/1566 649/1566 650/1566 651/1566 652/1566
## 653/1566 654/1566 655/1566 656/1566 657/1566 658/1566 659/1566 660/1566
## 661/1566 662/1566 663/1566 664/1566 665/1566 666/1566 667/1566 668/1566
## 669/1566 670/1566 671/1566 672/1566 673/1566 674/1566 675/1566 676/1566
## 677/1566 678/1566 679/1566 680/1566 681/1566 682/1566 683/1566 684/1566
## 685/1566 686/1566 687/1566 688/1566 689/1566 690/1566 691/1566 692/1566
## 693/1566 694/1566 695/1566 696/1566 697/1566 698/1566 699/1566 700/1566
## 701/1566 702/1566 703/1566 704/1566 705/1566 706/1566 707/1566 708/1566
## 709/1566 710/1566 711/1566 712/1566 713/1566 714/1566 715/1566 716/1566
## 717/1566 718/1566 719/1566 720/1566 721/1566 722/1566 723/1566 724/1566
## 725/1566 726/1566 727/1566 728/1566 729/1566 730/1566 731/1566 732/1566
## 733/1566 734/1566 735/1566 736/1566 737/1566 738/1566 739/1566 740/1566
## 741/1566 742/1566 743/1566 744/1566 745/1566 746/1566 747/1566 748/1566
## 749/1566 750/1566 751/1566 752/1566 753/1566 754/1566 755/1566 756/1566
## 757/1566 758/1566 759/1566 760/1566 761/1566 762/1566 763/1566 764/1566
## 765/1566 766/1566 767/1566 768/1566 769/1566 770/1566 771/1566 772/1566
## 773/1566 774/1566 775/1566 776/1566 777/1566 778/1566 779/1566 780/1566
## 781/1566 782/1566 783/1566 784/1566 785/1566 786/1566 787/1566 788/1566
## 789/1566 790/1566 791/1566 792/1566 793/1566 794/1566 795/1566 796/1566
## 797/1566 798/1566 799/1566 800/1566 801/1566 802/1566 803/1566 804/1566
## 805/1566 806/1566 807/1566 808/1566 809/1566 810/1566 811/1566 812/1566
## 813/1566 814/1566 815/1566 816/1566 817/1566 818/1566 819/1566 820/1566
## 821/1566 822/1566 823/1566 824/1566 825/1566 826/1566 827/1566 828/1566
## 829/1566 830/1566 831/1566 832/1566 833/1566 834/1566 835/1566 836/1566
## 837/1566 838/1566 839/1566 840/1566 841/1566 842/1566 843/1566 844/1566
## 845/1566 846/1566 847/1566 848/1566 849/1566 850/1566 851/1566 852/1566
## 853/1566 854/1566 855/1566 856/1566 857/1566 858/1566 859/1566 860/1566
## 861/1566 862/1566 863/1566 864/1566 865/1566 866/1566 867/1566 868/1566
## 869/1566 870/1566 871/1566 872/1566 873/1566 874/1566 875/1566 876/1566
## 877/1566 878/1566 879/1566 880/1566 881/1566 882/1566 883/1566 884/1566
## 885/1566 886/1566 887/1566 888/1566 889/1566 890/1566 891/1566 892/1566
## 893/1566 894/1566 895/1566 896/1566 897/1566 898/1566 899/1566 900/1566
## 901/1566 902/1566 903/1566 904/1566 905/1566 906/1566 907/1566 908/1566
## 909/1566 910/1566 911/1566 912/1566 913/1566 914/1566 915/1566 916/1566
## 917/1566 918/1566 919/1566 920/1566 921/1566 922/1566 923/1566 924/1566
## 925/1566 926/1566 927/1566 928/1566 929/1566 930/1566 931/1566 932/1566
## 933/1566 934/1566 935/1566 936/1566 937/1566 938/1566 939/1566 940/1566
## 941/1566 942/1566 943/1566 944/1566 945/1566 946/1566 947/1566 948/1566
## 949/1566 950/1566 951/1566 952/1566 953/1566 954/1566 955/1566 956/1566
## 957/1566 958/1566 959/1566 960/1566 961/1566 962/1566 963/1566 964/1566
## 965/1566 966/1566 967/1566 968/1566 969/1566 970/1566 971/1566 972/1566
## 973/1566 974/1566 975/1566 976/1566 977/1566 978/1566 979/1566 980/1566
## 981/1566 982/1566 983/1566 984/1566 985/1566 986/1566 987/1566 988/1566
## 989/1566 990/1566 991/1566 992/1566 993/1566 994/1566 995/1566 996/1566
## 997/1566 998/1566 999/1566 1000/1566 1001/1566 1002/1566 1003/1566
## 1004/1566 1005/1566 1006/1566 1007/1566 1008/1566 1009/1566 1010/1566
## 1011/1566 1012/1566 1013/1566 1014/1566 1015/1566 1016/1566 1017/1566
## 1018/1566 1019/1566 1020/1566 1021/1566 1022/1566 1023/1566 1024/1566
## 1025/1566 1026/1566 1027/1566 1028/1566 1029/1566 1030/1566 1031/1566
## 1032/1566 1033/1566 1034/1566 1035/1566 1036/1566 1037/1566 1038/1566
## 1039/1566 1040/1566 1041/1566 1042/1566 1043/1566 1044/1566 1045/1566
## 1046/1566 1047/1566 1048/1566 1049/1566 1050/1566 1051/1566 1052/1566
## 1053/1566 1054/1566 1055/1566 1056/1566 1057/1566 1058/1566 1059/1566
## 1060/1566 1061/1566 1062/1566 1063/1566 1064/1566 1065/1566 1066/1566
## 1067/1566 1068/1566 1069/1566 1070/1566 1071/1566 1072/1566 1073/1566
## 1074/1566 1075/1566 1076/1566 1077/1566 1078/1566 1079/1566 1080/1566
## 1081/1566 1082/1566 1083/1566 1084/1566 1085/1566 1086/1566 1087/1566
## 1088/1566 1089/1566 1090/1566 1091/1566 1092/1566 1093/1566 1094/1566
## 1095/1566 1096/1566 1097/1566 1098/1566 1099/1566 1100/1566 1101/1566
## 1102/1566 1103/1566 1104/1566 1105/1566 1106/1566 1107/1566 1108/1566
## 1109/1566 1110/1566 1111/1566 1112/1566 1113/1566 1114/1566 1115/1566
## 1116/1566 1117/1566 1118/1566 1119/1566 1120/1566 1121/1566 1122/1566
## 1123/1566 1124/1566 1125/1566 1126/1566 1127/1566 1128/1566 1129/1566
## 1130/1566 1131/1566 1132/1566 1133/1566 1134/1566 1135/1566 1136/1566
## 1137/1566 1138/1566 1139/1566 1140/1566 1141/1566 1142/1566 1143/1566
## 1144/1566 1145/1566 1146/1566 1147/1566 1148/1566 1149/1566 1150/1566
## 1151/1566 1152/1566 1153/1566 1154/1566 1155/1566 1156/1566 1157/1566
## 1158/1566 1159/1566 1160/1566 1161/1566 1162/1566 1163/1566 1164/1566
## 1165/1566 1166/1566 1167/1566 1168/1566 1169/1566 1170/1566 1171/1566
## 1172/1566 1173/1566 1174/1566 1175/1566 1176/1566 1177/1566 1178/1566
## 1179/1566 1180/1566 1181/1566 1182/1566 1183/1566 1184/1566 1185/1566
## 1186/1566 1187/1566 1188/1566 1189/1566 1190/1566 1191/1566 1192/1566
## 1193/1566 1194/1566 1195/1566 1196/1566 1197/1566 1198/1566 1199/1566
## 1200/1566 1201/1566 1202/1566 1203/1566 1204/1566 1205/1566 1206/1566
## 1207/1566 1208/1566 1209/1566 1210/1566 1211/1566 1212/1566 1213/1566
## 1214/1566 1215/1566 1216/1566 1217/1566 1218/1566 1219/1566 1220/1566
## 1221/1566 1222/1566 1223/1566 1224/1566 1225/1566 1226/1566 1227/1566
## 1228/1566 1229/1566 1230/1566 1231/1566 1232/1566 1233/1566 1234/1566
## 1235/1566 1236/1566 1237/1566 1238/1566 1239/1566 1240/1566 1241/1566
## 1242/1566 1243/1566 1244/1566 1245/1566 1246/1566 1247/1566 1248/1566
## 1249/1566 1250/1566 1251/1566 1252/1566 1253/1566 1254/1566 1255/1566
## 1256/1566 1257/1566 1258/1566 1259/1566 1260/1566 1261/1566 1262/1566
## 1263/1566 1264/1566 1265/1566 1266/1566 1267/1566 1268/1566 1269/1566
## 1270/1566 1271/1566 1272/1566 1273/1566 1274/1566 1275/1566 1276/1566
## 1277/1566 1278/1566 1279/1566 1280/1566 1281/1566 1282/1566 1283/1566
## 1284/1566 1285/1566 1286/1566 1287/1566 1288/1566 1289/1566 1290/1566
## 1291/1566 1292/1566 1293/1566 1294/1566 1295/1566 1296/1566 1297/1566
## 1298/1566 1299/1566 1300/1566 1301/1566 1302/1566 1303/1566 1304/1566
## 1305/1566 1306/1566 1307/1566 1308/1566 1309/1566 1310/1566 1311/1566
## 1312/1566 1313/1566 1314/1566 1315/1566 1316/1566 1317/1566 1318/1566
## 1319/1566 1320/1566 1321/1566 1322/1566 1323/1566 1324/1566 1325/1566
## 1326/1566 1327/1566 1328/1566 1329/1566 1330/1566 1331/1566 1332/1566
## 1333/1566 1334/1566 1335/1566 1336/1566 1337/1566 1338/1566 1339/1566
## 1340/1566 1341/1566 1342/1566 1343/1566 1344/1566 1345/1566 1346/1566
## 1347/1566 1348/1566 1349/1566 1350/1566 1351/1566 1352/1566 1353/1566
## 1354/1566 1355/1566 1356/1566 1357/1566 1358/1566 1359/1566 1360/1566
## 1361/1566 1362/1566 1363/1566 1364/1566 1365/1566 1366/1566 1367/1566
## 1368/1566 1369/1566 1370/1566 1371/1566 1372/1566 1373/1566 1374/1566
## 1375/1566 1376/1566 1377/1566 1378/1566 1379/1566 1380/1566 1381/1566
## 1382/1566 1383/1566 1384/1566 1385/1566 1386/1566 1387/1566 1388/1566
## 1389/1566 1390/1566 1391/1566 1392/1566 1393/1566 1394/1566 1395/1566
## 1396/1566 1397/1566 1398/1566 1399/1566 1400/1566 1401/1566 1402/1566
## 1403/1566 1404/1566 1405/1566 1406/1566 1407/1566 1408/1566 1409/1566
## 1410/1566 1411/1566 1412/1566 1413/1566 1414/1566 1415/1566 1416/1566
## 1417/1566 1418/1566 1419/1566 1420/1566 1421/1566 1422/1566 1423/1566
## 1424/1566 1425/1566 1426/1566 1427/1566 1428/1566 1429/1566 1430/1566
## 1431/1566 1432/1566 1433/1566 1434/1566 1435/1566 1436/1566 1437/1566
## 1438/1566 1439/1566 1440/1566 1441/1566 1442/1566 1443/1566 1444/1566
## 1445/1566 1446/1566 1447/1566 1448/1566 1449/1566 1450/1566 1451/1566
## 1452/1566 1453/1566 1454/1566 1455/1566 1456/1566 1457/1566 1458/1566
## 1459/1566 1460/1566 1461/1566 1462/1566 1463/1566 1464/1566 1465/1566
## 1466/1566 1467/1566 1468/1566 1469/1566 1470/1566 1471/1566 1472/1566
## 1473/1566 1474/1566 1475/1566 1476/1566 1477/1566 1478/1566 1479/1566
## 1480/1566 1481/1566 1482/1566 1483/1566 1484/1566 1485/1566 1486/1566
## 1487/1566 1488/1566 1489/1566 1490/1566 1491/1566 1492/1566 1493/1566
## 1494/1566 1495/1566 1496/1566 1497/1566 1498/1566 1499/1566 1500/1566
## 1501/1566 1502/1566 1503/1566 1504/1566 1505/1566 1506/1566 1507/1566
## 1508/1566 1509/1566 1510/1566 1511/1566 1512/1566 1513/1566 1514/1566
## 1515/1566 1516/1566 1517/1566 1518/1566 1519/1566 1520/1566 1521/1566
## 1522/1566 1523/1566 1524/1566 1525/1566 1526/1566 1527/1566 1528/1566
## 1529/1566 1530/1566 1531/1566 1532/1566 1533/1566 1534/1566 1535/1566
## 1536/1566 1537/1566 1538/1566 1539/1566 1540/1566 1541/1566 1542/1566
## 1543/1566 1544/1566 1545/1566 1546/1566 1547/1566 1548/1566 1549/1566
## 1550/1566 1551/1566 1552/1566 1553/1566 1554/1566 1555/1566 1556/1566
## 1557/1566 1558/1566 1559/1566 1560/1566 1561/1566 1562/1566 1563/1566
## 1564/1566 1565/1566 1566/1566

Paint a map

To see if the right bbox was calculated, you can use the bbox_map function to simply double check the location. In this case you should see a map of the French alps around Alpe d’Huez.

bbox_map(bbox)
## Source : http://tile.stamen.com/terrain/13/4233/2943.png
## Source : http://tile.stamen.com/terrain/13/4234/2943.png
## Source : http://tile.stamen.com/terrain/13/4235/2943.png
## Source : http://tile.stamen.com/terrain/13/4236/2943.png
## Source : http://tile.stamen.com/terrain/13/4233/2944.png
## Source : http://tile.stamen.com/terrain/13/4234/2944.png
## Source : http://tile.stamen.com/terrain/13/4235/2944.png
## Source : http://tile.stamen.com/terrain/13/4236/2944.png
## Source : http://tile.stamen.com/terrain/13/4233/2945.png
## Source : http://tile.stamen.com/terrain/13/4234/2945.png
## Source : http://tile.stamen.com/terrain/13/4235/2945.png
## Source : http://tile.stamen.com/terrain/13/4236/2945.png
## Source : http://tile.stamen.com/terrain/13/4233/2946.png
## Source : http://tile.stamen.com/terrain/13/4234/2946.png
## Source : http://tile.stamen.com/terrain/13/4235/2946.png
## Source : http://tile.stamen.com/terrain/13/4236/2946.png

Receive elevation data

The elevaton data will be received from SRTM. As SRTM provides only 5 degree x 5 degree sectors, the data is filtered for the bbox. Afterwards this data can be converted into a long format to use it in ggplot or into a matrix without any labels that can easily be used in standard rayshader functions.

el_mat <- bbox %>% get_elevdata_from_bbox()

# Use data from EUDEM project available at: https://land.copernicus.eu/imagery-in-situ/eu-dem/eu-dem-v1.1
el_mat <- get_elevdata_from_bbox(bbox = bbox, type ="EUDEM", file = "eu_dem_v11_E40N20/eu_dem_v11_E40N20.TIF")
data(el_mat) # load pre-stored data
elmat_rayshade <- el_mat %>% unlabel_elevdata()
elmat_long <- get_elevdata_long(el_mat)

Plot 2D with map overlay

To double check the data is the right elevation data, it will be plotted. You should see the shades of mountains where you would expect them.

# in case of EUDEM data you might need to transpose the elmat_rayshade
plot_2d_elevdata(elevdata_rayshade = elmat_rayshade)

Generate 3D video

The most important step of this package is the generation of a 3D video. The video generation works the following way:

  1. A geom_tile plot is generated from the elevation data
  2. The GPX line is painted on this elevation map
  3. A 3D model of the landscape is generated by plot_gg from rayshader.
  4. A snapshot is taken

The procedure is repeated number_of_screens times. In each step the GPX line is painted a bit further.

The main length of the line is calculated such that the intervals between snapshots have a similar time difference to generate a movie feeling.

On more than 50 screens the animation will look from different angles and different zooms on the 3D model.

All snapshots get rendered into a gif by the magick package or into a mp4 by ffmpeg. Therefore ffmpeg needs to be installed and inside the PATH.

output_gif <- video_animation(gpx_table = gpx_table, elevdata_long = elmat_long, make_gif = TRUE, number_of_screens = 4,
                output_file_loc = tempfile(fileext = ".gif"))

Sys.setenv("PATH" = paste0(Sys.getenv("PATH"), ";", "<Where is ffmpeg>"))

output_vid <- video_animation(gpx_table = gpx_table, elevdata_long = elmat_long, make_gif = FALSE, number_of_screens = 6,
                output_file_loc = tempfile(fileext = ".mp4"))