【问题标题】:How to export high quality resolution images using Rayshader R如何使用 Rayshader R 导出高质量分辨率图像
【发布时间】:2020-10-05 00:50:08
【问题描述】:

我一直在将 R 中的 Rayshader 包与 RStudio 结合使用,并制作了一些不错的 2D 和 3D 图像。

我通常使用下拉框直接从 RStudio 查看面板导出图像,然后选择所需的格式,即 pdf 或 png。这似乎适用于 Rayshader plot_map() 函数生成的 2D 图像。

但是,对于 plot_3d() 函数,图像会在 rgl 查看器中显示几秒钟,然后消失,然后重新出现在 RStudio 查看面板中。查看面板中的图像相当小,然后当我尝试按上述方式导出图像时,它们的质量很差。

render_snapshot() 函数旨在保存文件,但到目前为止我还不能让它工作。任何帮助表示赞赏。

那么,对于如何将 Rayshader 生成的高质量图像直接保存到我的工作目录中,有人有什么建议吗?

我目前使用的代码如下。

library(dplyr)
library(ggplot2)
library(raster)
library(rgdal)
library(scales)
library(rgeos)
library(sp)
library(ggspatial)
library(sf)
library(rayshader)

dem1<- getData("SRTM",lat=34.5,lon=33)
dem2<- getData("SRTM",lat=34.5,lon=36)
dem3<- getData("SRTM",lat=36,lon=33)
dem4<- getData("SRTM",lat=36,lon=36)
dem <- merge(dem1,dem2, dem3, dem4)

#Create polygon to crop the elevation data file   
Ps1 = as(extent(34.5, 35, 31.5, 32), 'SpatialPolygons')
crs(Ps1) = "+proj=longlat +datum=WGS84 +no_defs"
#crop the elevation data using the polygon
dem = crop(dem, Ps1, snap= 'out')

#Create input matrix for Rayshader plot
elev_matrix <- matrix(
  raster::extract(dem, raster::extent(dem), buffer = 1000), 
  nrow = ncol(dem), ncol = nrow(dem)
)
elev_matrix[is.na(elev_matrix)] = 0

#Produce 3D map - remember that the y axis for render_label is in -ve direction
elev_matrix %>%
  sphere_shade(texture = "imhof2") %>%
  add_water(detect_water(elev_matrix), color = "desert") %>%
  add_shadow(ray_shade(elev_matrix, zscale = 3), 0.5) %>%
  add_shadow(ambient_shade(elev_matrix), 0) %>%
  plot_3d(elev_matrix, zscale = 30, fov = 0, theta = 335, zoom = 0.75, phi = 25, windowsize = c(10000, 10000))
Sys.sleep(0.2)
render_snapshot(clear = TRUE)

【问题讨论】:

    标签: r rayshader


    【解决方案1】:

    您需要在render_snapshot()中添加一个参数说明输出图像的文件路径和名称。

    render_snapshot("FILENAME.png", clear = TRUE)
    

    同时,该函数渲染的图像分辨率受显示器分辨率的限制。这是目前已知的限制。

    Increase resolution of R rayshader image

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-24
      • 1970-01-01
      • 2014-11-20
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多