tylermorganwall / rayshader

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

overlay a raster layer over plot_3d #191

Closed aguscamacho closed 1 year ago

aguscamacho commented 2 years ago

Dearlist, I am trying to implement this spectacular visualization tool and the only thing that seems to get in the way is to be able of overlapping raster layers over the 3dplot, How couldthat be possible? I tried add_overlay,but I cannot understand how to proceed from the error message.

require(raster) altc=getData('alt', country='MOZ',mask=T) elevation_matrix = raster_to_matrix(altc)

y=raster(https://www.dropbox.com/s/zhsu204du0rgbjp/Tlim_margins_Mozambique.grd?dl=0)

mat_reduced <- resize_matrix(elevation_matrix, 0.7)

mat_reduced |> sphere_shade(texture = create_texture(lightcolor = "white", shadowcolor = "black", leftcolor = "grey", rightcolor = "grey", centercolor = "grey", cornercolors = c(NW = "#ffc500", NE = "#387642", SW = "#d27441", SE = "#296176")), colorintensity=0.12, sunangle = 45) |>

plot_3d(mat_tx_reduced, windowsize = c(800, 600), zscale = 200, zoom = 0.65, phi = 80, theta = 0, fov = 0, shadow = TRUE, shadowcolor = "#5da5da", water = TRUE, watercolor= "lightblue", waterlinecolor="lightblue")|> add_overlay(overlay=y, alphalayer = 0.5) Error in .local(x, i = i, j = j, ..., value) : unused argument (value)

tylermorganwall commented 2 years ago

Hi, the issue here is the order of the operations: you need to add the overlay prior to plotting it in 3D.

Like this:


mat_reduced |>
  sphere_shade() |>
  add_overlay(overlay=y, alphalayer = 0.5)
  plot_3d(mat_tx_reduced)

You will also have to transform your raster layer into a RGB 3-layer array first (right now, you're passing the raw raster object).

aguscamacho commented 2 years ago

Thank you, but how did you plot without the heightmap argument? When I try to follow your hint, I get:

The "heightmap" argument is absent, with no default value.

Also, when typing ?plot3d, I get "Internal Server Error".

Regards Agus

Dr. Agustín Camacho Guerrero. Marie Curie Researcher. http://www.agustincamacho.com Departamento de Ecología Evolutiva. Estación Biológica de Doñana. CSIC.

Avenida Américo Vespucio, núm 26

Isla de la Cartuja. CP: 41092.

Sevilla. España.

"Unámonos por un mundo mejor, sin injusticia, libre y sin fronteras. Pero con mucho respeto hacia todas las personas y especies."

Anderson, Perú, simpatizante de Avaaz.

El dom, 10 oct 2021 a las 16:44, tylermorganwall @.***>) escribió:

Hi, the issue here is the order of the operations: you need to add the overlay prior to plotting it in 3D.

Like this:

mat_reduced |> sphere_shade() |> add_overlay(overlay=y, alphalayer = 0.5) plot_3d(mat_tx_reduced)

You will also have to transform your raster layer into a RGB 3-layer array first (right now, you're passing the raw raster object).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tylermorganwall/rayshader/issues/191#issuecomment-939494523, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK6HUBB2ARHENDS5YM5GHDUGGREDANCNFSM5E2FQXVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tylermorganwall commented 2 years ago

You need to run your original code: I just gave a general outline of what the code should look like, not the exact code you should use.

In this case, replace mat_tx_reduced with mat_reduced.

aguscamacho commented 2 years ago

Thanks again, but I am afraid the problem is not a confusion with the name of the object. Apparently, I need a hillshade image for plot_3d, but when I added one, created from the same elevation raster, I got another error:

plot_3d(heightmap=mat_reduced,hillshade=hill,
      windowsize = c(800, 600),
      zscale = 200,
      zoom = 0.65,
      phi = 80,
      theta = 0,
      fov = 0,
      shadow = TRUE,
      shadowcolor = "#5da5da",
      water = TRUE,
      watercolor= "lightblue",
      waterlinecolor="lightblue")

Error in if (any(hillshade > 1 | hillshade < 0, na.rm = TRUE)) { : Argument not interpretable as logical Warning message: In any(new("RasterLayer", file = new(".RasterFile", name = "", datanotation = "LOG1S", : Nothing to summarize if you provide a single RasterLayer; see cellStats

Also, I am unclear about what this means: "You will also have to transform your raster layer into a RGB 3-layer array first" I am following this tutorial: https://www.rayshader.com/ Where I do not see that step. Maybe array=as.array(alt) Would get me such array, but where do I insert it in the function?

Best regards Agus

Dr. Agustín Camacho Guerrero. Marie Curie Researcher. http://www.agustincamacho.com Departamento de Ecología Evolutiva. Estación Biológica de Doñana. CSIC.

Avenida Américo Vespucio, núm 26

Isla de la Cartuja. CP: 41092.

Sevilla. España.

"Unámonos por un mundo mejor, sin injusticia, libre y sin fronteras. Pero con mucho respeto hacia todas las personas y especies."

Anderson, Perú, simpatizante de Avaaz.

El dom, 10 oct 2021 a las 19:42, tylermorganwall @.***>) escribió:

You need to run your original code: I just gave a general outline of what the code should look like, not the exact code you should use.

In this case, replace mat_tx_reduced with mat_reduced.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tylermorganwall/rayshader/issues/191#issuecomment-939522681, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK6HUH3UTL2EJN3ARGEUS3UGHGABANCNFSM5E2FQXVQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

tylermorganwall commented 1 year ago

I would recommend following some of the tutorials out there for rayshader: I have many on my site (tylermw.com) and rayshader.com has quite extensive documentation.