Skip to content

MultiLineString

Bases: Spatial

Represents a list of lines.

Follows the GeoJSON specification (RFC 7946).

Parameters:

Name Type Description Default
value List[List[Tuple[float, float]]]

A multilinestring.

required

Examples:

Create a single line.

>>> MultiLineString([[(0,0), (0,1), (1,1), (0,0)]])

Create 3 lines.

>>> MultiLineString(
...     [
...         [(0,0), (0,1), (1,1)],
...         [(0.1, 0.1), (0.1, 0.2), (0.2, 0.2)],
...         [(0.6, 0.6), (0.6, 0.7), (0.7, 0.7)],
...     ]
... )
Source code in valor/schemas/symbolic/types.py
class MultiLineString(Spatial):
    """
    Represents a list of lines.

    Follows the GeoJSON specification (RFC 7946).

    Parameters
    ----------
    value : List[List[Tuple[float, float]]], optional
        A multilinestring.

    Examples
    --------
    Create a single line.
    >>> MultiLineString([[(0,0), (0,1), (1,1), (0,0)]])

    Create 3 lines.
    >>> MultiLineString(
    ...     [
    ...         [(0,0), (0,1), (1,1)],
    ...         [(0.1, 0.1), (0.1, 0.2), (0.2, 0.2)],
    ...         [(0.6, 0.6), (0.6, 0.7), (0.7, 0.7)],
    ...     ]
    ... )
    """

    def __init__(
        self,
        value: typing.List[typing.List[typing.Tuple[float, float]]],
    ):
        super().__init__(value=value)

    @classmethod
    def __validate__(cls, value: typing.Any):
        if not isinstance(value, list):
            raise TypeError(
                f"Expected type 'List[List[Tuple[float, float]]]' received type '{type(value).__name__}'"
            )
        for line in value:
            LineString.__validate__(line)

    @classmethod
    def decode_value(
        cls,
        value: typing.Optional[typing.List[typing.List[typing.List[float]]]],
    ):
        """Decode object from JSON compatible dictionary."""
        if value is None:
            return None
        return cls(
            [[(point[0], point[1]) for point in line] for line in value]
        )

Functions

valor.schemas.MultiLineString.decode_value(value) classmethod

Decode object from JSON compatible dictionary.

Source code in valor/schemas/symbolic/types.py
@classmethod
def decode_value(
    cls,
    value: typing.Optional[typing.List[typing.List[typing.List[float]]]],
):
    """Decode object from JSON compatible dictionary."""
    if value is None:
        return None
    return cls(
        [[(point[0], point[1]) for point in line] for line in value]
    )