# STFindOffset

STFindOffset — Compute smallest perpendicular offset from supplied point to the supplied linestring.

Function Specification.

```Function [lrs].[STFindOffset] (
@p_linestring geometry,
@p_point      geometry,
@p_round_xy   int = 3,
@p_round_zm   int = 2
)
Returns float
```

Description.

Given a point near @p_linestring, this function returns the perpendicular distance from it to the closest point on @p_linestring.

Notes.

Calls [lrs].[STInterpolatePoint]

Srid of @p_linestring and @p_point must be the same.

Parameters.

```    @p_linestring (geometry) - (Multi)LineString geometry.
@p_point      (geometry) - Offset Point for which closest linestring point measure is needed.
@p_round_xy        (int) - Decimal digits of precision for XY ordinates.
@p_round_zm        (int) - Decimal digits of precision for M ordinate.
```

Result.

The function returns the perpendicular offset distance from point to nearest point on line.

TODO.

Value is negative if on left of line; positive if on right.

Example.

```select [lrs].[STFindOffset] (
geometry::STGeomFromText('LINESTRING(-4 -4 0 1, 0 0 0 5.6, 10 0 0 15.61, 10 10 0 25.4)',28355),
geometry::Point(8,8,28355),
3,2) offset_distance
union all
select [lrs].[STFindOffset] (
geometry::STGeomFromText('LINESTRING(-4 -4 0 1, 0 0 0 5.6, 10 0 0 15.61, 10 10 0 25.4)',28355),
geometry::Point(10,0,28355),
3,2)
go

offset_distance
2
0
```