Table of Contents

Class AbstractPolylineEncoder<TCoordinate, TPolyline>

Namespace
PolylineAlgorithm.Abstraction
Assembly
PolylineAlgorithm.dll

Provides a base implementation for encoding sequences of geographic coordinates into encoded polyline strings.

public abstract class AbstractPolylineEncoder<TCoordinate, TPolyline> : IPolylineEncoder<TCoordinate, TPolyline>

Type Parameters

TCoordinate

The type that represents a geographic coordinate to encode.

TPolyline

The type that represents the encoded polyline output.

Inheritance

Implements

Inherited Members

Extension Methods

Remarks

Derive from this class to implement an encoder for a specific coordinate and polyline type. Override PolylineAlgorithm.Abstraction.AbstractPolylineEncoder`2.GetLatitude(`0), PolylineAlgorithm.Abstraction.AbstractPolylineEncoder`2.GetLongitude(`0), and PolylineAlgorithm.Abstraction.AbstractPolylineEncoder`2.CreatePolyline(System.ReadOnlyMemory{System.Char}) to provide type-specific behavior.

Constructors

AbstractPolylineEncoder()

Initializes a new instance of the PolylineAlgorithm.Abstraction.AbstractPolylineEncoder`2 class with default encoding options.

protected AbstractPolylineEncoder()

AbstractPolylineEncoder(PolylineEncodingOptions)

Initializes a new instance of the PolylineAlgorithm.Abstraction.AbstractPolylineEncoder`2 class with the specified encoding options.

protected AbstractPolylineEncoder(PolylineEncodingOptions options)

Parameters

options PolylineEncodingOptions

The PolylineAlgorithm.PolylineEncodingOptions to use for encoding operations.

Exceptions

ArgumentNullException

Thrown when options is null

Properties

Options

Gets the encoding options used by this polyline encoder.

public PolylineEncodingOptions Options { get; }

Property Value

PolylineEncodingOptions

Methods

CreatePolyline(ReadOnlyMemory<char>)

Creates a polyline instance from the provided read-only sequence of characters.

protected abstract TPolyline CreatePolyline(ReadOnlyMemory<char> polyline)

Parameters

polyline ReadOnlyMemory<char>

A ReadOnlyMemory<T> containing the encoded polyline characters.

Returns

TPolyline

An instance of TPolyline representing the encoded polyline.

Encode(ReadOnlySpan<TCoordinate>, CancellationToken)

Encodes a collection of TCoordinate instances into an encoded TPolyline string.

[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Method contains local methods. Actual method only 55 lines.")]
public TPolyline Encode(ReadOnlySpan<TCoordinate> coordinates, CancellationToken cancellationToken = default)

Parameters

coordinates ReadOnlySpan<TCoordinate>

The collection of TCoordinate objects to encode.

cancellationToken CancellationToken

A CancellationToken that can be used to cancel the encoding operation.

Returns

TPolyline

An instance of TPolyline representing the encoded coordinates.

Exceptions

ArgumentNullException

Thrown when coordinates is null.

ArgumentException

Thrown when coordinates is an empty enumeration.

InvalidOperationException

Thrown when the internal encoding buffer cannot accommodate the encoded value.

GetLatitude(TCoordinate)

Extracts the latitude value from the specified coordinate.

protected abstract double GetLatitude(TCoordinate current)

Parameters

current TCoordinate

The coordinate from which to extract the latitude.

Returns

double

The latitude value as a Double.

GetLongitude(TCoordinate)

Extracts the longitude value from the specified coordinate.

protected abstract double GetLongitude(TCoordinate current)

Parameters

current TCoordinate

The coordinate from which to extract the longitude.

Returns

double

The longitude value as a Double.