1515from __future__ import annotations
1616
1717import json
18- from typing import Mapping , Union
18+ from typing import Mapping , Optional , Union
1919
2020import shapely # type: ignore
2121
@@ -681,25 +681,46 @@ def st_length(
681681
682682def st_regionstats (
683683 geography : Union [bigframes .series .Series , bigframes .geopandas .GeoSeries ],
684- raster : bigframes .series .Series ,
685- band : str ,
686- options : Mapping [str , Union [str , int , float ]] = {},
684+ raster_id : str ,
685+ band : Optional [str ] = None ,
686+ include : Optional [str ] = None ,
687+ options : Optional [Mapping [str , Union [str , int , float ]]] = None ,
687688) -> bigframes .dataframe .DataFrame :
688- """Computes statistics for a raster band within a given geography.
689+ """Returns statistics summarizing the pixel values of the raster image
690+ referenced by raster_id that intersect with geography.
689691
690- See: https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_regionstats
692+ The statistics include the count, minimum, maximum, sum, standard
693+ deviation, mean, and area of the valid pixels of the raster band named
694+ band_name. Google Earth Engine computes the results of the function call.
691695
692- .. warning::
693- This function requires the Earth Engine API to be enabled.
696+ See: https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_regionstats
694697
695698 Args:
696699 geography (bigframes.series.Series | bigframes.geopandas.GeoSeries):
697- A series of geography objects.
698- raster (bigframes.series.Series):
699- A series of raster URIs. This can be a Google Cloud Storage URI,
700- or an Earth Engine asset ID.
701- band (str):
702- The name of the raster band to compute statistics for.
700+ A series of geography objects to intersect with the raster image.
701+ raster_id (str):
702+ A string that identifies a raster image. The following formats are
703+ supported. A URI from an image table provided by Google Earth Engine
704+ in BigQuery sharing (formerly Analytics Hub). A URI for a readable
705+ GeoTIFF raster file. A Google Earth Engine asset path that
706+ references public catalog data or project-owned assets with read
707+ access.
708+ band (Optional[str]):
709+ A string in one of the following formats:
710+ A single band within the raster image specified by raster_id. A
711+ formula to compute a value from the available bands in the raster
712+ image. The formula uses the Google Earth Engine image expression
713+ syntax. Bands can be referenced by their name, band_name, in
714+ expressions. If you don't specify a band, the first band of the
715+ image is used.
716+ include (Optional[str]):
717+ An optional string formula that uses the Google Earth Engine image
718+ expression syntax to compute a pixel weight. The formula should
719+ return values from 0 to 1. Values outside this range are set to the
720+ nearest limit, either 0 or 1. A value of 0 means that the pixel is
721+ invalid and it's excluded from analysis. A positive value means that
722+ a pixel is valid. Values between 0 and 1 represent proportional
723+ weights for calculations, such as weighted means.
703724 options (Mapping[str, Union[str, int, float]], optional):
704725 A dictionary of options to pass to the function. See the BigQuery
705726 documentation for a list of available options.
@@ -708,6 +729,11 @@ def st_regionstats(
708729 bigframes.dataframe.DataFrame:
709730 A dataframe containing the computed statistics.
710731 """
711- op = ops .StRegionStatsOp (options = json .dumps (options ) if options else None )
712- df = geography ._apply_ternary_op (raster , band , op )
732+ op = ops .StRegionStatsOp (
733+ raster_id = raster_id ,
734+ band = band ,
735+ include = include ,
736+ options = json .dumps (options ) if options else None ,
737+ )
738+ df = geography ._apply_unary_op (op )
713739 return df [df .columns [0 ]].struct .explode ()
0 commit comments