tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.05k stars 211 forks source link

offset argument in `render_buildings` does not match vertical_offset argument in raybevel's `generate_roof` #304

Closed tteo closed 8 months ago

tteo commented 8 months ago

Describe the bug Running render_buildings() throws this error: Error in raybevel::generate_roof(skeletons, offset = top, base_height = 0, : unused argument (offset = top)

Fixed bug by replacing offset argument in render_buildings() with the correct vertical_offset argument in generate_roof

Session Info

R version 4.3.2 (2023-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22631)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8    LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                           LC_TIME=English_United States.utf8    

time zone: America/New_York
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] raybevel_0.1.0   rayshader_0.37.0 raster_3.6-26    sp_2.1-2         osmdata_0.2.5   

loaded via a namespace (and not attached):
 [1] xfun_0.41          httr2_1.0.0        htmlwidgets_1.6.4  lattice_0.21-9     vctrs_0.6.5        tools_4.3.2       
 [7] generics_0.1.3     curl_5.2.0         parallel_4.3.2     rgl_1.2.9          tibble_3.2.1       proxy_0.4-27      
[13] fansi_1.0.6        pkgconfig_2.0.3    KernSmooth_2.23-22 lifecycle_1.0.4    compiler_4.3.2     progress_1.2.3    
[19] terra_1.7-65       codetools_0.2-19   htmltools_0.5.7    class_7.3-22       rayimage_0.10.0    pillar_1.9.0      
[25] crayon_1.5.2       classInt_0.4-10    slippymath_0.3.1   elevatr_0.99.0     wk_0.9.1           magick_2.8.2      
[31] iterators_1.0.14   foreach_1.5.2      tidyselect_1.2.0   digest_0.6.34      sf_1.0-15          dplyr_1.1.4       
[37] purrr_1.0.2        fastmap_1.1.1      grid_4.3.2         cli_3.6.2          magrittr_2.0.3     base64enc_0.1-3   
[43] utf8_1.2.4         e1071_1.7-14       prettyunits_1.2.0  rappdirs_0.3.3     lubridate_1.9.3    timechange_0.2.0  
[49] httr_1.4.7         progressr_0.14.0   png_0.1-8          hms_1.1.3          knitr_1.45         rayvertex_0.10.4  
[55] doParallel_1.0.17  s2_1.1.6           rlang_1.1.3        Rcpp_1.0.12        glue_1.7.0         DBI_1.2.0         
[61] xml2_1.3.6         decido_0.3.0       rstudioapi_0.15.0  jsonlite_1.8.8     R6_2.5.1           units_0.8-5  

Reproducible Example Please provide a reproducible example that triggers the bug below.

library(rayshader)
library(osmdata)
library(raster)

osm_bbox = c(-121.9472, 36.6019, -121.9179, 36.6385)

opq(osm_bbox) |>
  add_osm_feature("building") |>
  osmdata_sf() ->
  osm_data

opq(osm_bbox) |>
  add_osm_feature("highway") |>
  osmdata_sf() ->
  osm_road

building_polys = osm_data$osm_polygons
osm_dem = elevatr::get_elev_raster(building_polys, z = 11, clip = "bbox")
e = extent(building_polys)

osm_dem |>
  crop(e) |>
  extent() ->
  new_e

osm_dem |>
  crop(e) |>
  raster_to_matrix() ->
  osm_mat

osm_mat[osm_mat <= 1] = -2

osm_mat %>%
  rayimage::render_resized(mag=4) |>
  sphere_shade(texture = "desert") |>
  add_overlay(generate_polygon_overlay(building_polys, extent = new_e,
                                       heightmap = osm_mat,
                                       linewidth = 6,
                                       resolution_multiply = 50), rescale_original = TRUE) |>
  add_overlay(generate_line_overlay(osm_road$osm_lines, extent = new_e,
                                    heightmap = osm_mat,
                                    linewidth = 6,
                                    resolution_multiply = 50), rescale_original = TRUE) |>
  plot_3d(osm_mat, water = TRUE, windowsize = 800, watercolor = "dodgerblue",
          zscale = 10, theta=220, phi=22, zoom=0.45, fov=110,
          background = "pink")

#error occurs here
render_buildings(building_polys,  flat_shading  = TRUE,
                 angle = 30 , heightmap = osm_mat,
                 material = "white", roof_material = "white",
                 extent = new_e, roof_height = 3, base_height = 0,
                 zscale=10)
tylermorganwall commented 8 months ago

Thanks for the pull request!