get_extent#
- get_extent(ds: str | CloudPath | Path | Tuple[ndarray | MaskedArray, dict] | DataArray | Dataset | DatasetReader | DatasetWriter) GeoDataFrame [source]#
Get the extent of a raster as a
geopandas.Geodataframe
.- Parameters:
ds (AnyRasterType) – Path to the raster, its dataset, its
xarray
or a tuple containing its array and metadata- Returns:
Extent as a
geopandas.Geodataframe
- Return type:
gpd.GeoDataFrame
Example
>>> raster_path = "path/to/raster.tif" >>> >>> extent1 = get_extent(raster_path) >>> # or >>> with rasterio.open(raster_path) as ds: >>> extent2 = get_extent(ds) >>> >>> # Assert those two approaches give the same result >>> extent1 == extent2 True