OpenStreetMap

In the recent days I’ve experimented with rendering floor plans using indoor data from OSM. The Simple Indoor Tagging schema suggests pretty lean additive tagging rules to specify the floor level of features and extends to drawing room/area shapes. Well done guys! It’s a very nice and flexible suggestion to add indoor data to OSM.

Turns out coverage of indoor data in OSM is quite limited:

  • Only a few places mapped, mostly university buildings, subway stations and a few shopping centres.
  • Walls are rarely drawn and room polygons touch each other.
  • Doorways are not omitted when drawing walls, in other words there is no hole where doors are located.

This is expected given the difficulty to source indoor data paired with the limited editor support. And frankly, I don’t see much use in mapping indoor data (as part of OSM) except for POI floor levels.

The Simple Indoor Tagging is right in suggesting to map walls only if not already defined by room shapes. Having wall shapes in OSM would dramatically increase the number of nodes and make it more difficult than it already is to edit indoor data. Note that the spatially overlapping room shapes in the different floors are already troublesome to edit unless one uses things like JOSM’s filters extensively.

Being aware of these constraints I came up with the following process to generate walls on the fly:

  1. Cluster rooms, areas, walls, doors, floor level shape by floor level and spatial intersection. Basically collect what is close to each other.
  2. Create wireframes for the walls by collecting the outlines of the room shapes and explicitly drawn walls. This results in approximate centrelines of the walls.
  3. Calculate where the wall wireframe is close to door nodes, buffer (blow up) this part of the wall wireframe to gain the doorway polygons.
  4. Union buffered room polygons and the floor level polygon if available.
  5. Subtract walkable areas, add explicitly drawn walls, subtract doorways.

The process is slow as the above involves a lot of not so simple calculations. Luckily, JTS comes to the rescue and does most of the work. It’s still taking a few seconds for most buildings and annoyingly many seconds for buildings mapped in detail. However since the whole thing is just an experiment, I deemed it good enough.

Rendering of the polygons, including the complex wall polygons, was quick enough in OpenLayers to build a simple interactive map. Raw OSM data can be retrieved using Overpass API once one learned how to use its unfamiliar query language. It’s capabilities are impressive as it allows any motivated developer to make pretty specific queries and access the whole, global OSM dataset.

The remaining bit to make a map that is somewhat pleasant to look at was labelling. Sadly, OpenLayers is limited in this aspect and I found myself fiddling with quirky HTML DOM APIs trying to get text flows and label variants to work. I guess the result works reasonably well given the time spent on it.

An interactive map to play with is available on https://typescript-6ixy5d.stackblitz.io/ but you have been warned that buildings mapped in detail may hang your browser for a while.

In case you find nicely looking buildings or buildings which don’t render correctly even though they are mapped according to the Simple Indoor Tagging schema, please leave a comment.

Example rendering

Discussion

Comment from Aury88 on 6 October 2022 at 17:52

that is simply wonderful! thx @Augustus Kling

Probably your server now is overloaded by multiple requests. I was not able to see any indoor mapping (in my indoor mapped buildings and in your examples presets) but only the normal carto-map.

I will try again later

Comment from Augustus Kling on 8 October 2022 at 18:21

@Aury88, many thanks for your comment.

I don’t operate an own server for this experiment but rely on Stackblitz and VK’s Overpass API instance. I’m not aware either of them had a downtime and didn’t face any issues with their services so far.

Please provide the coordinates or OSM link of indoor data you mapped if you want me to check. I couldn’t reproduce issues with the examples.

Comment from Aury88 on 12 October 2022 at 06:22

Hi ,@Augustus Kling, Yes, probably it was an issue with my browser or with one of its plugin. From my smartphone it works correctly. Thank you.

Comment from TrickyFoxy on 15 October 2022 at 21:34

Good job!

Will you post the source code of the project?


There was also a problem with the download:( In Firefox, it turned out to be necessary to disable Tracking Protection.

Comment from Augustus Kling on 15 October 2022 at 22:38

The code is available on https://github.com/AugustusKling/osm-floorplans

Note that the whole thing is an experiment and not a library that could be reused easily. I may or may not continue work on it.

Comment from hfs on 17 October 2022 at 09:49

Hey @Aury88,

for me Firefox blocked the Overpass requests to mail.ru. If you’re using Firefox as well, you could try to turn off tracking protection for the site – shield icon in the URL bar.

Log in to leave a comment