Python Package#

class space2stats.lib.StatsTable(conn: psycopg.Connection, table_name: str)#

Bases: object

aggregate(aoi: Feature[Polygon | MultiPolygon, Dict], spatial_join_method: Literal['touches', 'centroid', 'within'], fields: List[str], aggregation_type: Literal['sum', 'avg', 'count', 'max', 'min']) Dict[str, float]#

Aggregate Statistics from a GeoJSON feature.

conn: Connection#
classmethod connect(settings: Settings | None = None, **kwargs) StatsTable#

Helper method to connect to the database and return a StatsTable instance.

with StatsTable.connect() as stats_table:
    stats_table.fields()
fields() List[str]#
summaries(aoi: Feature[Polygon | MultiPolygon, Dict], spatial_join_method: Literal['touches', 'centroid', 'within'], fields: List[str], geometry: Literal['polygon', 'point'] | None = None)#

Retrieve Statistics from a GeoJSON feature.

Parameters:
  • aoi (GeoJSON Feature) – The Area of Interest, either as a Feature or an instance of AoiModel

  • spatial_join_method (["touches", "centroid", "within"]) –

    The method to use for performing the spatial join between the AOI and H3 cells
    • ”touches”: Includes H3 cells that touch the AOI

    • ”centroid”: Includes H3 cells where the centroid falls within the AOI

    • ”within”: Includes H3 cells entirely within the AOI

  • fields (List[str]) – A list of field names to retrieve from the statistics table.

  • geometry (Optional["polygon", "point"]) – Specifies if the H3 geometries should be included in the response. It can be either “polygon” or “point”. If None, geometries are not included

Returns:

A list of dictionaries containing statistical summaries for each H3 cell. Each dictionary contains:
  • ”hex_id”: The H3 cell identifier

  • ”geometry” (optional): The geometry of the H3 cell, if geometry is specified.

  • Other fields from the statistics table, based on the specified fields

Return type:

List[Dict]

table_name: str#