brails.utils.rapid_utils module

This is a utility class for datasets created by the RAPID facility at UW.

RAPIDUtils(dataset_path)

Utility class for datasets created by the RAPID facility at UW.

class brails.utils.rapid_utils.RAPIDUtils(dataset_path)

Bases: object

Utility class for datasets created by the RAPID facility at UW.

This class provides methods to extract asset-specific imagery from datasets collected by the RAPID facility at UW.

Please use the following statement to import the RAPIDUtils class.

from brails.utils import RAPIDUtils
extract_aerial_imagery(asset_inventory, save_directory, max_missing_data_ratio=0.2, overlay_asset_outline=False)

Extract aerial imagery patches for each asset from a raster dataset.

Parameters:
  • asset_inventory (AssetInventory) – Inventory object containing asset geometries and metadata.

  • save_directory (str) – Directory where extracted images will be saved.

  • max_missing_data_ratio (float, optional) – Maximum allowed proportion of missing data (0-1). Default is 0.2.

  • overlay_asset_outline (bool, optional) – If True, overlay the asset polygon on the saved image. Default is False.

Returns:

Object containing metadata and paths of saved images.

Return type:

ImageSet

Example

The following example assumes that a valid orthomosaic raster file exists at raster_test_data.tif. Actual outputs may vary depending on the specific contents of the raster file.

Step 1: Import required packages and load the raster dataset. Note that RAPIDUtils automatically identifies the methods applicable for the loaded dataset:

>>> from brails.utils import RAPIDUtils, Importer
>>> rapid_utils = RAPIDUtils('raster_test_data.tif')
Detected orthomosaic data.
Applicable methods for this data type are:
'extract_aerial_imagery', 'get_mosaic_bbox_wgs84'.

Step 2: Retrieve building footprints covering the extent of the dataset:

>>> importer = Importer()
>>> region_data = {
...     "type": "locationPolygon",
...     "data": rapid_utils.dataset_extent
... }
>>> region_boundary_object = importer.get_class(
...     'RegionBoundary'
... )(region_data)
>>> osm_footprint_scraper = importer.get_class(
...     'OSM_FootprintScraper'
... )({'length': 'ft'})
>>> scraper_inventory = osm_footprint_scraper.get_footprints(
...     region_boundary_object
... )
Found a total of 503 building footprints in the bounding box:
(-122.1421632630, 47.69423131358, -122.12908634292, 47.70804716657)

Step 3: Extract building-level imagery from the orthomosaic dataset. Optionally overlay the building footprints to aid computer vision applications:

>>> image_set = rapid_utils.extract_aerial_imagery(
...     scraper_inventory,
...     'images_raster_test/overlaid_imagery',
...     overlay_asset_outline=True
... )
Images will be saved to: /home/bacetiner/Documents/SoftwareTesting/
images_raster_test/overlaid_imagery
Extracting aerial imagery...: 100%|██████████| 503/503
[01:04<00:00,  7.79it/s]
Extracted aerial imagery for a total of 397 assets.
get_mosaic_bbox_wgs84()

Get the bounding box of the raster dataset in WGS84 coordinates.

This method opens the raster dataset, reads its bounding box, and transforms it from the dataset’s native CRS to EPSG:4326 (WGS84 latitude-longitude).

Returns:

The bounding box coordinates in WGS84, returned as (min_longitude, min_latitude, max_longitude, max_latitude).

Return type:

Tuple[float, float, float, float]

Example

The following example assumes that a valid orthomosaic raster file exists at raster_test_data.tif. Actual outputs may vary depending on the specific contents of the raster file.

>>> from brails.utils import RAPIDUtils
>>> rapid_utils = RAPIDUtils('raster_test_data.tif')
Detected orthomosaic data.
Applicable methods for this data type are:
'extract_aerial_imagery', 'get_mosaic_bbox_wgs84'.
>>> bbox_wgs84 = rapid_utils.get_mosaic_bbox_wgs84()
>>> print(bbox_wgs84)
(-122.1421632630, 47.69423131358, -122.12908634292, 47.70804716657)