st_makeenvelope
対象: Databricks Runtime 18.2以降
備考
プレビュー
この機能は パブリック プレビュー段階です。
2 つの角座標(x1, y1)と(x2, y2)で定義される 2D 軸に沿ったエンベロープ (最小境界ボックス) を表すジオメトリを返します。
対応する Databricks SQL 関数については、 st_makeenvelope関数を参照してください。
構文
Python
from pyspark.databricks.sql import functions as dbf
dbf.st_makeenvelope(x1=<x1>, y1=<y1>, x2=<x2>, y2=<y2>)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
|
| 最初の角のX座標。 |
|
| 最初の角のY座標。 |
|
| 2番目の角のX座標。 |
|
| 2番目の角のY座標。 |
戻り値
pyspark.sql.Column2つの入力コーナーの2次元軸に沿った包絡線を表すジオメトリ値の列。返されたジオメトリのSRIDは0です。
入力コーナーは任意の順序で指定できます。結果として得られるエンベロープは、コーナーが(xmin, ymin)と(xmax, ymax)に正規化された場合と同じです。
返されるジオメトリのタイプは、入力されたコーナーによって異なります。
- ボックスが単一の点(
x1 = x2とy1 = y2)に退化する場合、結果は点になります。 - ボックスがセグメント(
x1 = x2またはy1 = y2、ただし両方ではない)に退化する場合、結果は2つの点を持つ線分になります。 - それ以外の場合は、頂点が5つの多角形(閉じた環)が生成される。
入力値のいずれかがNoneの場合、関数はNoneを返します。
例
Python
# 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()
Output
[Row(result='POLYGON((1 2,1 6,4 6,4 2,1 2))')]
Python
# 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()
Output
[Row(result='POLYGON((1 2,1 6,4 6,4 2,1 2))')]
Python
# 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()
Output
[Row(result='POINT(3 5)')]
Python
# 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()
Output
[Row(result='LINESTRING(1 0,4 0)')]
Python
# 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()
Output
[Row(result='LINESTRING(0 2,0 7)')]
Python
# 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()
Output
[Row(result=0)]