BingAerialImageExtractor#

class rapidtools.data_sources.BingAerialImageExtractor(save_directory: str | Path = 'output', zoom_level: int = 20, max_workers: int = 10, **kwargs: Any)[source]#

Bases: WebMercatorTileExtractor

Client for extracting high-resolution imagery from Bing Maps tiles.

Use it as a context manager; tiles are downloaded through a pooled, retrying session. Supports stitching polygons into images and yielding individual tiles for machine-learning pipelines.

Example

>>> from rapidtools.data_sources import BingAerialImageExtractor
>>> BingAerialImageExtractor.tile_to_quadkey(3, 5, zoom=3)
'213'
>>> with BingAerialImageExtractor('out', zoom_level=18) as extractor:
...     print(extractor.process_polygon(feature, index=0))
Success: test_building

Methods

buffered_bounds

Expand a polygon's bounds by a percentage of its width and height.

generate_polygon_tiles

Yield individual tiles intersecting a GeoJSON polygon feature.

generate_region_tiles

Yield individual tiles covering a bounding box.

lat_lon_to_pixel

Convert latitude and longitude to global Web Mercator pixel coordinates.

pad_to_square

Center an image on a black square canvas whose side is its longer edge.

pixel_to_lat_lon

Convert global Web Mercator pixel coordinates back to latitude/longitude.

process_geojson

Read a GeoJSON file and save one image per polygon feature.

process_polygon

Download, stitch, crop and save imagery for one GeoJSON polygon feature.

stitch_region

Download every tile covering a bounding box and crop the mosaic to it.

tile_bounds

Return the geographic bounds of an XYZ tile.

tile_to_quadkey

Convert tile XY coordinates into a Bing Maps quadkey string.

static tile_to_quadkey(tile_x: int, tile_y: int, zoom: int) → str[source]#

Convert tile XY coordinates into a Bing Maps quadkey string.

Parameters:
  • tile_x – Tile column index.

  • tile_y – Tile row index.

  • zoom – Zoom level (equals the length of the returned quadkey).

Returns:

str – The quadkey used to fetch the tile from Bing’s servers.

Example

>>> BingAerialImageExtractor.tile_to_quadkey(3, 5, zoom=3)
'213'