适用于:
Databricks Runtime 18.2 及更高版本
Important
此功能目前以公共预览版提供。
返回一个 Geometry ,表示由两个角坐标和两个角坐标(x1, y1)(x2, y2)定义的二维轴对齐信封(最小边界框)。
有关相应的 Databricks SQL 函数,请参阅 st_makeenvelope 函数。
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.st_makeenvelope(x1=<x1>, y1=<y1>, x2=<x2>, y2=<y2>)
参数
| 参数 | 类型 | Description |
|---|---|---|
x1 |
pyspark.sql.Column 或浮点数 |
第一个角的 X 坐标。 |
y1 |
pyspark.sql.Column 或浮点数 |
第一个角的 Y 坐标。 |
x2 |
pyspark.sql.Column 或浮点数 |
第二角的 X 坐标。 |
y2 |
pyspark.sql.Column 或浮点数 |
第二个角的 Y 坐标。 |
Returns
pyspark.sql.Column:表示两个输入角的 2D 轴对齐信封的 Geometry 值的列。 返回的几何图形的 SRID 为 0。
可以按任意顺序提供输入角;生成的信封与转角规范化到 (xmin, ymin) 和 (xmax, ymax)规范化时相同。
返回的几何图形的类型取决于输入角:
- 如果框退化为单个点(
x1 = x2并且y1 = y2),则结果是一个点。 - 如果框退化为段(
x1 = x2或y1 = y2,但不是两者),则结果是一个带两个点的线字符串。 - 否则,结果是具有五个顶点(封闭环)的多边形。
如果任何输入为None,该函数将返回None。
示例
# Returns the polygon envelope defined by two corners.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(1.0, 2.0, 4.0, 6.0)], ['x1', 'y1', 'x2', 'y2'])
df.select(dbf.st_astext(dbf.st_makeenvelope('x1', 'y1', 'x2', 'y2')).alias('result')).collect()
[Row(result='POLYGON((1 2,1 6,4 6,4 2,1 2))')]
# Corners may be provided in any order.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(4.0, 6.0, 1.0, 2.0)], ['x1', 'y1', 'x2', 'y2'])
df.select(dbf.st_astext(dbf.st_makeenvelope('x1', 'y1', 'x2', 'y2')).alias('result')).collect()
[Row(result='POLYGON((1 2,1 6,4 6,4 2,1 2))')]
# Returns a point when the box degenerates to a point.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(3.0, 5.0, 3.0, 5.0)], ['x1', 'y1', 'x2', 'y2'])
df.select(dbf.st_astext(dbf.st_makeenvelope('x1', 'y1', 'x2', 'y2')).alias('result')).collect()
[Row(result='POINT(3 5)')]
# Returns a linestring when the box degenerates to a horizontal segment.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(1.0, 0.0, 4.0, 0.0)], ['x1', 'y1', 'x2', 'y2'])
df.select(dbf.st_astext(dbf.st_makeenvelope('x1', 'y1', 'x2', 'y2')).alias('result')).collect()
[Row(result='LINESTRING(1 0,4 0)')]
# Returns a linestring when the box degenerates to a vertical segment.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(0.0, 2.0, 0.0, 7.0)], ['x1', 'y1', 'x2', 'y2'])
df.select(dbf.st_astext(dbf.st_makeenvelope('x1', 'y1', 'x2', 'y2')).alias('result')).collect()
[Row(result='LINESTRING(0 2,0 7)')]
# The SRID of the returned geometry is always 0.
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(0.0, 0.0, 10.0, 10.0)], ['x1', 'y1', 'x2', 'y2'])
df.select(dbf.st_srid(dbf.st_makeenvelope('x1', 'y1', 'x2', 'y2')).alias('result')).collect()
[Row(result=0)]