rayshader R包中的render_highquality仅渲染黑色.png图像

2w3kk1z5  于 2023-01-18  发布在  其他
关注(0)|答案(1)|浏览(153)

我正在遵循这个教程:https://www.youtube.com/watch?v=zgFXVhmKNbU&lc=Ugxj9Lfa6m7FfLaJlzN4AaABAg.9kn2A9lbmnP9kn2SD5s2vs在video render_highquality函数中,成功将3d绘图导出为. png图像。我的代码运行良好。render_highquality之前的所有内容都能产生预期的输出,但render_highquality却不能。我正在导出图像,但. png图像导出为全黑图像,我不知道发生了什么,也不知道如何修复它。其他注意事项包括render_snapshot和save_obj函数也运行良好。
下面是我的代码:

library(rayshader)
library(MetBrewer)
library(colorspace)
library(sf)
library(raster)
library(ggplot2)
library(stars)

data <- st_read("data/kontur_population_MX_20220630.gpkg")
ags <- getData("GADM", country = "Mexico", level = 1) %>% 
  st_as_sf() %>%
  filter(NAME_1 == "Aguascalientes") |> 
  st_transform(crs= st_crs(data))

st_ags <- st_intersection(data, ags)

bb <- st_bbox(st_ags)

bottom_left <- st_point(c(bb[["xmin"]], bb[["ymin"]])) |> 
  st_sfc(crs = st_crs(data))

bottom_right <- st_point(c(bb[["xmax"]], bb[["ymin"]])) |> 
  st_sfc(crs = st_crs(data))

width <- st_distance(bottom_left, bottom_right)

top_left <- st_point(c(bb[["xmin"]], bb[["ymax"]])) |> 
  st_sfc(crs = st_crs(data))

height <- st_distance(bottom_left, top_left)

if (width > height) {
  w_ratio <- 1
  h_ratio <- height / width
} else {
  h_ration <- 1
  w_ratio <- width / height
}

size <- 1000

ags_rast <- st_rasterize(st_ags, 
                     nx = floor(size * w_ratio),
                     ny = floor(size * h_ratio))

mat <- matrix(ags_rast$population, 
          nrow = floor(size * w_ratio),
          ncol = floor(size * h_ratio))

c1 <- met.brewer("OKeeffe2")
swatchplot(c1)

texture <- grDevices::colorRampPalette(c1, bias = 2)(256)
swatchplot(texture)

mat |> 
  height_shade(texture = texture) |> 
  plot_3d(heightmap = mat,
          zscale = 100,
          solid = FALSE,
          shadowdepth = 0)

png_outfile <- 'imgs/ags_model.png'

render_camera(theta = -20, phi = 45, zoom = .8)

render_highquality(
  filename = png_outfile
)

我唯一尝试过的解决问题的方法是使用以下命令从GitHub中删除并重新安装rayshader包:
devtools::install_github("tylermorganwall/rayshader")我正在使用Mac OS Ventura 13.0.1的M1 Mac mini

hc2pp10m

hc2pp10m1#

通过remotes重新安装rayshader和rayrender包就可以了。

install.packages("remotes")
remotes::install_github("tylermorganwall/rayshader")
remotes::install_github("tylermorganwall/rayrender")

相关问题