Table of Contents

Class Snapping

Namespace
SpatialNET
Assembly
SpatialNET.Extensions.dll

Snapping to a target (ADR 0046): SnapTo moves the vertices of a geometry that lie within a tolerance of another geometry onto it, so that data with small errors (digitised by hand, projected, rounded) meets where it is meant to meet. The exact operations (Cut, the overlays, the predicates) stay exact; snapping is the step before them: cutter.SnapTo(polygon, 0.01).Cut(polygon).

public static class Snapping

Inheritance

Inherited Members

Remarks

A vertex of the target within the tolerance always wins over a point on an edge, so that a point does not land just beside a corner (which would leave a sliver). Among equally near candidates the first one of the target wins.

A moved point keeps its own Z and M: the target decides only where it lies. A vertex of the target that is inserted into a segment gets Z and M interpolated on that segment.

Vertices that fall together are merged, paths with fewer than two and rings with fewer than three distinct vertices are dropped (as for SpatialNET.Cleaning.SnapToGrid(SpatialNET.IGeometry2D,System.Double,SpatialNET.IGeometryFactory)). The result may be invalid (moving vertices can make edges cross); MakeValid repairs it.

The tolerance is in the units of the coordinates. A point lies on the target after snapping within the rounding of its computation (about 1e-16 relative), far below the grid of the overlays (ADR 0005), so that those see it as touching.

Methods

SnapTo(IPoint2D, IGeometry2D, double, IGeometryFactory?)

Snaps a point to the target: to the nearest vertex of the target within tolerance, otherwise to the nearest point of an edge within it. A point with nothing within the tolerance stays as it is.

public static IPoint2D SnapTo(this IPoint2D point, IGeometry2D target, double tolerance, IGeometryFactory? factory = null)

Parameters

point IPoint2D

The point.

target IGeometry2D

The geometry to snap to; any kind, a polygon by its rings.

tolerance double

The largest distance a point is moved; finite and greater than 0.

factory IGeometryFactory?

The factory; null = SpatialNET.GeometryFactory.Default.

Returns

IPoint2D

Exceptions

ArgumentNullException

An argument is null.

ArgumentOutOfRangeException

tolerance is not finite or not greater than 0.

NotSupportedException

target is not a known geometry kind.

InvalidOperationException

No factory available.

SnapTo(IMultiPoint2D, IGeometry2D, double, IGeometryFactory?)

Snaps every point of a multipoint to the target, as SpatialNET.Snapping.SnapTo(SpatialNET.IPoint2D,SpatialNET.IGeometry2D,System.Double,SpatialNET.IGeometryFactory); all points stay, also if they now coincide.

public static IMultiPoint2D SnapTo(this IMultiPoint2D multiPoint, IGeometry2D target, double tolerance, IGeometryFactory? factory = null)

Parameters

multiPoint IMultiPoint2D

The multipoint.

target IGeometry2D

The geometry to snap to.

tolerance double

The largest distance a point is moved; finite and greater than 0.

factory IGeometryFactory?

The factory; null = SpatialNET.GeometryFactory.Default.

Returns

IMultiPoint2D

Exceptions

ArgumentNullException

An argument is null.

ArgumentOutOfRangeException

tolerance is not finite or not greater than 0.

NotSupportedException

target is not a known geometry kind.

InvalidOperationException

No factory available.

SnapTo(IPolyline2D, IGeometry2D, double, SnapMode, SnapEnds, IGeometryFactory?)

Snaps a polyline to the target (ADR 0046). With SpatialNET.SnapMode.Ends (the default) only the loose ends move: an end that runs over the target by less than the tolerance (measured along the line) is cut back to where it meets it, an end short of it is moved or extended to it as ends says, and a vertex of the target within the tolerance of the end wins. With SpatialNET.SnapMode.Vertices every vertex is snapped as a point, and vertices of the target near a segment are inserted into it; ends is not used then.

public static IPolyline2D SnapTo(this IPolyline2D line, IGeometry2D target, double tolerance, SnapMode mode = SnapMode.Ends, SnapEnds ends = SnapEnds.Nearest, IGeometryFactory? factory = null)

Parameters

line IPolyline2D

The polyline.

target IGeometry2D

The geometry to snap to; any kind, a polygon by its rings.

tolerance double

The largest distance a vertex is moved; finite and greater than 0.

mode SnapMode

What is moved.

ends SnapEnds

How a loose end reaches the target (only for SpatialNET.SnapMode.Ends).

factory IGeometryFactory?

The factory; null = SpatialNET.GeometryFactory.Default.

Returns

IPolyline2D

Exceptions

ArgumentNullException

An argument is null.

ArgumentOutOfRangeException

tolerance is not finite or not greater than 0; mode or ends is not a known value.

NotSupportedException

target is not a known geometry kind.

InvalidOperationException

No factory available.

SnapTo(IPolygon2D, IGeometry2D, double, SnapMode, IGeometryFactory?)

Snaps the rings of a polygon to the target (ADR 0046), with SpatialNET.SnapMode.Vertices (the default) as for a polyline. A polygon has no loose ends, so SpatialNET.SnapMode.Ends gives a copy. The rings are normalized (shells counter-clockwise, holes clockwise); a part whose shell collapses goes with its holes.

public static IPolygon2D SnapTo(this IPolygon2D polygon, IGeometry2D target, double tolerance, SnapMode mode = SnapMode.Vertices, IGeometryFactory? factory = null)

Parameters

polygon IPolygon2D

The polygon.

target IGeometry2D

The geometry to snap to; any kind, a polygon by its rings.

tolerance double

The largest distance a vertex is moved; finite and greater than 0.

mode SnapMode

What is moved.

factory IGeometryFactory?

The factory; null = SpatialNET.GeometryFactory.Default.

Returns

IPolygon2D

Exceptions

ArgumentNullException

An argument is null.

ArgumentOutOfRangeException

tolerance is not finite or not greater than 0; mode is not a known value.

NotSupportedException

target is not a known geometry kind.

InvalidOperationException

No factory available.

SnapTo(IGeometry2D, IGeometry2D, double, SnapMode?, SnapEnds, IGeometryFactory?)

Snaps any geometry to the target, by the overloads for its kind. Without mode a polyline snaps its SpatialNET.SnapMode.Ends and a polygon its SpatialNET.SnapMode.Vertices; points snap as points.

public static IGeometry2D SnapTo(this IGeometry2D geometry, IGeometry2D target, double tolerance, SnapMode? mode = null, SnapEnds ends = SnapEnds.Nearest, IGeometryFactory? factory = null)

Parameters

geometry IGeometry2D

The geometry.

target IGeometry2D

The geometry to snap to; any kind, a polygon by its rings.

tolerance double

The largest distance a vertex is moved; finite and greater than 0.

mode SnapMode?

What is moved; null = the default of the kind.

ends SnapEnds

How a loose end reaches the target (only for a polyline with SpatialNET.SnapMode.Ends).

factory IGeometryFactory?

The factory; null = SpatialNET.GeometryFactory.Default.

Returns

IGeometry2D

Exceptions

ArgumentNullException

An argument is null.

ArgumentOutOfRangeException

tolerance is not finite or not greater than 0; mode or ends is not a known value.

NotSupportedException

geometry or target is not a known geometry kind.

InvalidOperationException

No factory available.