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

# GeoSeries.snap

> Snap the vertices and segments of the geometry to vertices of the reference.

Snap the vertices and segments of the geometry to vertices of the reference.

Vertices and segments of the input geometry are snapped to vertices of the
reference geometry, returning a new geometry; the input geometries are not
modified. The result geometry is the input geometry with the vertices and
segments snapped. If no snapping occurs then the input geometry is returned
unchanged. The tolerance is used to control where snapping is performed.

Where possible, this operation tries to avoid creating invalid geometries;
however, it does not guarantee that output geometries will be valid. It is
the responsibility of the caller to check for and handle invalid geometries.

Because too much snapping can result in invalid geometries being created,
heuristics are used to determine the number and location of snapped
vertices that are likely safe to snap. These heuristics may omit
some potential snaps that are otherwise within the tolerance.

Note: Sedona's result may differ slightly from geopandas's snap() result
because of small differences between the underlying engines being used.

The operation works in a 1-to-1 row-wise manner:

## Signature

```python theme={"system"}
snap(other, tolerance, align=None) -> GeoSeries
```

## Parameters

<ParamField path="other" type="GeoSeries or geometric object" required>
  The Geoseries (elementwise) or geometric object to snap to.
</ParamField>

<ParamField path="tolerance" type="float or array like" required>
  Maximum distance between vertices that shall be snapped
</ParamField>

<ParamField path="align" type="bool | None (default None)" default="None">
  If True, automatically aligns GeoSeries based on their indices. None defaults to True.
  If False, the order of elements is preserved.
</ParamField>

## Returns

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

## Examples

```python theme={"system"}
>>> from sedona.spark.geopandas import GeoSeries
>>> from shapely import Polygon, LineString, Point
>>> s = GeoSeries(
...     [
...         Point(0.5, 2.5),
...         LineString([(0.1, 0.1), (0.49, 0.51), (1.01, 0.89)]),
...         Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]),
...     ],
... )
>>> s
0                               POINT (0.5 2.5)
1    LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)
2       POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))
dtype: geometry
```

```python theme={"system"}
>>> s2 = GeoSeries(
...     [
...         Point(0, 2),
...         LineString([(0, 0), (0.5, 0.5), (1.0, 1.0)]),
...         Point(8, 10),
...     ],
...     index=range(1, 4),
... )
>>> s2
1                       POINT (0 2)
2    LINESTRING (0 0, 0.5 0.5, 1 1)
3                      POINT (8 10)
dtype: geometry
```

We can snap each geometry to a single shapely geometry:

```python theme={"system"}
>>> s.snap(Point(0, 2), tolerance=1)
0                                     POINT (0 2)
1      LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)
2    POLYGON ((0 0, 0 2, 0 10, 10 10, 10 0, 0 0))
dtype: geometry
```

We can also snap two GeoSeries to each other, row by row.
The GeoSeries above have different indices. We can either align both GeoSeries
based on index values and snap elements with the same index using
`align=True` or ignore index and snap elements based on their matching
order using `align=False`:

```python theme={"system"}
>>> s.snap(s2, tolerance=1, align=True)
0                                                 None
1           LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)
2    POLYGON ((0.5 0.5, 1 1, 0 10, 10 10, 10 0, 0.5...
3                                                 None
dtype: geometry
```

```python theme={"system"}
>>> s.snap(s2, tolerance=1, align=False)
0                                      POINT (0 2)
1                   LINESTRING (0 0, 0.5 0.5, 1 1)
2    POLYGON ((0 0, 0 10, 8 10, 10 10, 10 0, 0 0))
dtype: geometry
```


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