適用於:
執行環境 18.2 及以上版本
回傳一個幾何體,代表由兩個角座標(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>)
Parameters
| 參數 | 類型 | 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:一列幾 何 值,代表兩個輸入角的二維軸對齊包絡線。 返回幾何體的 SRID 為 0。
輸入角可任意順序提供;所得包絡線與角點正規化為 (xmin, ymin)(xmax, ymax)和 相同。
回傳幾何形狀的類型取決於輸入角點:
- 若該框退化為單一點(
x1 = x2且y1 = y2),則結果為一個點。 - 如果盒子退化成一段(
x1 = x2或y1 = y2,但不會兩者皆是),結果是一條有兩個點的線串。 - 否則,結果是一個有五個頂點的多邊形(閉環)。
如果任何輸入為 None,則函式會傳None回 。
Examples
# 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)]