Buildings¶
satprint.buildings
¶
OpenStreetMap buildings -> closed solids standing on the terrain.
Each building is a prism: a flat roof at its height above the highest terrain under it, walls, and a floor sunk slightly below the lowest terrain under it so it fuses with the base when sliced. Every prism is closed and outward-wound on its own, so the merged STL stays edge-manifold.
Two sources, both OpenStreetMap data:
- OpenFreeMap vector tiles (:func:
buildings_from_vector_tiles): heights are the tiles'render_height, already worked out from the OSM tags, and an outline whose parts are mapped is flaggedhide_3d. - Overpass (:func:
buildings_from_osm): raw OSM. Heights come from theheighttag, thenbuilding:levels, then a default.
Either way, where a building has building:part shapes the parts are used
and the outline is dropped, as the OSM Simple 3D Buildings scheme specifies.
A part's minimum height is ignored: parts are extruded from the ground so
nothing floats in a print.
Roofs tagged roof:shape dome, onion, cone or pyramidal get that shape
(:data:ROOF_PROFILES); every other roof is flat. The vector tiles carry no
roof tags, so :func:apply_shapes merges in the shaped buildings from a small
Overpass query. A few landmarks are replaced by exact shapes from
:mod:satprint.landmarks.
apply_shapes(buildings, shaped)
¶
Swap in shaped buildings for the plain copies of them in buildings.
A plain building is a copy of a shaped one when it contains the shaped
footprint's representative point, is within a factor of two of its area
and has its height, within the tiles' rounding to whole meters. Other
overlaps, such as the drum under a dome, are left to
:func:building_mesh.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buildings
|
list[Building]
|
buildings from a source without roof tags. |
required |
shaped
|
list[Building]
|
buildings with roof profiles, from Overpass. |
required |
Returns:
| Type | Description |
|---|---|
list[Building]
|
|
Source code in satprint/buildings.py
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 | |
building_mesh(buildings, bbox, relief_mm, width_mm, depth_mm, base_mm, mm_per_m, scale=1.0, sink_mm=0.3, min_height_mm=0.2, min_area_mm2=0.05, simplify_mm=0.05, min_roof_mm=0.3, progress=None)
¶
Place buildings on the terrain block built from relief_mm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
buildings
|
list[Building]
|
footprints in lon/lat with heights. |
required |
bbox
|
BBox
|
area the terrain block covers. |
required |
relief_mm
|
ndarray
|
the relief passed to :func: |
required |
width_mm
|
float
|
block width. |
required |
depth_mm
|
float
|
block depth. |
required |
base_mm
|
float
|
base thickness under the lowest terrain. |
required |
mm_per_m
|
float
|
horizontal model scale; building heights use it too,
so |
required |
scale
|
float
|
building height multiplier. |
1.0
|
sink_mm
|
float
|
how far floors go below the terrain. |
0.3
|
min_height_mm
|
float
|
lowest building height, so small ones still print. |
0.2
|
min_area_mm2
|
float
|
footprints smaller than this are dropped. |
0.05
|
simplify_mm
|
float
|
footprint simplification tolerance. |
0.05
|
min_roof_mm
|
float
|
shaped roofs lower than this are printed flat, at the building's full height. |
0.3
|
progress
|
Progress | None
|
called as |
None
|
Returns:
| Type | Description |
|---|---|
BuildingMesh
|
all buildings as one :class: |
Source code in satprint/buildings.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 | |
buildings_from_osm(data)
¶
Parse an Overpass out body geom response into buildings.
Source code in satprint/buildings.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 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 | |
buildings_from_vector_tiles(tiles)
¶
Parse the building layer of OpenMapTiles vector tiles.
Source code in satprint/buildings.py
277 278 279 280 281 282 283 284 285 286 287 288 | |
model_projection(bbox, width_mm, depth_mm)
¶
lon/lat (n, 2) -> model mm (n, 2) for a block covering bbox.
Linear in Web Mercator, as the heightmap and texture are, with X east and Y north.
Source code in satprint/buildings.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
parse_height(tags)
¶
Building height in meters from OSM tags.
Source code in satprint/buildings.py
107 108 109 110 111 112 113 114 115 | |
parse_roof(tags, height_m, footprint)
¶
(profile, roof height) from OSM roof:shape, roof:height and
roof:levels tags.
Source code in satprint/buildings.py
144 145 146 147 148 149 150 151 152 153 154 155 | |
radius_m(footprint)
¶
Radius of the circle with the footprint's area, for a lon/lat polygon.
Source code in satprint/buildings.py
118 119 120 121 122 | |
resolve_overlaps(footprints, tolerance=1e-06)
¶
Replace overlapping footprints with non-overlapping pieces.
OSM footprints overlap: a tower's parts stack over its base, and neighboring outlines cross by a few centimeters. Extruded as they are, those prisms pass through each other, which slicers report as invalid geometry. Within each group of overlapping footprints, every piece of the overlay takes the tallest height covering it, and pieces of equal height are merged, so the solids only touch along shared walls. Footprints that overlap nothing pass through unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
footprints
|
list[tuple[Polygon, float]]
|
(polygon, height) pairs, in any planar units. |
required |
tolerance
|
float
|
overlap area below which two footprints count as only touching. |
1e-06
|
Returns:
| Type | Description |
|---|---|
list[tuple[Polygon, float]]
|
(polygon, height) pairs with no overlapping interiors. |
Source code in satprint/buildings.py
729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 | |
roof_shape(shape, roof_height_m, height_m, footprint)
¶
(profile, roof height) for a roof:shape value; flat if unsupported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
str | None
|
the |
required |
roof_height_m
|
float | None
|
the tagged roof height, or None to use the footprint's radius, a hemisphere for a dome. |
required |
height_m
|
float
|
total height; the roof never exceeds it. |
required |
footprint
|
Polygon
|
lon/lat footprint. |
required |
Source code in satprint/buildings.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
vector_tile_features(tiles, layer)
¶
Polygons of one layer of OpenMapTiles vector tiles, in lon/lat.
Each feature is clipped to its own tile, without the tile buffer, so a shape crossing a tile edge comes back as two pieces that meet at the edge instead of two overlapping copies.
Source code in satprint/buildings.py
239 240 241 242 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 | |