Floorplan YAML Construction
YAML serialisation of indoor building geometry.
This module provides utilities for converting labelled room polygons into a structured, human-readable YAML representation of a building floorplan. It operates on GeoDataFrame-derived polygon geometries and produces a schema focused on architectural topology rather than geospatial metadata.
Responsibilities of this module include: - Converting polygon exteriors into ordered wall segments. - Mapping labelled polygons and canonical door segments to room definitions. - Assembling building- and floor-level metadata into a serialisable form. - Writing the resulting structure to disk as YAML.
The module assumes: - One polygon corresponds to one room. - Polygon geometries are valid, closed, and planar. - Coordinates exist in a local Cartesian space with no CRS. - Room labels have already been attached upstream.
DXF parsing, spatial joins, and geometry construction are explicitly out of scope and must be handled before using this module.
FlowList
Bases: list
List subtype used to force YAML flow-style serialisation.
Source code in src/floorplan_extractor/yaml_construction.py
42 43 | |
apply_door_cardinality_policy(rooms, *, singleton_policy='error')
Validate door attachments and handle doors connected to only one room.
The runtime requires each model door to connect exactly two rooms. A singleton segment can instead be restored to the physical wall geometry when the model intentionally treats the outside as impassable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rooms
|
list[dict]
|
Room definitions containing |
required |
singleton_policy
|
(error, wall)
|
Whether a door attached to one room raises an error or is restored as a physical wall segment. |
"error"
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
Copied room definitions with the selected policy applied. |
Raises:
| Type | Description |
|---|---|
InvalidDefinitionError
|
If |
InvalidDoorError
|
If a door does not connect exactly two rooms and the selected policy cannot resolve it. |
Source code in src/floorplan_extractor/yaml_construction.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
build_yaml_structure(*, building_name, building_address, floor_level, rooms, spatial_units)
Construct a YAML-ready building data structure from room definitions.
This function assembles building metadata and a collection of room
definitions into a nested dictionary matching the expected output
schema. The resulting structure is suitable for serialisation using
yaml.safe_dump without further transformation.
The function does not perform validation of room geometry or schema completeness. It assumes that each room dictionary contains, at a minimum, the keys: - "name" - "walls" - "doors"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
building_name
|
str
|
Name of the building. |
required |
building_address
|
str
|
Address of the building. |
required |
floor_level
|
int
|
Floor identifier to associate with the provided rooms. |
required |
rooms
|
list[dict]
|
List of room definitions produced by |
required |
spatial_units
|
SpatialUnits
|
Explicit conversion from source coordinates to canonical metres. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Nested dictionary structured as: { "schema_version": 1, "coordinate_unit": "m", "coordinate_provenance": { "source_unit": str, "units_per_metre": float, }, "building": { "name": str, "address": str, "floors": [ { "level": int, "rooms": list[dict], } ], } } |
Source code in src/floorplan_extractor/yaml_construction.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
polygons_to_rooms(gdf, room_name_column, door_column=None, opening_column=None, opening_tolerance=1e-06)
Convert labelled polygons into room definitions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
GeoDataFrame containing polygon geometries. |
required |
room_name_column
|
str
|
Column containing room names. |
required |
door_column
|
str or None
|
Optional column containing lists of canonical door segments represented
as |
None
|
opening_column
|
str or None
|
Optional column containing lists of non-operable opening segments. When
provided, those segments are emitted as |
None
|
opening_tolerance
|
float
|
Maximum boundary distance accepted when removing an opening from the physical wall list. |
1e-6
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
Room definitions containing |
Source code in src/floorplan_extractor/yaml_construction.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 | |
register_yaml_representers()
Register custom YAML representers used by the building serialisation module.
This function registers a representer for the FlowList type with
PyYAML's SafeDumper, ensuring that wall segment coordinate lists are
emitted in flow style (e.g. [x1, y1, x2, y2]) when using
yaml.safe_dump.
The registration mutates PyYAML's global dumper state and therefore must be called exactly once, before any YAML serialisation occurs. It is intentionally explicit to avoid hidden import-time side effects.
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/floorplan_extractor/yaml_construction.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |