# Thu Oct 15 14:56:34 2020 -
# 字符编码:UTF-8
# R 版本:R x64 4.0.2 for window 10
# cgh163email@163.com
# 个人笔记不负责任
# —— 拎了个梨🍐
.rs.restartR()
rm(list=ls());gc()
# render_path函数,渲染三维路径路线
require(rayshader)
# 使用范围对象定义的参考系统中的纬度/经度或坐标,将3D路径添加到当前场景。 如果未提供高度,则路径将升高一定的偏移高度,使其高于高度图。 如果路径偏离边缘,将使用高度图上最近的高度。
#Starting at Moss Landing in Monterey Bay, we are going to simulate a flight of a bird going
#out to sea and diving for food.
#First, create simulated lat/long data
set.seed(2009)
moss_landing_coord = c(36.806807, -121.793332)
x_vel_out = -0.001 + rnorm(1000)[1:300]/1000
y_vel_out = rnorm(1000)[1:300]/200
z_out = c(seq(0,2000,length.out = 180), seq(2000,0,length.out=10),
seq(0,2000,length.out = 100), seq(2000,0,length.out=10))
bird_track_lat = list()
bird_track_long = list()
bird_track_lat[[1]] = moss_landing_coord[1]
bird_track_long[[1]] = moss_landing_coord[2]
for(i in 2:300) {
bird_track_lat[[i]] = bird_track_lat[[i-1]] + y_vel_out[i]
bird_track_long[[i]] = bird_track_long[[i-1]] + x_vel_out[i]
}
#渲染3D地图
montereybay %>%
sphere_shade() %>%
plot_3d(montereybay,zscale=50,water=TRUE,
shadowcolor="#40310a", watercolor="#233aa1", background = "tan",
theta=210, phi=22, zoom=0.2, fov=55)
#传递基础栅格的范围(存储在montereybay #dataset的属性中)以及轨道的纬度,经度和海拔高度。
render_path(extent = attr(montereybay,"extent"),
lat = unlist(bird_track_lat), long = unlist(bird_track_long),
altitude = z_out, zscale=50,color="white", antialias=TRUE)
render_snapshot()
# Sat Oct 17 13:57:14 2020 ---diy---------------------------
map.bys <- raster('https://gitee.com/youmigo/open-file/raw/master/.grd/%E7%99%BD%E4%BA%91%E5%B1%B160%E7%B1%B3%E9%87%87%E6%A0%B7%E9%AB%98%E7%A8%8B%E7%82%B9.grd')#白云山grd
# runif(n, min, max ) 生成n个大于min,小于max的随机数
# 113.2837, 113.3292, 23.15698, 23.21607
map.xyz <- data.frame(runif(100,23.15698,23.21607),runif(100,113.2837,113.3292),runif(100,5,200))
names(map.xyz)
rgl::rgl.close() # 清空设备
raster_to_matrix(map.bys) %>% sphere_shade() %>%
plot_3d( raster_to_matrix(map.bys),zscale = 8,
water = T,waterdepth = 15,
zoom = .8) # 水平面100
render_path(extent = attr(map.bys,"extent"),
lat = map.xyz[,1], long =map.xyz[,2],
altitude =map.xyz[,3], zscale=5,color="#FFCCCC")
render_snapshot()
dev.copy(png, "diy添加3D路线.png", width = 400, height = 400);dev.off() # 保存当前显示的图像
# Sat Oct 17 14:08:28 2020 --diy,ok
#
#阴影
#我们将海拔高度设置在水面上方,以使轨道具有“阴影”。
render_path(extent = attr(montereybay,"extent"),
lat = unlist(bird_track_lat), long = unlist(bird_track_long),
altitude = 10, zscale=50, color="black", antialias=TRUE)
render_camera(theta=30,phi=35,zoom=0.45,fov=70)
render_snapshot()
dev.copy(png, "添加阴影.png");dev.off()
# 删除路径:
render_path(clear_previous=TRUE)
# 通过离开海拔高度'NULL'来绘制与地面偏移的GPS坐标。#在这里,我们绘制了围绕Moss Landing的螺旋形数值。 这需要原始的高度图。
t = seq(0,2*pi,length.out=1000)
circle_coords_lat = moss_landing_coord[1] + 0.5 * t/8 * sin(t*6)
circle_coords_long = moss_landing_coord[2] + 0.5 * t/8 * cos(t*6)
render_path(extent = attr(montereybay,"extent"), heightmap = montereybay,
lat = unlist(circle_coords_lat), long = unlist(circle_coords_long),
zscale=50, color="red", antialias=TRUE,offset=100, linewidth=5)
render_camera(theta = 160, phi=33, zoom=0.4, fov=55)
render_snapshot()
dev.copy(png,'搞笑的路线图.jpg');dev.off()
#And all of these work with
render_highquality()
render_highquality(clamp_value=10, line_radius=3)
rgl::rgl.close()
R语言,rayshader包,render_path函数,渲染三维路径路线
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...