Skip to main content

Box2DType

Spark SQL type of Sedona 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

Spark SQL type of Sedona 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.

geography_type

Default geography schema for the installed Spark runtime.

geometry_type

Default spatial schema; native schemas allow a different SRID in each row.

is_geography_type

True if 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

True if 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

LegacyGeographyType

Decode legacy geography UDT schemas with little-endian SRID/ISO WKB payloads. On Spark 4.2, Classic DataFrame creation from Sedona Geography values requires an explicit legacy schema and verifySchema=False because those values no longer carry a UDT marker. Use to_spark_geography for native input.

LegacyGeometryType

Decode legacy geometry UDT schemas on native spatial runtimes. On Spark 4.2, Sedona does not attach a UDT marker to Shapely classes. To create a Classic DataFrame from Shapely values with an explicit legacy schema, pass verifySchema=False. For ordinary native input, use to_spark_geometry.

RasterType

Spark SQL type of Sedona raster columns. Raster values are 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

Normalize a geometry value obtained from 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. Spark’s native types validate their supported SRIDs. 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 pass through unchanged on older runtimes and unwrap on Spark 4.2+. 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 and None are returned unchanged. Sedona Geography objects are unwrapped on Spark 4.2 and later, and returned unchanged on older runtimes.

to_spark_geography

Convert a Shapely geometry (or Sedona Geography) to a Spark geography. On Spark 4.2+, an unset Shapely SRID (0) defaults to WGS84 (4326), matching Spark’s native geography constructor. Other embedded SRIDs are preserved. Older Spark returns Sedona’s Geography wrapper. None is preserved.

Parameters

object
required
A Shapely geometry, Sedona Geography wrapper, existing Spark native geography value, or None. A Sedona wrapper’s nonzero SRID takes precedence over the SRID stored in its Shapely geometry.

Returns

object
A native geography on Spark 4.2 or later, a Sedona Geography wrapper on older runtimes, or None for a null input.

to_spark_geometry

Convert a Shapely geometry to Spark’s spatial value, preserving its SRID. Spark 4.2+ returns a native pyspark.sql.types.Geometry. Older Spark versions accept Shapely directly through Sedona’s UDT and return it unchanged. None is preserved. Native conversion requires Shapely 2 or later.

Parameters

shapely.geometry.base.BaseGeometry or pyspark.sql.types.Geometry or None
required
A Shapely geometry, an existing native geometry value, or None.

Returns

object
A native geometry on Spark 4.2 or later, the input on older runtimes, or None for a null input.