I have a roof as an OSM building, which I need to convert to an elevation raster to be used for QGIS calculation, with a raster resolution of 9pts/sqm.

Typical OSM building would be: http://city.informatik.uni-bremen.de/~jeff/complex1.osm

However, I'm not able to find a way to convert this OSM building file to a geotiff raster for QGIS. I tried to convert it to shapefile, but I always loose the z elevation.

Would you have any clue on how to perform this conversion ?

2 Answers 2


For flat roofs:

You could manually create a height attribute in the shapefile if you're just doing this for one building. Otherwise, you need to import the OSM and then export the Topology and select Polygons. There is a guide for this kind of thing here: http://learnosm.org/en/osm-data/osm-in-qgis/

Export the polygons to a Shapefile and then use GDAL_rasterize from the commandline (or possibly from QGIS) to burn in the elevation attribute into a blank raster. The last example on the GDAL_rasterize documentation sounds like what you want. http://www.gdal.org/gdal_rasterize.html

For non-flat roofs:

From looking at the XML of your data it seems like you have ridge height line and then a lower height which is presumably the height at the edges/walls /eaves of the building. I guess when visualised these make up planes of the roof. Thus there needs to be an interpolation between heights to arrive at a continous surface (gridded at the raster resolution).

I think your best approach will be to use GRASS. 1) Construct a 3D TIN representation based on your height values, using the ridgeline as a breakline in the triangulation. 2) Then convert this TIN surface to a raster (if you can in GRASS, I'm unsure), or sample the height TIN surface with a pre-defined grid of points that matches your desired raster resolution. I'm hazy on the precise technicalities of 2).

  • Thanks, this process partly works, as it ends up with a flat roof. However, the roof I was considering has slopes with varying elevation, and so the final raster does not show these elevation variation. How could I update this process to reflect the variation of roof elevation in the final raster ?
    – Sébastien
    Aug 23, 2017 at 13:52
  • Ah. Now that's more interesting and involves more processing than just format conversion. I've updated the answer with a recommended approach. Aug 23, 2017 at 14:35
  • Ok, thanks Julian. I will try : 1) import my OSM building to grass using v.in.osm 2) do a 3D TIN on the OSM vector using v.triangle (add on to GRASS) 3) create a raster with the grid resolution required @9pts/sqm 4) match the raster with the vector, ok directly convert the vector to raster if it works. Will let you know, Sébastien
    – Sébastien
    Aug 24, 2017 at 7:12

Julian Rosser answered your actual question, but I'd like to add some information about the OSM data model for roofs. Your example building is somewhat atypical for OSM in that it has roof ridge and edges modeled as geometry. While this is one possible approach, it is only used for 1 in 100 buildings with roof information at the time of writing.

For most buildings, the roof's shape is given as a building attribute (picked from a catalog of common roof designs), and the roof's orientation is provided as another attribute, or inferred from the shape of the building outline. See the relevant section of the "Simple 3D buildings" format in the OSM wiki.

If you know that the buildings you're interested in are using explicitly drawn ridge lines, that's of course not a concern for you. But I felt it was worth pointing out, if only to avoid unpleasant surprises when trying to apply this solution to the general case.

  • In order to solve this issue, I'm now using the cityGML format instead of the OSM xml format, which is more suited for building definition. Then, I converting the CityGML to Objects using the cityGML2OBJs tool (github.com/tudelft3d/CityGML2OBJs). But now, I still have to convert this OBJ file to an elevation raster. Do you know any straightforward way to import this OBJ file to GRASS ? Then, either I can use the built in fonction of GRASS, either I need to use the TIN method described by Julian Rosser.
    – Sébastien
    Sep 12, 2017 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.