> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Spatial data types

> The Spark SQL types of geometry, geography, box, and raster columns, and the Python values they hold.

```python theme={"system"}
from sedona.spark.sql.types import GeometryType, GeographyType, RasterType
```

## Box2DType

```python theme={"system"}
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

```python theme={"system"}
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.

## GeographyType

```python theme={"system"}
GeographyType()
```

Spark SQL type of Sedona geography columns.

Geography values are `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

```python theme={"system"}
GeometryType()
```

Spark SQL type of Sedona geometry columns.

Geometry values are Shapely geometries in Python: `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

```python theme={"system"}
>>> from pyspark.sql.types import StructField, StructType
>>> from shapely.geometry import Point
>>> from sedona.spark.sql.types import GeometryType
>>> schema = StructType([StructField("geom", GeometryType())])
>>> df = sedona.createDataFrame([(Point(1, 2),)], schema)  # doctest: +SKIP
```

## is\_geography\_type

```python theme={"system"}
is_geography_type(data_type) -> bool
```

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

<ParamField path="data_type" type="pyspark.sql.types.DataType" required>
  The data type to check, such as `df.schema["geog"].dataType`.
</ParamField>

#### Returns

<ResponseField name="return" type="bool" />

## is\_geometry\_type

```python theme={"system"}
is_geometry_type(data_type) -> bool
```

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

<ParamField path="data_type" type="pyspark.sql.types.DataType" required>
  The data type to check, such as `df.schema["geom"].dataType`.
</ParamField>

#### Returns

<ResponseField name="return" type="bool" />

## RasterType

```python theme={"system"}
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

```python theme={"system"}
to_shapely(value)
```

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. 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

<ParamField path="value" type="object" required>
  A value of a geometry or geography column from `DataFrame.collect()`,
  or None.
</ParamField>

#### Returns

<ResponseField name="return" type="object">
  The value as a Shapely geometry. Shapely geometries, Sedona `Geography`
  objects and None are returned unchanged.
</ResponseField>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.