Box2DType
box2d columns, such as the result of ST_Box2D.
Values are sedona.spark.core.geom.box2d.Box2D objects in Python, with
xmin, ymin, xmax and ymax attributes. A column of this type is
stored as a struct of those four doubles.
Box3DType
box3d columns, such as the result of ST_Box3D.
Values are sedona.spark.core.geom.box3d.Box3D objects in Python, with
xmin, ymin, zmin, xmax, ymax and zmax attributes. A
column of this type is stored as a struct of those six doubles.
GeographyType
sedona.spark.core.geom.geography.Geography
objects in Python, which hold a Shapely geometry in their geometry
attribute. DataFrame.collect() returns them, and Geography objects
passed to createDataFrame are stored as geographies.
This is the Python side of org.apache.spark.sql.sedona_sql.UDT.GeographyUDT.
The JVM serializes a geography as a 4-byte big-endian SRID followed by standard
WKB (GeographyWKBSerializer), which is a different layout from the Sedona
geometry serde used by GeometryType. Both directions here must match it.
GeometryType
DataFrame.collect()
returns Shapely geometry objects, and Shapely geometries passed to
createDataFrame are stored as geometries. Use GeometryType() in a
schema to declare a geometry column.
With spark.sedona.enableNativeGeoTypes=true on Spark 4.1 or later, Sedona
emits Spark’s native geometry type instead. Use is_geometry_type to
recognize both, and to_shapely to convert their values to Shapely.
Examples
is_geography_type
data_type is a geography column type in either mode: Sedona’s
GeographyType UDT, or (PySpark >= 4.1) Spark’s native GeographyType.
Parameters
pyspark.sql.types.DataType
required
The data type to check, such as
df.schema["geog"].dataType.Returns
bool
is_geometry_type
data_type is a geometry column type in either mode: Sedona’s
GeometryType UDT, or (PySpark >= 4.1) Spark’s native GeometryType.
Parameters
pyspark.sql.types.DataType
required
The data type to check, such as
df.schema["geom"].dataType.Returns
bool
RasterType
sedona.spark.raster.SedonaRaster objects in
Python, which DataFrame.collect() and Python UDFs receive. Converting
raster values requires rasterio; without it, they raise
NotImplementedError. Only in-db rasters can be converted back to a
raster column, for example when a UDF returns one.
to_shapely
DataFrame.collect() to shapely.
UDT-typed columns already deserialize to shapely and are returned as-is. Native
columns (PySpark >= 4.1) yield pyspark.sql.types.Geometry (WKB + SRID), which
is parsed here; the SRID is attached via shapely.set_srid when available
(shapely >= 2.0). None passes through. Note Spark’s external boundary only
supports whitelisted SRIDs {0, 3857, 4326} for native columns.
The native wrapper is detected structurally (getBytes/getSrid), which
covers both pyspark.sql.types.Geometry and pyspark.sql.types.Geography —
native geography values also parse to (planar) shapely geometries. Sedona’s own
UDT geography columns deserialize to sedona.spark.core.geom.geography.Geography
and pass through unchanged. Field order is normalized defensively: PySpark 4.1’s own internal conversion is
asymmetric (toInternal writes the key wkb while fromInternal reads
bytes), so depending on the collect path the wrapper can arrive with swapped
fields, or the raw {"srid": ..., "wkb"/"bytes": ...} dict can surface directly.
Parameters
object
required
A value of a geometry or geography column from
DataFrame.collect(),
or None.Returns
object
The value as a Shapely geometry. Shapely geometries, Sedona
Geography
objects and None are returned unchanged.
