(src_path: Union[str, pathlib.PurePath], **kwargs: Any)
return models.Info(
        Path=str(src_path),
        Driver=driver,
        COG=is_valid,
        Compression=compression,
        ColorSpace=colorspace,
        COG_errors=validation_errors or None,
        COG_warnings=validation_warnings or None,
        Profile=profile,
        GEO=geo,
        Tags=tags,
        Band_Metadata=band_metadata,
        IFD=ifds,
    )
Get general info and validate Cloud Optimized Geotiff.
Get general info and validate Cloud Optimized Geotiff.
Get general info and validate Cloud Optimized Geotiff .
def cog_info(src_path: Union[str, pathlib.PurePath], **kwargs: Any) -> models.Info:
    """Get general info and validate Cloud Optimized Geotiff."""
    is_valid, validation_errors, validation_warnings = cog_validate(
        src_path, quiet=True, **kwargs,
    )

    with rasterio.open(src_path) as src_dst:
        driver = src_dst.driver
        compression = src_dst.compression.value if src_dst.compression else None
        colorspace = src_dst.photometric.value if src_dst.photometric else None
        overviews = src_dst.overviews(1)

        tags = {"Image Metadata": src_dst.tags()}
        namespaces = src_dst.tag_namespaces()
        for ns in namespaces:
            if ns in ["DERIVED_SUBDATASETS"]:
                continue
            tags.update({str.title(ns).replace("_", " "): src_dst.tags(ns=ns)})

        band_metadata = {
            f"Band {ix}": models.BandMetadata(
                **{
                    "Description": src_dst.descriptions[ix - 1],
                    "ColorInterp": src_dst.colorinterp[ix - 1].name,
                    "Offset": src_dst.offsets[ix - 1],
                    "Scale": src_dst.scales[ix - 1],
                    "Metadata": src_dst.tags(ix),
                }
            )
            for ix in src_dst.indexes
        }

        try:
            colormap = src_dst.colormap(1)
        except ValueError:
            colormap = None

        profile = models.Profile(
            Bands=src_dst.count,
            Width=src_dst.width,
            Height=src_dst.height,
            Tiled=src_dst.is_tiled,
            Dtype=src_dst.dtypes[0],
            Interleave=src_dst.interleaving.value,
            AlphaBand=utils.has_alpha_band(src_dst),
            InternalMask=utils.has_mask_band(src_dst),
            Nodata=src_dst.nodata,
            ColorInterp=tuple([color.name for color in src_dst.colorinterp]),
            ColorMap=colormap is not None,
            Scales=src_dst.scales,
            Offsets=src_dst.offsets,
        )

        try:
            crs = (
                f"EPSG:{src_dst.crs.to_epsg()}"
                if src_dst.crs.to_epsg()
                else src_dst.crs.to_wkt()
            )
        except AttributeError:
            crs = None

        minzoom: Optional[int] = None
        maxzoom: Optional[int] = None
        try:
            minzoom, maxzoom = utils.get_zooms(src_dst)
        except Exception:
            pass

        geo = models.Geo(
            CRS=crs,
            BoundingBox=tuple(src_dst.bounds),
            Origin=(src_dst.transform.c, src_dst.transform.f),
            Resolution=(src_dst.transform.a, src_dst.transform.e),
            MinZoom=minzoom,
            MaxZoom=maxzoom,
        )

        ifds = [
            models.IFD(
                Level=0,
                Width=src_dst.width,
                Height=src_dst.height,
                Blocksize=src_dst.block_shapes[0],
                Decimation=0,
            )
        ]

    for ix, decim in enumerate(overviews):
        with rasterio.open(src_path, OVERVIEW_LEVEL=ix) as ovr_dst:
            ifds.append(
                models.IFD(
                    Level=ix + 1,
                    Width=ovr_dst.width,
                    Height=ovr_dst.height,
                    Blocksize=ovr_dst.block_shapes[0],
                    Decimation=decim,
                )
            )

    return models.Info(
        Path=str(src_path),
        Driver=driver,
        COG=is_valid,
        Compression=compression,
        ColorSpace=colorspace,
        COG_errors=validation_errors or None,
        COG_warnings=validation_warnings or None,
        Profile=profile,
        GEO=geo,
        Tags=tags,
        Band_Metadata=band_metadata,
        IFD=ifds,
    )
