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
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 decoder.
public PolylineEncodingOptions Options { get; }Property Value
Methods
CreateCoordinate(double, double)
Creates a TCoordinate instance from the specified latitude and longitude values.
protected abstract TCoordinate CreateCoordinate(double latitude, double longitude)Parameters
latitudedouble-
The latitude component of the coordinate, in degrees.
longitudedouble-
The longitude component of the coordinate, in degrees.
Returns
- TCoordinate
-
A
TCoordinateinstance 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
polylineTPolyline-
The
TPolylineinstance containing the encoded polyline string to decode. cancellationTokenCancellationToken-
A CancellationToken that can be used to cancel the decoding operation.
Returns
- IEnumerable<TCoordinate>
-
An IEnumerable<T> of
TCoordinaterepresenting the decoded latitude and longitude pairs.
Exceptions
- ArgumentNullException
-
Thrown when
polylineis null. - ArgumentException
-
Thrown when
polylineis empty. - InvalidPolylineException
-
Thrown when the polyline format is invalid or malformed at a specific position.
- OperationCanceledException
-
Thrown when
cancellationTokenis 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
polylineTPolyline-
The
TPolylineinstance 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
sequenceReadOnlyMemory<char>-
The read-only memory region of characters representing the polyline to validate.
loggerILogger?-
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.