0

this is my first post and i will try to describe my problem as exactly as i can without writing a novel. Also since english is not my native language please forgive any ambiguities or spelling errors.

I am currently trying out the rayshader package for R in order to visualise several layers and create a representation of georeferenced data from Berlin. The data i got is a DEM (5m resolution) and a GEOJSON including a building layer including information of the building heights, a water layer and a tree layer including tree heights.

For now only the DEM and the building layer are used. I can render the DEM without any problems. The buildingpolygons are also getting extruded and rendered, but their foundation height does not coincide with the corresponding height that should be read from the elevation matrix created from the DEM.

I expected the polygons to be placed correctly and "stand" on the rendered surface, but most of them clip through said surface or are stuck inside the ground layer. My assumption is, that i use a wrong function for my purpose - the creator of the package uses render_multipolygonz() for buildings as can be seen here timecode 12:49. I tried that, but it just renders an unextruded continuous polygon on my base layer underneath the ground. Or that i am missing an Argument of the render_polygons() function.

It could also be quite possible, that i am producing a superficial calling or assignment error, since i am all but an expert in R. I am just starting my coding journey.

Here is my code:

#set wd to save location
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))

#load libs
library(geojsonR)
library(rayshader)
library(raster)
library(sf)
library(rgdal)
library(dplyr)
library(rgl)

#load DEM
tempel_DOM <- raster("Daten/Tempelhof_Gelaende_5m_25833.tif")

#load buildings layer from GEOJSON
buildings_temp <- 
  st_read(dsn = "Daten/Tempelhof_GeoJSON_25833.geojson", layer = "polygon") %>%
  st_transform(crs = st_crs(tempel_DOM)) %>%
  filter(!is.na(bh))

#create elevation matrix from DEM
tempel_elmat <- raster_to_matrix(tempel_DOM)

#Tempelhof Render
tempel_elmat %>%
  sphere_shade(texture = "imhof1") %>%
  add_shadow(ray_shade(tempel_elmat), 0.5) %>%
  plot_3d(
    tempel_elmat,
    zscale = 5,
    fov = 0,
    theta = 135,
    zoom = 0.75,
    phi = 45,
    windowsize = c(1000, 800),
  )

render_polygons(
  buildings_temp,
  extent = extent(tempel_DOM),
  color = 'hotpink4',
  parallel = TRUE,
  data_column_top = 'bh',
  clear_previous = T,
)

The structure of my buildings_temp using str() is:

> str(buildings_temp)
Classes ‘sf’ and 'data.frame':  625 obs. of  11 variables:
 $ t       : int  1 1 1 1 1 1 1 1 1 1 ...
 $ t2      : int  NA NA NA NA NA NA NA NA NA NA ...
 $ t3      : int  NA NA NA NA NA NA NA NA NA NA ...
 $ t4      : int  NA NA NA NA NA NA NA NA NA NA ...
 $ t1      : int  1 4 1 1 1 1 1 1 1 1 ...
 $ bh      : num  20.9 2.7 20.5 20.1 19.3 20.9 19.7 19.8 19.6 17.8 ...
 $ t5      : int  NA NA NA NA NA NA NA NA NA NA ...
 $ t6      : int  NA NA NA NA NA NA NA NA NA NA ...
 $ th      : num  NA NA NA NA NA NA NA NA NA NA ...
 $ id      : int  261 262 263 264 265 266 267 268 269 270 ...
 $ geometry:sfc_MULTIPOLYGON of length 625; first list element: List of 1
  ..$ :List of 1
  .. ..$ : num [1:12, 1:2] 393189 393191 393188 393182 393177 ...
  ..- attr(*, "class")= chr [1:3] "XY" "MULTIPOLYGON" "sfg"
 - attr(*, "sf_column")= chr "geometry"
 - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA
  ..- attr(*, "names")= chr [1:10] "t" "t2" "t3" "t4" ...

Thanks in advance for any help.

Cheers WiTell

Phil
  • 7,287
  • 3
  • 36
  • 66
WiTell
  • 1
  • 1

0 Answers0