Skip to content
Open
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
42 changes: 42 additions & 0 deletions pymeos/main/tpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,6 +1309,48 @@ def y(self) -> TFloatSeq:
def z(self) -> TFloatSeq:
return super().z()

@staticmethod
def from_arrays(
t: List[Union[datetime, str]],
x: List[float],
y: List[float],
z: Optional[List[float]] = None,
srid: int = 0,
geodetic: bool = False,
lower_inc: bool = True,
upper_inc: bool = False,
linear: bool = True,
normalize: bool = True,
) -> TPointSeq:

from ..factory import _TemporalFactory

assert len(t) == len(x) == len(y)
times = [
(
datetime_to_timestamptz(ti)
if isinstance(ti, datetime)
else pg_timestamptz_in(ti, -1)
)
for ti in t
]

return _TemporalFactory.create_temporal(
tpointseq_make_coords(
x,
y,
z,
times,
len(t),
srid,
geodetic,
lower_inc,
upper_inc,
linear,
normalize,
)
)

def plot(self, *args, **kwargs):
"""
Plots the temporal point sequence.
Expand Down
13 changes: 13 additions & 0 deletions tests/main/tgeompoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
TsTzSpanSet,
STBox,
)

from tests.conftest import TestPyMEOS


Expand Down Expand Up @@ -328,6 +329,18 @@ def test_copy_constructor(self, temporal):
assert temporal == other
assert temporal is not other

def test_from_arrays_constructor(self):
tg = TGeomPointSeq.from_arrays(
t=["2019-09-01", "2019-09-02", "2019-09-03"],
x=np.array([0.1, 0.2, 0.3]),
y=np.array([1, 2, 3]),
upper_inc=True,
)
assert tg == TGeomPointSeq(
"{POINT(0.1 1)@2019-09-01 00:00:00+00, POINT(0.2 2)@2019-09-02 00:00:00+00, POINT(0.3 3)@2019-09-03 00:00:00+00}",
upper_inc=True,
)


class TestTGeomPointOutputs(TestTGeomPoint):
tpi = TGeomPointInst("Point(1 1)@2019-09-01")
Expand Down
Loading