Skip to main content

st_asbinary

Preview

This feature is in Public Preview. You can confirm preview enrollment on the Previews page. See Manage Databricks previews.

Returns the input Geography or Geometry value in WKB format.

For the corresponding Databricks SQL function, see st_asbinary function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.st_asbinary(col1=<col1>, col2=<col2>)

Parameters

Parameter

Type

Description

col1

pyspark.sql.Column or str

A geospatial value, either a Geography or Geometry.

col2

pyspark.sql.Column or str, optional

The optional endianness of the output WKB, NDR for little-endian (default) or XDR for big-endian.

Examples

Python
from pyspark.databricks.sql import functions as dbf
from pyspark.sql.functions import hex
df = spark.createDataFrame([('LINESTRING(1 2,3 4)',)], ['wkt'])
df.select(hex(dbf.st_asbinary(dbf.st_geogfromtext('wkt'))).alias('result')).collect()
Output
[Row(result='010200000002000000000000000000F03F000000000000004000000000000008400000000000001040')]
Python
from pyspark.databricks.sql import functions as dbf
from pyspark.sql.functions import hex
df = spark.createDataFrame([('LINESTRING(1 2,3 4)', 'NDR',)], ['wkt', 'e'])
df.select(hex(dbf.st_asbinary(dbf.st_geogfromtext('wkt'), df.e)).alias('result')).collect()
Output
[Row(result='010200000002000000000000000000F03F000000000000004000000000000008400000000000001040')]
Python
from pyspark.databricks.sql import functions as dbf
from pyspark.sql.functions import hex
df = spark.createDataFrame([('LINESTRING(1 2,3 4)',)], ['wkt'])
df.select(hex(dbf.st_asbinary(dbf.st_geogfromtext('wkt'), 'XDR')).alias('result')).collect()
Output
[Row(result='0000000002000000023FF0000000000000400000000000000040080000000000004010000000000000')]