tylermorganwall / rayshader

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

simulating bathymetric data #209

Closed apsteinmetz closed 2 years ago

apsteinmetz commented 2 years ago

Along the lines of your cloud rendering, I'd like to suggest simulated bathymetric data. Recently I was using Canadian coastal data and found that, among the craggy fjords of British Columbia, some areas had depth data while others did not. The transitions were kind of jarring so I cobbled together a function to add fake depth data only where depth info is missing. It is not a good one as the bottoms look fake but it is a small improvement. If you are interested I'll link to before and after samples. A fractal generator would be a better approach and I gather your work on clouds probably might apply. Here's what I got:

# Change zero depths to fake depth based on distance to shore
fake_depth <- function(elev_depth_matrix,depth_step=5) {
  zeroes <- which(elev_depth_matrix == 0,arr.ind = T)
  maxrow <- dim(elev_depth_matrix)[1]
  maxcol <- dim(elev_depth_matrix)[2]
  for (i in 1:nrow(zeroes)){
    row <- zeroes[i,1] 
    col <- zeroes[i,2]
    found_shore = FALSE
    distance_to_shore = 1
    adjacent_level <- c(0,0,0,0)
    while (!found_shore) {
      if (row > distance_to_shore) adjacent_level[1] <- elev_depth_matrix[row - distance_to_shore, col] # south
      if (col > distance_to_shore) adjacent_level[2] <- elev_depth_matrix[row , col - distance_to_shore] # west
      if (row < maxrow - distance_to_shore) adjacent_level[3] <- elev_depth_matrix[row + distance_to_shore, col] # north
      if (col < maxcol - distance_to_shore) adjacent_level[4] <- elev_depth_matrix[row , col + distance_to_shore] # east
      found_shore <- (max(adjacent_level) > 0)
      if (found_shore) {
        elev_depth_matrix[row,col] <- -depth_step * distance_to_shore
      } else {
        distance_to_shore <- distance_to_shore + 1
      }
    }
  }
  return(elev_depth_matrix)
}
tylermorganwall commented 2 years ago

I think this would be good addition to an external package, but I don't think it fits well within rayshader. Clouds are just "window dressing" for the data being visualized, so the fact that the clouds are fake (i.e. not derived from data) isn't a big deal. Visualization of 3D terrain/bathymetry, however, is a primary purpose of the package, so I would be hesitant to add a feature that generates fake data to add to a scene.

apsteinmetz commented 2 years ago

makes sense. Thanks.