Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ jobs:
pip install .

- name: Test PyMEOS with pytest
env:
MEOS_IDL: ${{ github.workspace }}/PyMEOS-CFFI/builder/meos-idl.json
run: |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${{ matrix.ld_prefix }}/lib
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${{ matrix.ld_prefix }}/lib
Expand Down
108 changes: 101 additions & 7 deletions pymeos/boxes/stbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,94 @@ def from_expanding_bounding_box(
raise TypeError(f"Operation not supported with type {value.__class__}")
return STBox(_inner=stbox_expand_space(box, expansion))

@staticmethod
def from_text(text: str) -> STBox:
"""
Returns a :class:`STBox` from its text, the inverse of :meth:`as_text`.

Args:
text: The text representation.

Returns:
A new :class:`STBox` instance.

MEOS Functions:
stbox_in
"""
return STBox(string=text)

@staticmethod
def from_ewkb(ewkb: bytes) -> STBox:
"""
Returns a :class:`STBox` from its EWKB, the inverse of :meth:`as_ewkb`.

Args:
ewkb: The EWKB representation.

Returns:
A new :class:`STBox` instance.

MEOS Functions:
stbox_from_wkb
"""
return STBox(_inner=stbox_from_wkb(ewkb))

@staticmethod
def from_hexewkb(hexewkb: str) -> STBox:
"""
Returns a :class:`STBox` from its HEXEWKB, the inverse of :meth:`as_hexewkb`.

Args:
hexewkb: The HEXEWKB representation.

Returns:
A new :class:`STBox` instance.

MEOS Functions:
stbox_from_hexwkb
"""
return STBox(_inner=stbox_from_hexwkb(hexewkb))

def as_ewkb(self, endian: str = "") -> bytes:
"""
Returns the EWKB representation of ``self``, carrying its SRID.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`bytes` instance.

MEOS Functions:
stbox_as_ewkb, wkb_variant_from_endian
"""
return stbox_as_ewkb(self._inner, wkb_variant_from_endian(endian))

def as_hexewkb(self, endian: str = "") -> str:
"""
Returns the HEXEWKB representation of ``self``, carrying its SRID.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` instance.

MEOS Functions:
stbox_as_hexewkb, wkb_variant_from_endian
"""
return stbox_as_hexewkb(self._inner, wkb_variant_from_endian(endian))[0]

# ------------------------- Output ----------------------------------------
def __str__(self, max_decimals: int = 15):
def __str__(self) -> str:
"""
Returns the text representation of ``self``, its :meth:`as_text`.
"""
return self.as_text()

def as_text(self, max_decimals: int = 15) -> str:
"""
Returns a string representation of ``self``.

Expand All @@ -313,30 +399,38 @@ def __repr__(self):
"""
return f"{self.__class__.__name__}({self})"

def as_wkb(self) -> bytes:
def as_wkb(self, endian: str = "") -> bytes:
"""
Returns the WKB representation of ``self``.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self``.

MEOS Functions:
stbox_as_wkb
stbox_as_wkb, wkb_variant_from_endian
"""
return stbox_as_wkb(self._inner, 4)
return stbox_as_wkb(self._inner, wkb_variant_from_endian(endian))

def as_hexwkb(self) -> str:
def as_hexwkb(self, endian: str = "") -> str:
"""
Returns the WKB representation of ``self`` in hex-encoded ASCII.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self`` in
hex-encoded ASCII.

MEOS Functions:
stbox_as_hexwkb
stbox_as_hexwkb, wkb_variant_from_endian
"""
return stbox_as_hexwkb(self._inner, -1)[0]
return stbox_as_hexwkb(self._inner, wkb_variant_from_endian(endian))[0]

# ------------------------- Conversions ----------------------------------
def to_geometry(self, precision: int = 15) -> shp.BaseGeometry:
Expand Down
44 changes: 37 additions & 7 deletions pymeos/boxes/tbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,30 @@ def from_tnumber(temporal: TNumber) -> TBox:
"""
return TBox(_inner=tnumber_to_tbox(temporal._inner))

@staticmethod
def from_text(text: str) -> TBox:
"""
Returns a :class:`TBox` from its text, the inverse of :meth:`as_text`.

Args:
text: The text representation.

Returns:
A new :class:`TBox` instance.

MEOS Functions:
tbox_in
"""
return TBox(string=text)

# ------------------------- Output ----------------------------------------
def __str__(self, max_decimals: int = 15):
def __str__(self) -> str:
"""
Returns the text representation of ``self``, its :meth:`as_text`.
"""
return self.as_text()

def as_text(self, max_decimals: int = 15) -> str:
"""
Returns a string representation of ``self``.

Expand All @@ -262,30 +284,38 @@ def __repr__(self):
"""
return f"{self.__class__.__name__}({self})"

def as_wkb(self) -> bytes:
def as_wkb(self, endian: str = "") -> bytes:
"""
Returns the WKB representation of ``self``.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self``.

MEOS Functions:
tbox_as_wkb
tbox_as_wkb, wkb_variant_from_endian
"""
return tbox_as_wkb(self._inner, 4)
return tbox_as_wkb(self._inner, wkb_variant_from_endian(endian))

def as_hexwkb(self) -> str:
def as_hexwkb(self, endian: str = "") -> str:
"""
Returns the WKB representation of ``self`` in hex-encoded ASCII.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self`` in
hex-encoded ASCII.

MEOS Functions:
tbox_as_hexwkb
tbox_as_hexwkb, wkb_variant_from_endian
"""
return tbox_as_hexwkb(self._inner, -1)[0]
return tbox_as_hexwkb(self._inner, wkb_variant_from_endian(endian))[0]

# ------------------------- Conversions ----------------------------------
def to_floatspan(self) -> FloatSpan:
Expand Down
36 changes: 30 additions & 6 deletions pymeos/collections/base/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ def from_hexwkb(cls: type[Self], hexwkb: str) -> Self:

return _CollectionFactory.create_collection(set_from_hexwkb(hexwkb))

@classmethod
def from_text(cls: type[Self], text: str) -> Self:
"""
Returns a :class:`Set` from its text, the inverse of :meth:`as_text`.

Args:
text: The text representation.

Returns:
A new :class:`Set` instance.

MEOS Functions:
<type>_in
"""
return cls(string=text)

# ------------------------- Output ----------------------------------------
@abstractmethod
def __str__(self) -> str:
Expand All @@ -119,27 +135,35 @@ def __repr__(self) -> str:
"""
return f"{self.__class__.__name__}({self})"

def as_wkb(self) -> bytes:
def as_wkb(self, endian: str = "") -> bytes:
"""
Returns the WKB representation of ``self``.
Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self``.

MEOS Functions:
set_as_wkb
set_as_wkb, wkb_variant_from_endian
"""
return set_as_wkb(self._inner, 4)
return set_as_wkb(self._inner, wkb_variant_from_endian(endian))

def as_hexwkb(self) -> str:
def as_hexwkb(self, endian: str = "") -> str:
"""
Returns the WKB representation of ``self`` in hex-encoded ASCII.
Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self`` in hex-encoded ASCII.

MEOS Functions:
set_as_hexwkb
set_as_hexwkb, wkb_variant_from_endian
"""
return set_as_hexwkb(self._inner, -1)[0]
return set_as_hexwkb(self._inner, wkb_variant_from_endian(endian))[0]

# ------------------------- Conversions -----------------------------------
@overload
Expand Down
36 changes: 30 additions & 6 deletions pymeos/collections/base/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,22 @@ def from_hexwkb(cls: type[Self], hexwkb: str) -> Self:
result = span_from_hexwkb(hexwkb)
return cls(_inner=result)

@classmethod
def from_text(cls: type[Self], text: str) -> Self:
"""
Returns a :class:`Span` from its text, the inverse of :meth:`as_text`.

Args:
text: The text representation.

Returns:
A new :class:`Span` instance.

MEOS Functions:
<type>_in
"""
return cls(string=text)

# ------------------------- Output ----------------------------------------
@abstractmethod
def __str__(self) -> str:
Expand All @@ -116,30 +132,38 @@ def __repr__(self):
"""
return f"{self.__class__.__name__}({self})"

def as_wkb(self) -> bytes:
def as_wkb(self, endian: str = "") -> bytes:
"""
Returns the WKB representation of ``self``.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self``.

MEOS Functions:
span_as_wkb
span_as_wkb, wkb_variant_from_endian
"""
return span_as_wkb(self._inner, 4)
return span_as_wkb(self._inner, wkb_variant_from_endian(endian))

def as_hexwkb(self) -> str:
def as_hexwkb(self, endian: str = "") -> str:
"""
Returns the WKB representation of ``self`` in hex-encoded ASCII.

Args:
endian: The byte order, ``"NDR"``, ``"XDR"`` or ``""`` for the
machine's own.

Returns:
A :class:`str` object with the WKB representation of ``self`` in
hex-encoded ASCII.

MEOS Functions:
span_as_hexwkb
span_as_hexwkb, wkb_variant_from_endian
"""
return span_as_hexwkb(self._inner, -1)[0]
return span_as_hexwkb(self._inner, wkb_variant_from_endian(endian))[0]

# ------------------------- Conversions -----------------------------------
@abstractmethod
Expand Down
Loading
Loading