st_numpoints

適用於:勾選為 是 Databricks 執行時間 18.1 及以上版本

這很重要

地理值的支援目前已 在公開預覽階段。 對 GEOMETRY 值的支援已正式提供。

回傳輸入的 Geography 或 Geometry 值中非空的點的數量。

若輸入為 None,則該函式回傳 None。

關於對應的 Databricks SQL 函式,請參見 st_numpoints 函數。

這個函式是 st_npoints的別名。

語法

from pyspark.databricks.sql import functions as dbf

dbf.st_numpoints(col=<col>)

參數

參數 類型 說明
col pyspark.sql.Column 或 str 地理或幾何值。

Examples

回傳非空多點幾何的點數:

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOINT(10 34,44 57,EMPTY)',)], ['wkt'])
df.select(dbf.st_numpoints(dbf.st_geomfromtext('wkt')).alias('result')).collect()
[Row(result=2)]

回傳空多點幾何中的點數:

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('MULTIPOINT(EMPTY,EMPTY)',)], ['wkt'])
df.select(dbf.st_numpoints(dbf.st_geomfromtext('wkt')).alias('result')).collect()
[Row(result=0)]

回傳非空多邊形幾何中的點數:

from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('POLYGON((0 0,1 0,1 1,0 1,0 0))',)], ['wkt'])
df.select(dbf.st_numpoints(dbf.st_geomfromtext('wkt')).alias('result')).collect()
[Row(result=5)]