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
optionsPolylineEncodingOptions-
The PolylineAlgorithm.PolylineEncodingOptions to use for encoding operations.
Exceptions
- ArgumentNullException
-
Thrown when
optionsis null
Properties
Options
Gets the encoding options used by this polyline encoder.
public PolylineEncodingOptions Options { get; }Property Value
Methods
CreatePolyline(ReadOnlyMemory<char>)
Creates a polyline instance from the provided read-only sequence of characters.
protected abstract TPolyline CreatePolyline(ReadOnlyMemory<char> polyline)Parameters
polylineReadOnlyMemory<char>-
A ReadOnlyMemory<T> containing the encoded polyline characters.
Returns
- TPolyline
-
An instance of
TPolylinerepresenting 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
coordinatesReadOnlySpan<TCoordinate>-
The collection of
TCoordinateobjects to encode. cancellationTokenCancellationToken-
A CancellationToken that can be used to cancel the encoding operation.
Returns
- TPolyline
-
An instance of
TPolylinerepresenting the encoded coordinates.
Exceptions
- ArgumentNullException
-
Thrown when
coordinatesis null. - ArgumentException
-
Thrown when
coordinatesis 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
currentTCoordinate-
The coordinate from which to extract the latitude.
Returns
GetLongitude(TCoordinate)
Extracts the longitude value from the specified coordinate.
protected abstract double GetLongitude(TCoordinate current)Parameters
currentTCoordinate-
The coordinate from which to extract the longitude.