Closed bianchenhao closed 2 years ago
Hi, so I can't reproduce this: This is the output for me:
library(rayshader)
library(rayvista)
.lat <- 23.30974
.long <- 111.04041
cuillins <- plot_3d_vista(lat = .lat, long = .long,
phi=30,
radius = 5000,
elevation_detail = 14,
overlay_detail=15,
outlier_filter = 0.001)
#> Downloading overlay...
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj): PROJ/GDAL PROJ string degradation in workflow
#> repeated warnings suppressed
#> Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
#> Mosaicing & Projecting
#> Clipping DEM to bbox
render_snapshot()
Created on 2022-03-23 by the reprex package (v2.0.0)
What version of elevatr do you have installed? packageVersion('elevatr')
If you are unable to get rayvista working, I am currently devleoping a new version {raytrix} which is more flexible and generally faster but has pretty poor documentation at present: https://github.com/h-a-graham/raytrix You could reproduce your example with this package like so:
library(raytrix)
library(rayshader)
.lat <- 23.30974
.long <- 111.04041
set_canvas_centroid(.lat, .long, radius=5000)
#> Warning in set_canvas_centroid(.lat, .long, radius = 5000):
#> `set_canvas_centroid() `converts coordinates to web mercator for convnience.to
#> set a specific canvas extent and projection use `set_canvas()`
dem <- topo_matrix(10)
sat <- map_drape(5, src="wms_googlemaps_satellite_tms")
plot_3d(sat, dem, zscale=4)
render_snapshot()
Created on 2022-03-23 by the reprex package (v2.0.0)
Hi, rayvista
still reports the same error.
raytrix
works!
This is my sessioninfo:
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936 LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] raytrix_0.0.1 elevatr_0.4.2 rayvista_0.1.7.4 rayshader_0.24.10
loaded via a namespace (and not attached):
[1] gdalwebsrv_0.0.0.9001 pkgload_1.2.4 jsonlite_1.8.0 foreach_1.5.2 brio_1.1.3 assertthat_0.2.1 sp_1.4-6
[8] remotes_2.4.2 progress_1.2.2 sessioninfo_1.2.2 pillar_1.7.0 lattice_0.20-45 glue_1.6.2 digest_0.6.29
[15] colorspace_2.0-3 htmltools_0.5.2 slippymath_0.3.1 pkgconfig_2.0.3 devtools_2.4.3 raster_3.5-15 magick_2.7.3
[22] purrr_0.3.4 scales_1.1.1 processx_3.5.2 terra_1.5-21 maptiles_0.3.0 tibble_3.1.6 proxy_0.4-26
[29] generics_0.1.2 usethis_2.1.5 ellipsis_0.3.2 cachem_1.0.6 withr_2.5.0 vapour_0.8.5 cli_3.2.0
[36] magrittr_2.0.2 crayon_1.5.0 memoise_2.0.1 ps_1.6.0 fs_1.5.2 fansi_1.0.2 doParallel_1.0.17
[43] class_7.3-19 pkgbuild_1.3.1 progressr_0.10.0 tools_4.1.2 prettyunits_1.1.1 hms_1.1.1 lifecycle_1.0.1
[50] topography_0.0.0.9003 munsell_0.5.0 callr_3.7.0 compiler_4.1.2 e1071_1.7-9 rlang_1.0.1 classInt_0.4-3
[57] units_0.8-0 grid_4.1.2 iterators_1.0.14 rstudioapi_0.13 htmlwidgets_1.5.4 testthat_3.1.2 codetools_0.2-18
[64] DBI_1.1.2 curl_4.3.2 R6_2.5.1 knitr_1.37 dplyr_1.0.8 rgdal_1.5-29 fastmap_1.1.0
[71] utf8_1.2.2 rprojroot_2.0.2 KernSmooth_2.23-20 desc_1.4.1 parallel_4.1.2 Rcpp_1.0.8 vctrs_0.3.8
[78] sf_1.0-7 png_0.1-7 rgl_0.108.3 tidyselect_1.1.2 xfun_0.30
Can I also ask a question:
In render_highquality
or render_snapshot
, how to set specific lookat(longtitude, latitude, altitude)?
I have movement track (longtitude, latitude, altitude), and I can calculate tangent of track using rayrender::generate_camera_motion
, output like:
> camera_motion_real = generate_camera_motion(selected_points_offset, selected_points_offset,
+ closed=TRUE, fovs = 90, constant_step = TRUE,
+ frames=480,
+ offset_lookat = 1)
> camera_motion_real
x y z dx dy dz aperture fov focal orthox orthoy upx upy upz
1 110.7713 29100.15 23.36182 110.7858 29100.57 23.35940 0 90 0.4159204 1 1 0 1 0
254 110.8407 29114.94 23.35025 110.8407 29115.94 23.35024 0 90 1.0000000 1 1 0 1 0
275 110.8429 29257.29 23.34860 110.8429 29258.29 23.34858 0 90 1.0000000 1 1 0 1 0
298 110.8495 29149.28 23.34850 110.8496 29148.28 23.34851 0 90 1.0000000 1 1 0 1 0
305 110.8531 29006.92 23.34923 110.8531 29005.92 23.34923 0 90 1.0000000 1 1 0 1 0
310 110.8562 28864.57 23.35000 110.8562 28863.57 23.35001 0 90 1.0000000 1 1 0 1 0
314 110.8591 28722.21 23.35079 110.8591 28721.21 23.35079 0 90 1.0000000 1 1 0 1 0
318 110.8618 28579.85 23.35156 110.8619 28578.85 23.35156 0 90 1.0000000 1 1 0 1 0
321 110.8645 28437.49 23.35231 110.8645 28436.49 23.35232 0 90 1.0000000 1 1 0 1 0
But how to use this format of lookat in render_highquality
or render_snapshot
?
Oky so I'm not sure what is causing this issue - your packages all look up do date and sensible... Do you mind testin the following reprex, please? Hopefully it will help us to isolate the problem... I did see this issue: https://github.com/jhollist/elevatr/issues/66 which could be related - looks like your elevatr install is up to date but may be worth installing from github withremotes::install_github("jhollist/elevatr")
...
library(sf)
#> Linking to GEOS 3.10.1, GDAL 3.4.0, PROJ 8.2.0; sf_use_s2() is TRUE
library(elevatr)
library(mapview)
#> Warning: multiple methods tables found for 'crop'
#> Warning: multiple methods tables found for 'extend'
define_extent <- function(lat, long, radius, epsg){
extent_sf <- sf::st_sfc(sf::st_point(c(long, lat))) %>%
sf::st_set_crs(epsg) %>%
sf::st_transform(3857) %>%
sf::st_buffer(radius)%>%
sf::st_bbox()%>%
sf::st_as_sfc()%>%
sf::st_sf()
return(extent_sf)
}
bounds_sf <- define_extent(.lat <- 23.30974,
.long <- 111.04041,
radius=7000,
epsg=4326)
print(bounds_sf)
#> Simple feature collection with 1 feature and 0 fields
#> Geometry type: POLYGON
#> Dimension: XY
#> Bounding box: xmin: 12353960 ymin: 2662520 xmax: 12367960 ymax: 2676520
#> Projected CRS: WGS 84 / Pseudo-Mercator
#> geometry
#> 1 POLYGON ((12353962 2662520,...
mapview(bounds_sf)
el <- get_elev_raster(bounds_sf, z=10, clip='bbox',
neg_to_na = FALSE, verbose = F, src="aws")
#> Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj): PROJ/GDAL PROJ string degradation in workflow
#> repeated warnings suppressed
#> Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs
#> Mosaicing & Projecting
#> Clipping DEM to bbox
print(el)
#> class : RasterLayer
#> dimensions : 209, 209, 43681 (nrow, ncol, ncell)
#> resolution : 76.43703, 76.43703 (x, y)
#> extent : 12352988, 12368963, 2661537, 2677513 (xmin, xmax, ymin, ymax)
#> crs : +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs
#> source : memory
#> names : file154c374302231
#> values : -7, 347 (min, max)
mapview(el)
Created on 2022-03-25 by the reprex package (v2.0.0)
On your other question. I've not used these functions much but I think you have to create a scene in rayrender which you can then animate with render_animation and camera_position. here is an example:
library(raytrix)
library(av)
library(stringr)
library(rayshader)
library(rayrender)
.lat <- 23.30974
.long <- 111.04041
set_canvas_centroid(.lat, .long, radius=5000)
#> Warning in set_canvas_centroid(.lat, .long, radius = 5000):
#> `set_canvas_centroid() `converts coordinates to web mercator for convnience.to
#> set a specific canvas extent and projection use `set_canvas()`
dem <- topo_matrix(100)
sat <- map_drape(25, src="wms_googlemaps_satellite_tms")
plot_3d(sat, dem, zscale=10)
tmp <- tempfile(fileext = ".obj")
rayshader::save_obj(tmp)
scene <- generate_ground(depth=-10, material =
diffuse(checkercolor="grey50")) %>%
add_object(obj_model(tmp, texture = T)) %>%
add_object(sphere(x=240,y=80,z=160,radius=12,
material=light(color = '#FFA271',
intensity = 900,
spotlight_focus= c(-100,0,-100))))
camera_pos = list(c(500, 120, 105),c(100, 120, 105))
camera_motion = generate_camera_motion(positions = camera_pos)
mydir <- 'rayimages'
if (!file.exists(mydir)) dir.create(mydir)
fname <- file.path(mydir, 'rayimage')
render_animation(scene, camera_motion, samples=5, filename = fname,
sample_method="sobol_blue",
clamp_value=10, width=1000, height=400)
png_files <- list.files(mydir,'*.png', full.names = TRUE) %>%
str_sort(numeric = TRUE)
av_encode_video(png_files, framerate = 24,
output = 'rayimages/animation.mp4')
#> [1] "rayimages/animation.mp4"
Created on 2022-03-25 by the reprex package (v2.0.0)
Thanks for your reply! Testing outputs following:
Same error occurs in Code part2:
when I used remotes::install_github("jhollist/elevatr")
to reinstall elevatr, Code part2 works. Map generated:
but some errors appeared:
> mapview(el)
Error in (function (x) : attempt to apply non-function
Error in (function (x) : attempt to apply non-function
Error in (function (x) : attempt to apply non-function
Great, so does your original example work now?
Great, so does your original example work now?
It works now.thanks!
You're welcome!
On your other question. I've not used these functions much but I think you have to create a scene in rayrender which you can then animate with render_animation and camera_position. here is an example: ...... png_files <- list.files(mydir,'*.png', full.names = TRUE) %>% str_sort(numeric = TRUE)
av_encode_video(png_files, framerate = 24, output = 'rayimages/animation.mp4')
> [1] "rayimages/animation.mp4"
animation.mp4 Created on 2022-03-25 by the [reprex package](https://reprex.tidyverse.org) (v2.0.0)
I tried save obj file, then load it into rayrender.But I don't know how to align the coordinate system.
raytrix
turned lng, lat to WGS84, and x ranges from 12330816 to 12368403. when it's loaded in rayrender
, i don't know how to align the coordinate system of lookat and lookfrom consistent with WGS84 in saved obj.
Sure, so rayrender isn't using a geographic CRS, it is all about distance relative to the centre of the scene c(0,0,0).
So you need to convert your coordinates into a range readable by rayrender.
In my example, see the line:
camera_pos = list(c(500, 120, 105),c(100, 120, 105))
for each position the items describe c([ZOOM], [THETA], [PHI]) I think.
I image there is some clever way to do this, otherwise trial and error is the best option.
I don't know why this error occurs. longtitude is 111.04041.
error: