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. Those a prism cannot express, such as an arch or
separate legs, carry a closed triangle mesh in :attr:Building.solid, which
:func:building_mesh places on the terrain as it is.
Building(footprint, height_m, is_part=False, profile=(), roof_height_m=0.0, osm_id='', wikidata='', solid=None)
dataclass
¶
A building or building part: footprint, height and roof shape.
A landmark can replace the prism with a custom solid.
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
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 | |
bbox_area_km2(bbox)
¶
Ground area of bbox in square kilometers.
Source code in satprint/buildings.py
873 874 875 876 | |
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, min_alone_mm2=MIN_ALONE_MM2, simplify_mm=0.05, min_roof_mm=0.3, min_feature_mm=0.6, 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
|
min_alone_mm2
|
float
|
a building smaller than this that touches no other is dropped, too small for a nozzle to draw. |
MIN_ALONE_MM2
|
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
|
min_feature_mm
|
float
|
thinnest part of a building that carries a
:attr: |
0.6
|
progress
|
Progress | None
|
called as |
None
|
Returns:
| Type | Description |
|---|---|
BuildingMesh
|
all buildings as one :class: |
Source code in satprint/buildings.py
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 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | |
buildings_from_osm(data)
¶
Parse an Overpass out body geom response into buildings.
Source code in satprint/buildings.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 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 | |
buildings_from_vector_tiles(tiles)
¶
Parse the building layer of OpenMapTiles vector tiles.
Source code in satprint/buildings.py
327 328 329 330 331 332 333 334 335 336 337 338 | |
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
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
parse_height(tags)
¶
Building height in meters from OSM tags.
Source code in satprint/buildings.py
123 124 125 126 127 128 129 130 131 | |
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
160 161 162 163 164 165 166 167 168 169 170 171 | |
radius_m(footprint)
¶
Radius of the circle with the footprint's area, for a lon/lat polygon.
Source code in satprint/buildings.py
134 135 136 137 138 | |
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
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 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
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
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
vector_tile_features(tiles, layer, lines=False)
¶
vector_tile_features(tiles: list[tuple[int, int, int, bytes]], layer: str, lines: Literal[False] = ...) -> list[tuple[Polygon, dict]]
vector_tile_features(tiles: list[tuple[int, int, int, bytes]], layer: str, lines: Literal[True]) -> list[tuple[LineString, dict]]
Polygons of one layer of OpenMapTiles vector tiles, in lon/lat, or
its lines with lines=True.
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
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 | |