accessmod/zonalstats.py
def population_counts(
    boundaries: BoundariesLayer, population: PopulationLayer
) -> pd.Series:
    """Count population in each boundary.

    Parameters
    ----------
    boundaries : BoundariesLayer
        Input boundaries vector layer.
    population : PopulationLayer
        Input population raster layer (population count per pixel).

    Return
    -------
    Serie
        Population counts per area as a pandas Serie.
    """
    areas = enforce_crs(boundaries.read(), crs=population.meta["crs"])
    shapes = [area.__geo_interface__ for area in areas.geometry]
    stats = zonal_stats(
        shapes,
        population.read(),
        affine=population.meta["transform"],
        stats=["sum"],
        nodata=population.meta["nodata"],
    )
    data = pd.Series(data=[stat["sum"] for stat in stats], index=areas.index)
    logger.info(f"Counted population for {len(shapes)} areas (total={data.sum()})")
    return data
Count population in each boundary.

    Parameters
    ----------
    boundaries : BoundariesLayer
        Input boundaries vector layer.
    population : PopulationLayer
        Input population raster layer (population count per pixel).

    Return
    -------
    Serie
        Population counts per area as a pandas Serie.
    
Count population in each boundary.
Parameters

boundaries : BoundariesLayer
Input boundaries vector layer.
population : PopulationLayer
Input population raster layer (population count per pixel).

Return

Serie
Population counts per area as a pandas Serie.
Count population in each boundary . Parameters boundaries : BoundariesLayer Input boundaries vector layer . population : PopulationLayer Input population raster layer ( population count per pixel ) . Return Serie Population counts per area as a pandas Serie .
def population_counts(
    boundaries: BoundariesLayer, population: PopulationLayer
) -> pd.Series:
    areas = enforce_crs(boundaries.read(), crs=population.meta["crs"])
    shapes = [area.__geo_interface__ for area in areas.geometry]
    stats = zonal_stats(
        shapes,
        population.read(),
        affine=population.meta["transform"],
        stats=["sum"],
        nodata=population.meta["nodata"],
    )
    data = pd.Series(data=[stat["sum"] for stat in stats], index=areas.index)
    logger.info(f"Counted population for {len(shapes)} areas (total={data.sum()})")
    return data
def population_counts ( boundaries : BoundariesLayer , population : PopulationLayer ) -> pd . Series : areas = enforce_crs ( boundaries . read ( ) , crs = population . meta [ "crs" ] ) shapes = [ area . __geo_interface__ for area in areas . geometry ] stats = zonal_stats ( shapes , population . read ( ) , affine = population . meta [ "transform" ] , stats = [ "sum" ] , nodata = population . meta [ "nodata" ] , ) data = pd . Series ( data = [ stat [ "sum" ] for stat in stats ] , index = areas . index ) logger . info ( f"Counted population for {len(shapes)} areas (total={data.sum()})" ) return data
Count population in each boundary.
Count population in each boundary .
"""Count population in each boundary.

    Parameters
    ----------
    boundaries : BoundariesLayer
        Input boundaries vector layer.
    population : PopulationLayer
        Input population raster layer (population count per pixel).

    Return
    -------
    Serie
        Population counts per area as a pandas Serie.
    """
boundaries
BoundariesLayer
population
PopulationLayer