collocate

Contents

collocate#

collocate(reference_meta: dict, other_arr: ~numpy.ndarray | ~numpy.ma.MaskedArray, other_meta: dict, resampling: ~rasterio.enums.Resampling = Resampling.nearest) -> (typing.Union[numpy.ndarray, numpy.ma.MaskedArray], <class 'dict'>)[source]#

Collocate two georeferenced arrays: forces the other raster to be exactly georeferenced onto the reference raster by reprojection.

Parameters:
  • reference_meta (dict) – Reference metadata

  • other_arr (np.ma.masked_array) – Other array to be collocated

  • other_meta (dict) – Other metadata

  • resampling (Resampling) – Resampling method

Returns:

Collocated array and its metadata

Return type:

np.ma.masked_array, dict

Example

>>> reference_path = "path/to/reference.tif"
>>> other_path = "path/to/other.tif"
>>> col_path = "path/to/collocated.tif"
>>>
>>> # Just open the master data
>>> with rasterio.open(reference_path) as reference_dst:
>>>     # Read other
>>>     other, other_meta = read(other_path)
>>>
>>>     # Collocate the other to the reference
>>>     col_arr, col_meta = collocate(reference_dst.meta,
>>>                                   other,
>>>                                   other_meta,
>>>                                   Resampling.bilinear)
>>>
>>> # Write it
>>> write(col_arr, col_path, col_meta)