h-a-graham / rayvista

An R plugin for {rayshader} to view a 3D vista anywhere on earth.
GNU General Public License v3.0
107 stars 5 forks source link

Errorin col2rgb(colors) : no method for coercing this S4 class to a vector #31

Closed mariepastora closed 2 years ago

mariepastora commented 2 years ago

Hello, This is such a great package -- thanks for writing it! I'm trying to use render_polygons() on top of a plot_3d_vista(), and getting the following error message:

Errorin col2rgb(colors) : 
  no method for coercing this S4 class to a vector

I'm not sure of what's happening here. My polygon is a Simple Feature looking like this:

Simple feature collection with 1 feature and 8 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: -105.3896 ymin: 39.93475 xmax: -105.3558 ymax: 39.95643

Its datum is WGS84.

I'm calling render_polygons like this:

render_polygons(mypolygon,
                attr(cropped_dem, "extent"),
                cropped_dem,
                parallel = TRUE,
                top = 10
                )

cropped_dem being an elevation raster in WGS84 that is a bit larger than the area generated via plot_3d_vista. Would you have any idea of what might be happening? Thanks so much!

mariepastora commented 2 years ago

Hi again, after a bit of struggle it looks like my issue was a projection issue, along with the extent not being the same exact size as plot_3d_vista(). I've successfully generated polygons, but they appear to be upside down:

Screen Shot 2021-11-12 at 5 44 18 PM

when fiddling with the top and bottom parameters of render_polygons, it gets partially solved, but just offsets the polygon quite dramatically.

Screen Shot 2021-11-12 at 5 42 29 PM

Everything is in EPSG 4326, so I doubt it's a projection issue now. Any clue on what might be happening? Is there a way to use rayvista with generate_overlay() from rayshader instead? Thanks so much!

h-a-graham commented 2 years ago

Hi Marie, thanks for this issue. This is possible, but I'll admit that it is unintuitive and the documentation really isn't helpful so here is a reprex which should hopefully give you an idea of what you need. FYI, I am working an alternative to {rayvista} which should make these kind of things much simpler and more in keeping with a typical {rayshader} workflow.


library(rayvista)
library(rayshader)
library(sf)

demo(nc, ask = FALSE, echo = FALSE)
nc

nc_layers <- plot_3d_vista(req_area = nc, elevation_detail = 5,
                      overlay_detail = 8, show_vista = F)

# overlay example
nc_layers$texture %>%
  add_overlay(., generate_polygon_overlay(nc,
                                          extent=attr(nc_layers$dem_matrix, 'extent'),
                                          heightmap = nc_layers$dem_matrix,
                                          palette = NA)) %>%
  plot_3d(nc_layers$dem_matrix, zscale=100)

# rgl::clear3d()
# render_polygons example

nc_layers2 <- plot_3d_vista(req_area = nc, elevation_detail = 5,
                           overlay_detail = 8, show_vista = T, zscale=100)

render_polygons(nc, attr(nc_layers2, 'extent'), data_column_top='AREA',
                scale=100)

Please let me know if this solves things or if you have any other questions, Cheers, Hugh

mariepastora commented 2 years ago

Wow thank you this worked wonders! Thank you for taking the time, and can't wait to see the alternative to rayvista, too.