def cog_info ( src_path : Union [ str , pathlib . PurePath ] , * * kwargs : Any ) -> models . Info : is_valid , validation_errors , validation_warnings = cog_validate ( src_path , quiet = True , * * kwargs , ) with rasterio . open ( src_path ) as src_dst : driver = src_dst . driver compression = src_dst . compression . value if src_dst . compression else None colorspace = src_dst . photometric . value if src_dst . photometric else None overviews = src_dst . overviews ( 1 ) tags = { "Image Metadata" : src_dst . tags ( ) } namespaces = src_dst . tag_namespaces ( ) for ns in namespaces : if ns in [ "DERIVED_SUBDATASETS" ] : continue tags . update ( { str . title ( ns ) . replace ( "_" , " " ) : src_dst . tags ( ns = ns ) } ) band_metadata = { f"Band {ix}" : models . BandMetadata ( * * { "Description" : src_dst . descriptions [ ix - 1 ] , "ColorInterp" : src_dst . colorinterp [ ix - 1 ] . name , "Offset" : src_dst . offsets [ ix - 1 ] , "Scale" : src_dst . scales [ ix - 1 ] , "Metadata" : src_dst . tags ( ix ) , } ) for ix in src_dst . indexes } try : colormap = src_dst . colormap ( 1 ) except ValueError : colormap = None profile = models . Profile ( Bands = src_dst . count , Width = src_dst . width , Height = src_dst . height , Tiled = src_dst . is_tiled , Dtype = src_dst . dtypes [ 0 ] , Interleave = src_dst . interleaving . value , AlphaBand = utils . has_alpha_band ( src_dst ) , InternalMask = utils . has_mask_band ( src_dst ) , Nodata = src_dst . nodata , ColorInterp = tuple ( [ color . name for color in src_dst . colorinterp ] ) , ColorMap = colormap is not None , Scales = src_dst . scales , Offsets = src_dst . offsets , ) try : crs = ( f"EPSG:{src_dst.crs.to_epsg()}" if src_dst . crs . to_epsg ( ) else src_dst . crs . to_wkt ( ) ) except AttributeError : crs = None minzoom : Optional [ int ] = None maxzoom : Optional [ int ] = None try : minzoom , maxzoom = utils . get_zooms ( src_dst ) except Exception : pass geo = models . Geo ( CRS = crs , BoundingBox = tuple ( src_dst . bounds ) , Origin = ( src_dst . transform . c , src_dst . transform . f ) , Resolution = ( src_dst . transform . a , src_dst . transform . e ) , MinZoom = minzoom , MaxZoom = maxzoom , ) ifds = [ models . IFD ( Level = 0 , Width = src_dst . width , Height = src_dst . height , Blocksize = src_dst . block_shapes [ 0 ] , Decimation = 0 , ) ] for ix , decim in enumerate ( overviews ) : with rasterio . open ( src_path , OVERVIEW_LEVEL = ix ) as ovr_dst : ifds . append ( models . IFD ( Level = ix + 1 , Width = ovr_dst . width , Height = ovr_dst . height , Blocksize = ovr_dst . block_shapes [ 0 ] , Decimation = decim , ) ) return models . Info ( Path = str ( src_path ) , Driver = driver , COG = is_valid , Compression = compression , ColorSpace = colorspace , COG_errors = validation_errors or None , COG_warnings = validation_warnings or None , Profile = profile , GEO = geo , Tags = tags , Band_Metadata = band_metadata , IFD = ifds , )