|
14 | 14 |
|
15 | 15 | from __future__ import annotations |
16 | 16 |
|
17 | | -from typing import Union |
| 17 | +import json |
| 18 | +from typing import Mapping, Optional, Union |
18 | 19 |
|
19 | 20 | import shapely # type: ignore |
20 | 21 |
|
21 | 22 | from bigframes import operations as ops |
| 23 | +import bigframes.dataframe |
22 | 24 | import bigframes.geopandas |
23 | 25 | import bigframes.series |
24 | 26 |
|
@@ -677,6 +679,65 @@ def st_length( |
677 | 679 | return series |
678 | 680 |
|
679 | 681 |
|
| 682 | +def st_regionstats( |
| 683 | + geography: Union[bigframes.series.Series, bigframes.geopandas.GeoSeries], |
| 684 | + raster_id: str, |
| 685 | + band: Optional[str] = None, |
| 686 | + include: Optional[str] = None, |
| 687 | + options: Optional[Mapping[str, Union[str, int, float]]] = None, |
| 688 | +) -> bigframes.series.Series: |
| 689 | + """Returns statistics summarizing the pixel values of the raster image |
| 690 | + referenced by raster_id that intersect with geography. |
| 691 | +
|
| 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. |
| 695 | +
|
| 696 | + See: https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_regionstats |
| 697 | +
|
| 698 | + Args: |
| 699 | + geography (bigframes.series.Series | bigframes.geopandas.GeoSeries): |
| 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. |
| 724 | + options (Mapping[str, Union[str, int, float]], optional): |
| 725 | + A dictionary of options to pass to the function. See the BigQuery |
| 726 | + documentation for a list of available options. |
| 727 | +
|
| 728 | + Returns: |
| 729 | + bigframes.pandas.Series: |
| 730 | + A STRUCT Series containing the computed statistics. |
| 731 | + """ |
| 732 | + op = ops.GeoStRegionStatsOp( |
| 733 | + raster_id=raster_id, |
| 734 | + band=band, |
| 735 | + include=include, |
| 736 | + options=json.dumps(options) if options else None, |
| 737 | + ) |
| 738 | + return geography._apply_unary_op(op) |
| 739 | + |
| 740 | + |
680 | 741 | def st_simplify( |
681 | 742 | geography: "bigframes.series.Series", |
682 | 743 | tolerance_meters: float, |
|
0 commit comments