# Generate DEM with Buildings

- get bbox for location
- download dem
- download buildings shape
- calculate elevation of building rooftops
- rasterize shapefile
- 3d plot
- disaggregate to get higher resolution

Runoff simulations in urban areas necessarily need to include buildings as obstacles for surface runoff. Since most digital elevation models (dem) have buildings and vegetation digitally removed we have to add the buildings back in. Of course you could use a digtial surface model (dsm) which includes vegetation and buildings. But vegetation is a completely different obstacle that has to be treated differently than buildings. So it would be nice to only have buildings in the height map.

Our approach here will be to download a dem from the Geobasis NRW service of the German state Nordhrein Westfalen (NRW) and add buildings from another data product they provide.

Let’s start with loading the necessary packets:

# get bbox for location

In order to download data we will need a bounding box for the data query. We will work with a location that in 2021 got sadly famous for a very deverstating flood event.

We will add a radius of 100 meters around the central location and take that as a bounding box.

To get an impression of the location here you have a code and screenshot to produce an interactive openstreetmap plot of the location:

# download dem

To download the dem we use the `raster()`

function of the raster package. More about that process you can learn in the tutorial about wcs data.

# download buildings shape

To download shapefiles we use the `read_sf()`

function of the sf package. More about this you can learn in the tutorial about wfs data.

Let’s plot dem and buildings together:

# calculate elevation of building rooftops

The actual height of the building is not that relevant for the flow simulation. It only has to be a height that effectively blocks the flow path. Therefore we will give all buildings the same height of 8 meters. We will also make the rooftops flat since we don’t have any information about the roof types and roofs usually are drained into the sewer system.

Where buildings are located at a slope we will give the building a height of 8 meters above the highest point of the terrain they are standing on. Therefore we first calculate the maximum height at location of building:

Calculate rooftop height as 8 meters above the maximal height:

Plot the results:

# rasterize shapefile

We then rastarize the buildings and merge it with the dem:

# 3d plot

To get a 3d view of the resulting elevation model we use the rayshader package:

# disaggregate to get higher resolution

The dem has a resolution of 1m x 1m. With disaggregation we can render that down to for example 25cm x 25cm. This enables much sharper edges for the buildings.

The corners of the buildings are much sharper now.