Table of Contents

Class AbstractPolylineDecoder<TPolyline, TCoordinate>

Namespace
PolylineAlgorithm.Abstraction
Assembly
PolylineAlgorithm.dll

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

public abstract class AbstractPolylineDecoder<TPolyline, TCoordinate> : IPolylineDecoder<TPolyline, TCoordinate>

Type Parameters

TPolyline

The type that represents the encoded polyline input.

TCoordinate

The type that represents a decoded geographic coordinate.

Inheritance

Implements

Inherited Members

Remarks

Derive from this class to implement a decoder for a specific polyline type. Override PolylineAlgorithm.Abstraction.AbstractPolylineDecoder`2.GetReadOnlyMemory(`0@) and PolylineAlgorithm.Abstraction.AbstractPolylineDecoder`2.CreateCoordinate(System.Double,System.Double) to provide type-specific behavior.

Constructors

AbstractPolylineDecoder()

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

protected AbstractPolylineDecoder()

AbstractPolylineDecoder(PolylineEncodingOptions)

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

protected AbstractPolylineDecoder(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 decoder.

public PolylineEncodingOptions Options { get; }

Property Value

PolylineEncodingOptions

Methods

CreateCoordinate(double, double)

Creates a TCoordinate instance from the specified latitude and longitude values.

protected abstract TCoordinate CreateCoordinate(double latitude, double longitude)

Parameters

latitude double

The latitude component of the coordinate, in degrees.

longitude double

The longitude component of the coordinate, in degrees.

Returns

TCoordinate

A TCoordinate instance representing the specified geographic coordinate.

Decode(TPolyline, CancellationToken)

Decodes an encoded TPolyline into a sequence of TCoordinate instances, with support for cancellation.

public IEnumerable<TCoordinate> Decode(TPolyline polyline, CancellationToken cancellationToken = default)

Parameters

polyline TPolyline

The TPolyline instance containing the encoded polyline string to decode.

cancellationToken CancellationToken

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

Returns

IEnumerable<TCoordinate>

An IEnumerable<T> of TCoordinate representing the decoded latitude and longitude pairs.

Exceptions

ArgumentNullException

Thrown when polyline is null.

ArgumentException

Thrown when polyline is empty.

InvalidPolylineException

Thrown when the polyline format is invalid or malformed at a specific position.

OperationCanceledException

Thrown when cancellationToken is canceled during decoding.

GetReadOnlyMemory(in TPolyline)

Extracts the underlying read-only memory region of characters from the specified polyline instance.

protected abstract ReadOnlyMemory<char> GetReadOnlyMemory(in TPolyline polyline)

Parameters

polyline TPolyline

The TPolyline instance from which to extract the character sequence.

Returns

ReadOnlyMemory<char>

A ReadOnlyMemory<T> of Char representing the encoded polyline characters.

ValidateFormat(ReadOnlyMemory<char>, ILogger?)

Validates the format of the polyline character sequence, ensuring all characters are within the allowed range.

protected virtual void ValidateFormat(ReadOnlyMemory<char> sequence, ILogger? logger)

Parameters

sequence ReadOnlyMemory<char>

The read-only memory region of characters representing the polyline to validate.

logger ILogger?

An optional ILogger used to log a warning when format validation fails.

Exceptions

ArgumentException

Thrown when the polyline contains characters outside the valid encoding range or has an invalid block structure.