Map services¶
satprint.osm
¶
OpenStreetMap web services: OpenFreeMap vector tiles and Overpass (building data), and Nominatim (search).
Both are free public services with usage policies: identify the client with a User-Agent, cache what you fetch, and keep Nominatim to one request per second. See https://operations.osmfoundation.org/policies/nominatim/ and https://wiki.openstreetmap.org/wiki/Overpass_API#Public_Overpass_API_instances.
Geocoder(session=None, url=NOMINATIM_URL, timeout=20.0, cache_size=256)
¶
Place search through Nominatim, at most one request per second.
Source code in satprint/osm.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
search(q, limit=8)
¶
Matching places, best first, each with a bbox of [S, W, N, E].
Source code in satprint/osm.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 | |
OverpassClient(cache_dir=None, session=None, urls=OVERPASS_URLS, timeout=45.0)
¶
Run Overpass queries with mirror fallback and a gzipped disk cache.
Building downloads are split into fixed-grid tiles, each cached on its own, so a failed run keeps the tiles it finished and a retry or an overlapping area fetches only what is missing.
Source code in satprint/osm.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
buildings(bbox, progress=None)
¶
Building elements in bbox, fetched tile by tile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
BBox
|
area to cover. |
required |
progress
|
Progress | None
|
called as |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
an Overpass response with the tiles' elements, deduplicated. |
Source code in satprint/osm.py
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 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
query(query, cache_key=None)
¶
Run query, trying the last server that answered first.
Source code in satprint/osm.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
shaped(bbox)
¶
Buildings in bbox with a shaped roof or a landmark entry.
Source code in satprint/osm.py
203 204 205 | |
VectorTileClient(cache_dir=None, session=None, tilejson_url=OPENFREEMAP_TILEJSON, timeout=30.0)
¶
Fetch and disk-cache OpenFreeMap vector tiles covering an area.
Tiles are cached by z/x/y without the build date, like the elevation and imagery tiles, so cached buildings stay until the cache is cleared.
Source code in satprint/osm.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
template()
¶
Tile URL template of the current build, re-read once a day.
Source code in satprint/osm.py
281 282 283 284 285 286 287 288 289 | |
tiles(bbox, progress=None, zoom=VECTOR_ZOOM, stage='buildings')
¶
(z, x, y, tile bytes) for every tile covering bbox.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bbox
|
BBox
|
area to cover. |
required |
progress
|
Progress | None
|
called as |
None
|
zoom
|
int
|
tile zoom. |
VECTOR_ZOOM
|
stage
|
str
|
stage name to report. |
'buildings'
|
Returns:
| Type | Description |
|---|---|
list[tuple[int, int, int, bytes]]
|
the tiles, in row order. |
Source code in satprint/osm.py
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 | |
buildings_query(bbox, timeout_s=40)
¶
Overpass QL for building outlines and building parts in bbox.
Source code in satprint/osm.py
59 60 61 62 63 64 65 66 67 68 69 | |
fetch_buildings(source, bbox, osm, vtiles, progress=None)
¶
Buildings in bbox from one source, with roof shapes and landmarks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
"openfreemap", "overpass" or "overture". |
required |
bbox
|
BBox
|
area to cover. |
required |
osm
|
OverpassClient
|
Overpass client; also supplies roof shapes for OpenFreeMap. |
required |
vtiles
|
VectorTileClient
|
OpenFreeMap vector tile client. |
required |
progress
|
Progress | None
|
passed to the download. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[list[Building], str | None]
|
(buildings, warning); the warning says when the roof shapes could not be fetched and the roofs are flat. |
Source code in satprint/osm.py
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 | |
grid_tiles(bbox, deg=TILE_DEG)
¶
Fixed-grid tiles covering bbox as (row, col, tile bbox).
The grid is global, so overlapping areas share tiles and their cache.
Source code in satprint/osm.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
shapes_query(bbox, timeout_s=40)
¶
Overpass QL for buildings with a shaped roof or a landmark entry.
The vector tiles carry no roof tags, so this small query supplies them.
Source code in satprint/osm.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |