diff --git a/pymeos/main/tpoint.py b/pymeos/main/tpoint.py index 6bc22d9e..6f370f78 100644 --- a/pymeos/main/tpoint.py +++ b/pymeos/main/tpoint.py @@ -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. diff --git a/tests/main/tgeompoint_test.py b/tests/main/tgeompoint_test.py index abb38b6a..ec300e82 100644 --- a/tests/main/tgeompoint_test.py +++ b/tests/main/tgeompoint_test.py @@ -30,6 +30,7 @@ TsTzSpanSet, STBox, ) + from tests.conftest import TestPyMEOS @@ -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")