我一直收到以下错误。我在这里使用模板https://github.com/Pecners/rayshader_portraits/blob/main/R/portraits/arizona/render_graphic.R
Warning messages:
1: In rgl.primitive0(type = "triangles", x = c(-2499, -2498, -2497, :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
2: In rgl.primitive0(type = "triangles", x = c(2982, 2982, -2981, -2981, :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
Version Info
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status
major 4
minor 2.3
year 2023
month 03
day 15
svn rev 83980
language R
version. String R version 4.2.3 (2023-03-15 ucrt)
nickname Shortstop Beagle
我尝试运行的代码:
library(sf)
library(tidyverse)
library(elevatr)
library(rayshader)
library(glue)
library(colorspace)
library(tigris)
library(stars)
library(MetBrewer)
# Set map name that will be used in file names, and
# to get get boundaries from master NPS list
map <- "arizona"
# Kontur data source: https://data.humdata.org/dataset/kontur-population-united-states-of-america
data <- st_read("data/kontur/kontur_population_US_20220630.gpkg")
s <- states() |>
st_transform(crs = st_crs(data))
st <- s |>
filter(NAME == str_to_title("arizona"))
st |>
ggplot() +
geom_sf()
int <- st_intersects(data, st)
st_dd <- map_dbl(int, function(i) {
if (length(i) > 0) {
return(i)
} else {
return(0)
}
})
st_d <- data[which(st_dd == 1),]
#st_d <- st_intersection(data, st)
bb <- st_bbox(st_d)
yind <- st_distance(st_point(c(bb[["xmin"]], bb[["ymin"]])),
st_point(c(bb[["xmin"]], bb[["ymax"]])))
xind <- st_distance(st_point(c(bb[["xmin"]], bb[["ymin"]])),
st_point(c(bb[["xmax"]], bb[["ymin"]])))
if (yind > xind) {
y_rat <- 1
x_rat <- xind / yind
} else {
x_rat <- 1
y_rat <- yind / xind
}
size <- 8000
rast <- st_rasterize(st_d |>
select(population, geom),
nx = floor(size * x_rat), ny = floor(size * y_rat))
mat <- matrix(rast$population, nrow = floor(size * x_rat), ncol = floor(size * y_rat))
# set up color palette
pal <- "demuth"
colors <- met.brewer("Tam", 10, direction = -1)
texture <- grDevices::colorRampPalette(colors, bias = 3)(256)
swatchplot(texture)
###################
# Build 3D Object #
###################
# Keep this line so as you're iterating you don't forget to close the
# previous window
try(rgl::rgl.close())
# Create the initial 3D object
mat |>
height_shade(texture = texture) |>
plot_3d(heightmap = mat,
# This is my preference, I don't love the `solid` in most cases
solid = FALSE,
soliddepth = 0,
# You might need to hone this in depending on the data resolution;
# lower values exaggerate the height
z = 15,
# Set the location of the shadow, i.e. where the floor is.
# This is on the same scale as your data, so call `zelev` to see the
# min/max, and set it however far below min as you like.
shadowdepth = 0,
# Set the window size relatively small with the dimensions of our data.
# Don't make this too big because it will just take longer to build,
# and we're going to resize with `render_highquality()` below.
windowsize = c(800,800),
# This is the azimuth, like the angle of the sun.
# 90 degrees is directly above, 0 degrees is a profile view.
phi = 90,
zoom = 1,
# `theta` is the rotations of the map. Keeping it at 0 will preserve
# the standard (i.e. north is up) orientation of a plot
theta = 0,
background = "white")
# Use this to adjust the view after building the window object
render_camera(phi = 60, zoom = .65, theta = 0)
###############################
# Create High Quality Graphic #
###############################
# You should only move on if you have the object set up
# as you want it, including colors, resolution, viewing position, etc.
# Ensure dir exists for these graphics
if (!dir.exists(glue("images/{map}"))) {
dir.create(glue("images/{map}"))
}
# Set up outfile where graphic will be saved.
# Note that I am not tracking the `images` directory, and this
# is because these files are big enough to make tracking them on
# GitHub difficult.
outfile <- str_to_lower(glue("images/{map}/{map}_{pal}.png"))
# Now that everything is assigned, save these objects so we
# can use then in our markup script
saveRDS(list(
map = map,
pal = pal,
colors = colors,
outfile = outfile,
coords = coords
), glue("R/portraits/{map}/header.rds"))
{
# Test write a PNG to ensure the file path is good.
# You don't want `render_highquality()` to fail after it's
# taken hours to render.
if (!file.exists(outfile)) {
png::writePNG(matrix(1), outfile)
}
# I like to track when I start the render
start_time <- Sys.time()
cat(glue("Start Time: {start_time}"), "\n")
render_highquality(
# We test-wrote to this file above, so we know it's good
outfile,
# See rayrender::render_scene for more info, but best
# sample method ('sobol') works best with values over 256
samples = 450,
preview = FALSE,
light = TRUE,
lightdirection = rev(c(200, 200, 210, 210)),
lightcolor = c(colors[3], "white", colors[10], "white"),
lightintensity = c(750, 125, 1000, 125),
lightaltitude = c(10, 80, 10, 80),
# All it takes is accidentally interacting with a render that takes
# hours in total to decide you NEVER want it interactive
interactive = FALSE,
# HDR lighting used to light the scene
# environment_light = "assets/env/phalzer_forest_01_4k.hdr",
# # environment_light = "assets/env/small_rural_road_4k.hdr",
# # Adjust this value to brighten or darken lighting
# intensity_env = 1.5,
# # Rotate the light -- positive values move it counter-clockwise
# rotate_env = 130,
# This effectively sets the resolution of the final graphic,
# because you increase the number of pixels here.
# width = round(6000 * wr), height = round(6000 * hr),
width = 8000, height = 8000
)
end_time <- Sys.time()
cat(glue("Total time: {end_time - start_time}"), "\n")
}
这是我得到错误的地方
mat |>
height_shade(texture = texture) |>
plot_3d(heightmap = mat,
zscale = 100 / 5,
solid = FALSE,
shadowdepth = 0,
)
render_camera(theta = -20, phi = 45, zoom = .8)
我已经完成了重新安装 R、Rstudio、rTools 和所有所需软件包的过程。我昨天刚用这段代码工作,不知道问题出在哪里。
那些消息
Warning messages:
1: In rgl.primitive0(type = "triangles", x = c(-2499, -2498, -2497, :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
2: In rgl.primitive0(type = "triangles", x = c(2982, 2982, -2981, -2981, :
RGL: GL Library : Maximum texture size of 1024x1024 exceeded.
(Perhaps enabling mipmapping could help.)
是警告,不是错误。它们似乎来自
rgl
,它报告底层 OpenGL 库的硬件限制。但是rgl
不选尺码,那大概就是rayshader
。我不知道你怎么能告诉它不要超过那个限制。
只看消息的内容,您的图形驱动程序似乎无法支持非常大的纹理。 (纹理是映射到 3D 表面上的位图图像。)可能图形系统也被其他窗口使用,并且内存不足。或者,如果您在上次运行后切换了机器或视频模式,也许您只是没有新设置中的资源来运行它。
我无法提供更具体的建议,因为您的代码在我的系统上因 R 内存不足错误而死机:
Error: vector memory exhausted (limit reached?)
这发生在
render_camera()
通话期间,或者可能是之前的 plot_3d()
通话:您遇到问题的同一个地方。也许减少window_size = c(800, 800)
参数会有所帮助。