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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session | None
|
HTTP session to use. |
None
|
url
|
str
|
Nominatim search endpoint. |
NOMINATIM_URL
|
timeout
|
float
|
seconds per request. |
20.0
|
cache_size
|
int
|
most queries whose results are kept in memory. |
256
|
Source code in satprint/osm.py
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
search(q, limit=8)
¶
Matching places, best first, each with a bbox of [S, W, N, E].
Source code in satprint/osm.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
str | None
|
cache directory; default |
None
|
session
|
Session | None
|
HTTP session to use. |
None
|
urls
|
tuple[str, ...]
|
Overpass servers, tried in order. |
OVERPASS_URLS
|
timeout
|
float
|
seconds per request. |
45.0
|
Source code in satprint/osm.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
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
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 254 255 256 257 258 259 260 | |
query(query, cache_key=None)
¶
Run query, trying the last server that answered first.
Source code in satprint/osm.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
shaped(bbox)
¶
Buildings in bbox with a shaped roof or a landmark entry.
Source code in satprint/osm.py
210 211 212 | |
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
str | None
|
cache directory; default |
None
|
session
|
Session | None
|
HTTP session to use. |
None
|
tilejson_url
|
str
|
TileJSON that names the current tile build. |
OPENFREEMAP_TILEJSON
|
timeout
|
float
|
seconds per request. |
30.0
|
Source code in satprint/osm.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
fetch(z, x, y)
¶
The raw .pbf tile at z/x/y, from the cache or the server.
Source code in satprint/osm.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |
template()
¶
Tile URL template of the current build, re-read once a day.
Source code in satprint/osm.py
293 294 295 296 297 298 299 300 301 | |
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
319 320 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 346 347 348 349 | |
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
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 | |
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 | |