Is there a way to programmatically detect if a roof is sloped given raster mask?

85 Views Asked by At

I have some polygons representing building footprints (boundaries) and I am also using lidor raster data which shows elevation for each section in the raster.

I used the guide in this page to mask the raster layer so that I only have the raster sections that fall within the building polygons.

I've overlaid the masked raster sections over the building polygons and can see that these roofs are sloped however I'm looking for a programmatic (python) way to detect and mark whether each roof is sloped or flat. (flat roofs will present as uniform shading with the possible exception of chimneys or other building-top structures like water tanks etc).

My code is:

import fiona
import rasterio
import rasterio.mask

with fiona.open("MyShapefile.shp", "r") as shapefile:
    shapes = [feature["geometry"] for feature in shapefile]#
    
with rasterio.open("RasterFile.tif") as src:
    out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
    out_meta = src.meta
    
out_meta.update({"driver": "GTiff",
                 "height": out_image.shape[1],
                 "width": out_image.shape[2],
                 "transform": out_transform})

with rasterio.open("RasterFile_masked.tif", "w", **out_meta) as dest:
    dest.write(out_image)

enter image description here

1

There are 1 best solutions below

0
Sam On

For a flat roof, the median height of the roof is most likely to be the actual height of the roof with only building-top structures significantly deviating from this height.

For sloped roofs, most of the roof heights deviate from the median.

In short, roofs where more than a certain percentage (let's say 10%) of the heights deviate from the median height are likely to be sloped.