File: vlr.py

package info (click to toggle)
python-laspy 2.5.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,928 kB
  • sloc: python: 9,065; makefile: 20
file content (88 lines) | stat: -rw-r--r-- 2,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from abc import ABC, abstractmethod
from typing import Union


class IVLR(ABC):
    @property
    @abstractmethod
    def user_id(self) -> str:
        ...

    @property
    @abstractmethod
    def record_id(self) -> int:
        ...

    @property
    @abstractmethod
    def description(self) -> Union[str, bytes]:
        ...

    @abstractmethod
    def record_data_bytes(self) -> bytes:
        ...


class BaseVLR(IVLR, ABC):
    def __init__(self, user_id, record_id, description=""):
        self._user_id: str = user_id
        self._record_id: int = record_id
        self._description: Union[str, bytes] = description

    @property
    def user_id(self) -> str:
        """
        The user id
        """
        return self._user_id

    @property
    def record_id(self) -> int:
        """
        The record id
        """
        return self._record_id

    @property
    def description(self) -> Union[str, bytes]:
        """
        The description, cannot exceed 32 bytes
        """
        return self._description


class VLR(BaseVLR):
    """
    >>> import laspy
    >>> my_vlr = laspy.VLR(
    ... user_id="MyUserId",
    ... record_id=0,
    ... description="An Example VLR",
    ... record_data=int(42).to_bytes(8, byteorder='little'),
    ... )
    >>> my_vlr.user_id
    'MyUserId'
    >>> int.from_bytes(my_vlr.record_data, byteorder='little')
    42
    """

    def __init__(self, user_id, record_id, description="", record_data=b""):
        super().__init__(user_id, record_id, description=description)
        #: The record_data as bytes, length cannot exceed 65_535
        self.record_data: bytes = record_data

    def record_data_bytes(self) -> bytes:
        return self.record_data

    def __eq__(self, other):
        return (
            self.record_id == other.record_id
            and self.user_id == other.user_id
            and self.description == other.description
            and self.record_data == other.record_data
        )

    def __repr__(self):
        return "<{}(user_id: '{}', record_id: '{}', data len: {})>".format(
            self.__class__.__name__, self.user_id, self.record_id, len(self.record_data)
        )