

 从补丁 198 开始，Amazon Redshift 将不再支持创建新的 Python UDF。现有的 Python UDF 将继续正常运行至 2026 年 6 月 30 日。有关更多信息，请参阅[博客文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

# ST\$1GeomFromGeoSquare
<a name="ST_GeomFromGeoSquare-function"></a>

ST\$1GeomFromGeoSquare 返回一个几何体，该几何体覆盖由输入 geosquare 值表示的区域。返回的几何体始终是二维的。要计算 geosquare 值，请参阅 [ST\$1GeoSquare](ST_GeoSquare-function.md)。

## 语法
<a name="ST_GeomFromGeoSquare-function-syntax"></a>

```
ST_GeomFromGeoSquare(geosquare)
```

```
ST_GeomFromGeoSquare(geosquare, max_depth)
```

## 参数
<a name="ST_GeomFromGeoSquare-function-arguments"></a>

 *geosquare*   
一个数据类型为 `BIGINT` 的值或一个计算结果为 `BIGINT` 类型的 geosquare 值的表达式，该值描述了为达到目标正方形，而在初始域上进行细分的顺序。此值由 [ST\$1GeoSquare](ST_GeoSquare-function.md) 计算。

 *max\$1depth*   
一个数据类型为 `INTEGER` 的值，表示在初始域上进行的最大域细分次数。此值必须等于或大于 `1`。

## 返回类型
<a name="ST_GeomFromGeoSquare-function-return"></a>

`GEOMETRY`

如果 *geosquare* 无效，则该函数会返回错误。

如果输入 *max\$1depth* 不在范围内，则该函数会返回错误。

## 示例
<a name="ST_GeomFromGeoSquare-function-examples"></a>

以下 SQL 从 geosquare 值返回几何体。

```
SELECT ST_AsText(ST_GeomFromGeoSquare(797852));
```

```
 st_astext       
--------------------------------------------------------------------------------------------------------------------
 POLYGON((13.359375 52.3828125,13.359375 52.734375,13.7109375 52.734375,13.7109375 52.3828125,13.359375 52.3828125))
```

以下 SQL 从 geosquare 值返回几何体，最大深度为 `3`。

```
SELECT ST_AsText(ST_GeomFromGeoSquare(797852, 3));
```

```
 st_astext       
--------------------------------------
 POLYGON((0 45,0 90,45 90,45 45,0 45))
```

以下 SQL 首先通过将 x 坐标指定为经度，将 y 坐标指定为纬度 (-122.3, 47.6) 来计算西雅图的 geosquare 值，然后为 geosquare 返回多边形。尽管输出是二维几何体，但它可用于根据经度和纬度计算空间数据。

```
SELECT ST_AsText(ST_GeomFromGeoSquare(ST_GeoSquare(ST_Point(-122.3, 47.6))));
```

```
 st_astext
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
POLYGON((-122.335167014971 47.6080129947513,-122.335167014971 47.6080130785704,-122.335166931152 47.6080130785704,-122.335166931152 47.6080129947513,-122.335167014971 47.6080129947513))
```