get_extent#
- get_extent(xds: str | CloudPath | Path | tuple[ndarray | MaskedArray, dict] | DataArray | Dataset | DatasetReader | DatasetWriter) GeoDataFrame [source]#
Get the extent of a raster as a
geopandas.Geodataframe
.- Parameters:
xds (AnyRasterType) – Path to the raster or a rasterio dataset or a xarray
- 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