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
¶
ground_size_m()
¶
(width, height) in meters along the bbox's central lines.
Source code in satprint/terrain.py
71 72 73 74 75 | |
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.
Source code in satprint/terrain.py
272 273 274 275 276 277 278 279 280 281 282 283 284 285 | |
TileFetcher(cache_dir=None, session=None, url_template=TERRARIUM_URL, timeout=30.0)
¶
Fetch + disk-cache terrarium tiles.
Source code in satprint/terrain.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
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
122 123 124 125 126 127 128 129 | |
decode_terrarium(png_bytes)
¶
Decode a terrarium PNG into float32 meters.
Source code in satprint/terrain.py
202 203 204 205 206 | |
encode_terrarium(elev)
¶
Inverse of :func:decode_terrarium (used by tests and fixtures).
Source code in satprint/terrain.py
209 210 211 212 213 214 215 216 217 218 | |
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
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 | |
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
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 | |
gaussian_smooth(arr, sigma)
¶
Separable Gaussian blur with edge replication (no SciPy needed).
Source code in satprint/terrain.py
480 481 482 483 484 485 486 487 488 489 490 | |
heightmap_png(hm, clamp_sea_level=True)
¶
Hillshaded 8-bit preview PNG of the heightmap.
Source code in satprint/terrain.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 | |
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
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 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 | |
lonlat_to_global_px(lon, lat, zoom)
¶
Web-Mercator pixel coordinates (x right, y down) at zoom.
Source code in satprint/terrain.py
113 114 115 116 117 118 119 | |
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
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 | |
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
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 | |