# How to import 3D buildings from OpenStreetMap to Blender

As an OpenStreetMap (OSM) user, but pretty newbie regarding to Blender (I know the basics, but never used in depth because I get lost) or developing, I would like to 3D print some buildings stored in OSM and maybe make some basic renderings/modifications with Blender. After having done some research I've come to two different workflows but unfortunately none of them work for me, so hopefully anyone can tell me how to improve them or provide another one:

I have exported an OSM area into OSM's native format *.osm file (which is an xml file) from their website. Full explanations on exporting an OSM file can be found here. For purposes of this exercise I will be downloading this particular area, which looks like this on this 3D Viewer thanks to the work of the community.

The osm file that I am working with can be downloaded here as well.

BlenderGis Addon provides a lot of interesting features for GIS users. Amongst others it can import osm files geolocate, terrain analysis... it seems great!

Unfortunately the osm importer only imports 2D information of the geometry, and no other osm information is stored (at least I haven't been able to find it).

I would still need to extrude each object and model their roofs, and I haven't found any fast way to do that. I have just created a feature request on their repo, but despite it seems quite active I do not know if it will be accepted.

Scenario 2: Using Blender Geo Addon

Due to those problems I tried Blender Geo Addon which can import buildings in 3D, judging by this awesome video. It seems it has everything I need, except for these annoying issues (for me):

1. Only buildings that make use of osm's key building:height are extruded. Unfortunately this key is less used than building:levels which is more approximate but easier to get.
2. All roofs are flat, something which is not always true in most areas. OSM has some keys in order to store information regarding roofs, such as their type (roof:type) orientation (roof:orientation) and so on. (more details on that on this wiki)
3. There seem to be many overlapping meshes. (less cleaner than the other solution)

This is the result of the import:

The good news is that all this OSM information is stored as custom properties. The bad news is that I do not know how to work with them.

Regarding issue 1. I was wondering if there could be a way to extrude each object by its building:levels custom property without having to review and extrude them one by one.

Regarding issue 2: I do not have any idea on how to solve that. This is really a problem.

Regarding issue 3: I do not know if that's really a problem.

Final steps In case I could fix the import problem my idea is to use 3D print toolbox and export the model into stl file.

Can anyone provide any clues to overcome these problems?

• Could certainly edit the importer to extrude buildings using same code that is used for height. It's just establishing what is the level height? Will post some pix with different values. Sep 8 '16 at 12:50
• Sep 13 '16 at 16:28
• @vvoovv Tags are for the question, not a potential answer. Secondly, a tag should only be created if there are a significant number of questions that could benefit from the tag. I don't know if that is true of this tag yet (it might be). Mar 10 '20 at 21:17
• @RayMairlot, I thought the tag was applicable to the question, since the blender-osm addon was mentioned explicitly in the question. The addon was called blender-geo back in 2016. There are a number of questions about the blender-osm addon. I attempted to assign the tag blender-osm to them. Mar 12 '20 at 5:50

Update 25 January 2017

The OpenStreetMap importer for Blender has been completely rewritten. Here is the link: https://github.com/vvoovv/blender-osm

A large number of roof shapes is supported: flat, gabled, hipped (for a quadrangle outline only), mono-pitched, half-hipped, round, pyramidal, gambrel, dome, onion and saltbox.

Below are some results of its work.

• New York. The original OSM file contained more than 100.000 buildings and had the size 350 Mb.

• Moscow Kremlin. The example showcases the support of flat, gabled, mono-pitched, dome, onion and pyramidal roof shapes.

• Cool. re roofs have a look at gitlab.com/fg-radi/osm2city/blob/master/roofs.py Sep 18 '16 at 14:03
• Thank you for the link! I've already written some code to deal with hipped roofs through straight skeleton algorithm in another repo. There is a ticket to discuss roof support Sep 20 '16 at 3:37
• A large number of roof shapes is supported: flat, gabled, hipped (for a quadrangle outline only), mono-pitched, half-hipped, round, pyramidal, gambrel, dome, onion and saltbox. Jan 25 '17 at 3:16

Here are some updates to the script https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py

Extruded buildings based on building:levels using a level_height setting in import. Also added a scale setting.

Result So far.

Haven't done much with roofs yet.

Till I add it into code proper this adds some materials / object color to buildings

import bpy
from bpy import context

# CoDEmanX from BA.org
def hex_to_rgb(color_str):
# supports '123456', '#123456' and '0x123456'
(r,g,b), a = map(lambda component: component / 255, bytes.fromhex(color_str[-6:])), 1.0
return (r,g,b,a)

scene = context.scene
# buildings with material

bm = [b for b in scene.objects if "building:colour" in b.keys()]
materials = {}
for b in bm:
matname = b.get("building:material")
if matname is None:
matname = "building:material"
mat = bpy.data.materials.get(matname)
if mat is None:
mat = bpy.data.materials.new(matname)
mat.use_object_color = True
if matname not in b.data.materials:
b.data.materials.append(mat)
if b.get("building:colour"):
b.color = hex_to_rgb(b.get("building:colour"))


Might also pay to have a look at osm2x3d to convert to x3d and import from that format. (Haven't tried)

• Wow! thank you! haven't been able to test it yet, since I'm away from my computer. Willing to do so! (once I've done that I will mark your answer). Thanks again. Sep 10 '16 at 14:12