DXF Floorplan Extraction
DXF floorplan polygon extraction and labelling.
This module provides utilities for extracting closed polygon geometries from DXF floorplan linework and attaching textual room labels to those polygons using spatial point-in-polygon relationships.
The intended use case is indoor floorplans where all geometries exist in a single, local Cartesian coordinate space. No coordinate reference system (CRS) is assumed or required. All spatial operations are therefore purely topological.
Typical workflow: 1. Read a DXF file into a GeoDataFrame. 2. Polygonise linework from a specified DXF layer. 3. Extract room label point geometries from another layer. 4. Filter labels by floor using a string prefix. 5. Apply configured polygon corrections. 6. Spatially join labels to polygons and aggregate them deterministically. 7. Normalise accepted shared walls to common midlines. 8. Construct configured open-boundary spans from the final room boundaries. 9. Project door symbols onto the final room boundaries.
The module makes the following assumptions: - DXF layer names are stable and known in advance. - A column named "Layer" is present in the input GeoDataFrame. - Room labels are stored as point geometries. - Multiple labels may fall within a single polygon and will be concatenated in sorted order.
The public entry point is extract_polygons. All other functions are
internal helpers and are not part of the public API.
DoorAttachmentConfig
dataclass
Configuration for extracting and attaching canonical door segments.
Attributes:
| Name | Type | Description |
|---|---|---|
entity_col |
str
|
Column linking the CAD geometries that represent the same door. |
x_col |
str
|
Column containing centroid x coordinates retained for compatibility. |
y_col |
str
|
Column containing centroid y coordinates retained for compatibility. |
out_col |
str
|
Name of the output column added to the room polygons. |
predicate |
str
|
Spatial predicate retained for configuration compatibility. |
boundary_tolerance |
float
|
Maximum distance from a room-boundary segment used when projecting source door geometry. |
min_door_length |
float
|
Minimum projected door length to retain. |
max_attached_rooms |
int
|
Maximum expected number of rooms connected by one door. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
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 | |
ExtractionConfig
dataclass
Top-level configuration for DXF extraction.
Attributes:
| Name | Type | Description |
|---|---|---|
polygons |
PolygonExtractionConfig
|
Configuration controlling polygon generation and label attachment. |
spatial_units |
SpatialUnits
|
Explicit conversion from source coordinates to canonical metres. |
door_layer_name |
str
|
Name of the DXF layer containing door geometries. |
doors |
DoorAttachmentConfig or None
|
If provided, doors are extracted and attached to polygons. |
shared_walls |
SharedWallConfig or None
|
If provided and enabled, shared-wall normalisation may be applied by downstream processing. |
open_boundaries |
OpenBoundaryConfig or None
|
Explicit wallless room pairs to construct from final room boundaries. |
polygon_splits |
list[PolygonSplitConfig]
|
Floorplan-specific polygon splits applied before label attachment. |
polygon_additions |
list[PolygonAdditionConfig]
|
Floorplan-specific polygons added before label attachment. |
polygon_merges |
list[PolygonMergeConfig]
|
Floorplan-specific labelled polygons merged before geometry normalisation. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
OpenBoundaryConfig
dataclass
Configuration for constructing explicit wallless room boundaries.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
174 175 176 177 178 179 180 | |
OpenBoundaryPairConfig
dataclass
Configuration identifying one wallless boundary between two rooms.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
165 166 167 168 169 170 171 | |
OpenBoundarySpan
dataclass
Canonical shared boundary span for one configured room pair.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
183 184 185 186 187 188 | |
PolygonAdditionConfig
dataclass
Explicit polygon missing from source room-area linework.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
149 150 151 152 153 154 | |
PolygonExtractionConfig
dataclass
Configuration for DXF polygon extraction and labelling.
Attributes:
| Name | Type | Description |
|---|---|---|
polygon_layer_name |
str
|
Name of the DXF layer containing polygon boundary linework. |
label_layer_name |
str
|
Name of the DXF layer containing room label point geometries. |
polygon_label_column |
str
|
Name of the column containing room label text. |
polygon_label_target |
str
|
Name of the output column to store aggregated polygon labels. |
floor_filter |
str
|
Prefix used to select labels belonging to a specific floor. |
excluded_room_numbers |
list[str]
|
List of room numbers to exclude from labelling. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
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 | |
PolygonMergeConfig
dataclass
Configuration for merging labelled polygons into one target polygon.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
157 158 159 160 161 162 | |
PolygonSplitConfig
dataclass
Configuration for splitting one polygon at known floorplan boundaries.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
140 141 142 143 144 145 146 | |
PolygonSplitRegionConfig
dataclass
Explicit label for one region produced by a configured polygon split.
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
132 133 134 135 136 137 | |
attach_open_boundary_doors(labelled_polygons, spans, polygon_label_target, door_column='doors')
Add configured open-boundary spans to the existing room door column.
Exact CAD-derived matches are deduplicated. A partial or enclosing overlap with a CAD-derived segment is rejected because it would create ambiguous connectivity on the same room interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labelled_polygons
|
GeoDataFrame
|
Final labelled room polygons, optionally containing attached doors. |
required |
spans
|
list[OpenBoundarySpan]
|
Canonical spans constructed from the final room boundaries. |
required |
polygon_label_target
|
str
|
Column containing the unique room labels. |
required |
door_column
|
str
|
Column containing serialised |
"doors"
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Copy of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a span cannot be serialised or partially overlaps an existing door segment. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
attach_room_doors(labelled_polygons, doors, config=None)
Project CAD door geometry onto room boundaries and attach the segments.
Source geometries belonging to the same door are combined using
config.entity_col. Candidate spans are projected onto straight
exterior segments of the final room polygons. The preferred projection is
the segment shared by the greatest number of rooms, with projected length
used as a secondary ranking criterion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labelled_polygons
|
GeoDataFrame
|
GeoDataFrame containing room polygon geometries. The index is used as the room identifier. |
required |
doors
|
GeoDataFrame
|
GeoDataFrame containing one or more CAD geometries per physical door. |
required |
config
|
DoorAttachmentConfig
|
Configuration controlling the join predicate, column names, and output column name. |
DoorAttachmentConfig()
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Copy of |
Raises:
| Type | Description |
|---|---|
KeyError
|
If required columns are missing from either input GeoDataFrame. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 | |
config_from_yaml(path)
Load extraction configuration from a YAML file.
Expected YAML structure
polygons: polygon_layer_name: ... label_layer_name: ... polygon_label_column: ... polygon_label_target: ... floor_filter: ... excluded_room_numbers: [...]
spatial_units: source_unit: millimetres units_per_metre: 1000.0
doors: # optional layer_name: DOORS entity_col: EntityHandle x_col: x y_col: y out_col: doors predicate: intersects
shared_walls: # optional enabled: true min_gap: 50 max_gap: 130 angle_tolerance_degrees: 2 min_overlap_ratio: 0.75 min_overlap_length: 250 canonical_line: midline
open_boundaries: # optional tolerance: 1.0e-6 min_length: 0.0 pairs: - rooms: [ROOM_A, ROOM_B] selector_point: [x, y] # optional
polygon_splits: # optional - selector_point: [x, y] cut_lines: - [x1, y1, x2, y2] regions: - label: ROOM_CODE seed_point: [x, y]
polygon_additions: # optional - label: CORRIDOR coordinates: - [x, y]
polygon_merges: # optional - target_label: ROOM_CODE source_labels: [CORRIDOR]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the YAML configuration file. |
required |
Returns:
| Type | Description |
|---|---|
ExtractionConfig
|
Parsed and validated configuration object. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the YAML structure is invalid. |
KeyError
|
If required keys are missing. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 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 331 332 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 | |
construct_open_boundaries(labelled_polygons, config, polygon_label_target)
Construct canonical spans for explicitly configured wallless boundaries.
The input polygons must be the final corrected and shared-wall-normalised
geometries. Each configured pair is snapped within config.tolerance
before boundary intersection. Each pair accepts one non-zero, straight span
unless explicitly configured to retain multiple straight spans.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labelled_polygons
|
GeoDataFrame
|
Final labelled room polygons. |
required |
config
|
OpenBoundaryConfig
|
Explicit room pairs and geometric acceptance thresholds. |
required |
polygon_label_target
|
str
|
Column containing the unique room labels. |
required |
Returns:
| Type | Description |
|---|---|
list[OpenBoundarySpan]
|
Canonical spans in the same deterministic order as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a configured pair has no unique valid shared span, participates in a third room, or fails the configured geometry checks. |
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 | |
extract_polygons(input_dxf_path, config)
Extract labelled polygons from a DXF floorplan.
The DXF file is read into a GeoDataFrame, polygon geometries are generated from linework, and room labels are filtered and attached. Configured polygon corrections are applied before optional shared-wall normalisation and canonical door projection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dxf_path
|
Path
|
Path to the input DXF file. |
required |
config
|
ExtractionConfig
|
Configuration object controlling layer names, label filtering, and output column names. |
required |
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Labelled room polygons with extraction metadata. The columns include
|
Source code in src/floorplan_extractor/dxf_polygon_extraction.py
2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 | |