Terrain and elevation¶
satprint.terrain
¶
Elevation data sources and heightmap processing.
Sources¶
fetch_terrarium— satellite-derived global elevation (SRTM/ASTER/GMTED merged) from the AWS Open Data "Terrain Tiles" set, in Mapzen terrarium PNG encoding. No API key is required.fetch_imagery-- Esri World Imagery tiles for the same bbox, used as the texture on the GLB export.synthetic_heightmap— procedural mountains for offline use and tests.load_heightmap_file— user-supplied PNG / TIFF / GeoTIFF heightmaps.
BBox(south, west, north, east)
dataclass
¶
A latitude/longitude box in degrees, within +/-85 degrees latitude.
mid_lat
property
¶
Latitude halfway between south and north.
mid_lon
property
¶
Longitude halfway between west and east.
ground_size_m()
¶
(width, height) in meters along the bbox's central lines.
Source code in satprint/terrain.py
75 76 77 78 79 | |
Heightmap(data, ground_width_m, ground_height_m, source, bbox=None, meta=dict())
dataclass
¶
ImageryFetcher(cache_dir=None, session=None, url_template=IMAGERY_URL, timeout=30.0)
¶
Bases: TileFetcher
Fetch + disk-cache satellite imagery tiles as (256, 256, 3) uint8 RGB.
As :class:TileFetcher, caching in ~/.cache/satprint/imagery.
Source code in satprint/terrain.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
fetch(z, x, y)
¶
Tile z/x/y as RGB pixels.
Source code in satprint/terrain.py
310 311 312 313 | |
PrintParams(width_mm=100.0, base_mm=3.0, exaggeration=1.5, relief_mm=None, smoothing=0.0, clamp_sea_level=True, min_feature_mm=0.0)
dataclass
¶
Physical print settings, validated to the ranges the API accepts.
TileFetcher(cache_dir=None, session=None, url_template=TERRARIUM_URL, timeout=30.0)
¶
Fetch + disk-cache terrarium tiles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
str | None
|
cache directory; default |
None
|
session
|
Session | None
|
HTTP session to use. |
None
|
url_template
|
str
|
tile URL with |
TERRARIUM_URL
|
timeout
|
float
|
seconds per request. |
30.0
|
Source code in satprint/terrain.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
fetch(z, x, y)
¶
Tile z/x/y as elevations in meters.
Source code in satprint/terrain.py
284 285 286 | |
fetch_bytes(z, x, y)
¶
The encoded tile at z/x/y, from the cache or the server.
Raises:
| Type | Description |
|---|---|
LookupError
|
when the server has no such tile. |
Source code in satprint/terrain.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
choose_zoom(bbox, target_cols, max_zoom=MAX_ZOOM)
¶
Smallest zoom at which the bbox spans at least target_cols pixels.
Source code in satprint/terrain.py
132 133 134 135 136 137 138 139 | |
decode_terrarium(png_bytes)
¶
Decode a terrarium PNG into float32 meters.
Source code in satprint/terrain.py
213 214 215 216 217 | |
encode_terrarium(elev)
¶
Inverse of :func:decode_terrarium (used by tests and fixtures).
Source code in satprint/terrain.py
220 221 222 223 224 225 226 227 228 229 | |
fetch_imagery(bbox, max_px=2048, fetcher=None, workers=8, progress=None)
¶
Satellite image of bbox, cropped exactly like :func:fetch_terrarium.
The zoom is the smallest that reaches max_px columns, lowered until
the area fits in MAX_TILES. The image is downscaled so its longer
side is at most max_px. Row 0 is north, so grid node (r, c) of the
heightmap sits at texture coordinates (c / (cols-1), r / (rows-1)).
Source code in satprint/terrain.py
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 | |
fetch_terrarium(bbox, target_cols=256, fetcher=None, workers=8, progress=None)
¶
Download, mosaic and crop terrain tiles covering bbox.
The result is resampled so that its pixel aspect ratio matches the
ground aspect ratio (width/height in meters), with target_cols columns.
Source code in satprint/terrain.py
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 | |
gaussian_smooth(arr, sigma)
¶
Separable Gaussian blur with edge replication (no SciPy needed).
Source code in satprint/terrain.py
505 506 507 508 509 510 511 512 513 514 515 | |
haversine_m(lat1, lon1, lat2, lon2)
¶
Great-circle distance in meters between two points in degrees.
Source code in satprint/terrain.py
114 115 116 117 118 119 120 | |
heightmap_png(hm, clamp_sea_level=True)
¶
Hillshaded 8-bit preview PNG of the heightmap.
Source code in satprint/terrain.py
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | |
load_heightmap_file(data, filename='', ground_width_m=None, max_cols=1024)
¶
Load a heightmap image. GeoTIFFs use rasterio when available, otherwise the file is treated as a plain raster whose values are meters (16-bit PNGs are interpreted as meters as well, 8-bit as 0-255 relative units).
Source code in satprint/terrain.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
lonlat_to_global_px(lon, lat, zoom)
¶
Web-Mercator pixel coordinates (x right, y down) at zoom.
Source code in satprint/terrain.py
123 124 125 126 127 128 129 | |
prepare_relief(hm, p)
¶
Convert elevation (m) to relief heights (mm above the base) and report the scale actually used.
Source code in satprint/terrain.py
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 | |
resample(arr, rows, cols)
¶
Resize a float grid to rows x cols: box filter down, bicubic up.
Source code in satprint/terrain.py
494 495 496 497 498 499 500 501 502 | |
synthetic_heightmap(rows=200, cols=256, seed=0, ground_width_m=20000.0)
¶
Procedural alpine-looking terrain with ridges, valleys and a lake.
Source code in satprint/terrain.py
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 413 414 415 | |