# Geometry

GeoJSON-compatible geometry types for spatial data.

The SDK provides GeoJSON-compatible geometry types for working with SurrealDB's spatial data. All geometry classes extend the `Geometry` base class.

```python title="Import"
from surrealdb import (
    GeometryPoint,
    GeometryLine,
    GeometryPolygon,
    GeometryMultiPoint,
    GeometryMultiLine,
    GeometryMultiPolygon,
    GeometryCollection,
)
```

Individual types can also be imported from `surrealdb.data.types.geometry`.

---

## `GeometryPoint` {#geometrypoint}

A single geographic point defined by longitude and latitude.

### Constructor {#point-constructor}

```python title="Syntax"
GeometryPoint(longitude, latitude)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>longitude</code> _(required)_</td>
            <td><code>float</code></td>
            <td>The longitude coordinate.</td>
        </tr>
        <tr>
            <td><code>latitude</code> _(required)_</td>
            <td><code>float</code></td>
            <td>The latitude coordinate.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
point = GeometryPoint(-0.1278, 51.5074)
```

---

## `GeometryLine` {#geometryline}

A line defined by two or more points.

### Constructor {#line-constructor}

```python title="Syntax"
GeometryLine(points)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>points</code> _(required)_</td>
            <td><code>list[GeometryPoint]</code></td>
            <td>An ordered list of points that define the line.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
line = GeometryLine([
    GeometryPoint(-0.1278, 51.5074),
    GeometryPoint(-3.1883, 55.9533),
])
```

---

## `GeometryPolygon` {#geometrypolygon}

A polygon defined by one or more linear rings. The first ring is the exterior boundary; any subsequent rings are interior holes. Rings must be closed - the first and last point must be identical, following the GeoJSON specification.

### Constructor {#polygon-constructor}

```python title="Syntax"
GeometryPolygon(rings)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>rings</code> _(required)_</td>
            <td><code>list[GeometryLine]</code></td>
            <td>A list of linear rings. The first is the exterior ring; others are holes.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
polygon = GeometryPolygon([
    GeometryLine([
        GeometryPoint(0.0, 0.0),
        GeometryPoint(1.0, 0.0),
        GeometryPoint(1.0, 1.0),
        GeometryPoint(0.0, 1.0),
        GeometryPoint(0.0, 0.0),
    ]),
])
```

---

## `GeometryMultiPoint` {#geometrymultipoint}

A collection of points.

### Constructor {#multipoint-constructor}

```python title="Syntax"
GeometryMultiPoint(points)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>points</code> _(required)_</td>
            <td><code>list[GeometryPoint]</code></td>
            <td>A list of points.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
multi_point = GeometryMultiPoint([
    GeometryPoint(-0.1278, 51.5074),
    GeometryPoint(-3.1883, 55.9533),
    GeometryPoint(-1.8904, 52.4862),
])
```

---

## `GeometryMultiLine` {#geometrymultiline}

A collection of lines.

### Constructor {#multiline-constructor}

```python title="Syntax"
GeometryMultiLine(lines)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>lines</code> _(required)_</td>
            <td><code>list[GeometryLine]</code></td>
            <td>A list of lines.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
multi_line = GeometryMultiLine([
    GeometryLine([
        GeometryPoint(0.0, 0.0),
        GeometryPoint(1.0, 1.0),
    ]),
    GeometryLine([
        GeometryPoint(2.0, 2.0),
        GeometryPoint(3.0, 3.0),
    ]),
])
```

---

## `GeometryMultiPolygon` {#geometrymultipolygon}

A collection of polygons.

### Constructor {#multipolygon-constructor}

```python title="Syntax"
GeometryMultiPolygon(polygons)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>polygons</code> _(required)_</td>
            <td><code>list[GeometryPolygon]</code></td>
            <td>A list of polygons.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
multi_polygon = GeometryMultiPolygon([
    GeometryPolygon([
        GeometryLine([
            GeometryPoint(0.0, 0.0),
            GeometryPoint(1.0, 0.0),
            GeometryPoint(1.0, 1.0),
            GeometryPoint(0.0, 1.0),
            GeometryPoint(0.0, 0.0),
        ]),
    ]),
])
```

---

## `GeometryCollection` {#geometrycollection}

A heterogeneous collection of geometry objects. Unlike the other multi-types, a `GeometryCollection` can contain a mix of different geometry types.

### Constructor {#collection-constructor}

```python title="Syntax"
GeometryCollection(geometries)
```

<table>
    <thead>
        <tr>
            <th>Parameter</th>
            <th>Type</th>
            <th>Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><code>geometries</code> _(required)_</td>
            <td><code>list[Geometry]</code></td>
            <td>A list of geometry objects of any type.</td>
        </tr>
    </tbody>
</table>

### Examples

```python
collection = GeometryCollection([
    GeometryPoint(-0.1278, 51.5074),
    GeometryLine([
        GeometryPoint(0.0, 0.0),
        GeometryPoint(1.0, 1.0),
    ]),
])
```

---

## Usage {#usage}

```python
from surrealdb import Surreal, GeometryPoint

with Surreal("ws://localhost:8000") as db:
    db.use("my_ns", "my_db")
    db.signin({"username": "root", "password": "secret"})

    db.create("locations", {
        "name": "London",
        "coordinates": GeometryPoint(-0.1278, 51.5074),
    })

    locations = db.query("""
        SELECT * FROM locations
        WHERE geo::distance(coordinates, $point) < 50000
    """, {
        "point": GeometryPoint(-0.1180, 51.5099),
    }).first()
```

---

## See also

- [Data types](/docs/reference/python/api/values.md) - All SDK data types
- [RecordID](/docs/reference/python/api/values/record-id.md) - Record identifier
- [SurrealQL Geometry Functions](/docs/reference/query-language/functions/database-functions/geo.md) - Geospatial query functions
