From 85e80a19f2d59b878da121808b7480dfaf99d7cd Mon Sep 17 00:00:00 2001 From: Sophie de Virieu Date: Thu, 17 Jul 2025 11:14:13 +0200 Subject: [PATCH 1/4] add coords constructor --- pymeos/main/tpoint.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pymeos/main/tpoint.py b/pymeos/main/tpoint.py index 6bc22d9e..9a333272 100644 --- a/pymeos/main/tpoint.py +++ b/pymeos/main/tpoint.py @@ -1308,6 +1308,19 @@ 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): """ From db2acb506b7475af4dea639b675c8bc7361bcfa4 Mon Sep 17 00:00:00 2001 From: Sophie de Virieu Date: Thu, 31 Jul 2025 08:47:48 +0200 Subject: [PATCH 2/4] black formatting --- pymeos/main/tpoint.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/pymeos/main/tpoint.py b/pymeos/main/tpoint.py index 9a333272..6f370f78 100644 --- a/pymeos/main/tpoint.py +++ b/pymeos/main/tpoint.py @@ -1308,18 +1308,47 @@ 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: + 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] + 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) + tpointseq_make_coords( + x, + y, + z, + times, + len(t), + srid, + geodetic, + lower_inc, + upper_inc, + linear, + normalize, + ) ) def plot(self, *args, **kwargs): From cc23265cb98b60de75802f48547fa596e737184e Mon Sep 17 00:00:00 2001 From: Sophie de Virieu Date: Thu, 21 Aug 2025 16:42:15 +0200 Subject: [PATCH 3/4] add from_arrays test --- tests/main/tgeompoint_test.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/main/tgeompoint_test.py b/tests/main/tgeompoint_test.py index abb38b6a..09ab84e0 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") From 7df74399e66caa4e70acee4ff0b375da9e40cc67 Mon Sep 17 00:00:00 2001 From: Sophie de Virieu Date: Thu, 21 Aug 2025 17:07:26 +0200 Subject: [PATCH 4/4] black formatting --- tests/main/tgeompoint_test.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/main/tgeompoint_test.py b/tests/main/tgeompoint_test.py index 09ab84e0..ec300e82 100644 --- a/tests/main/tgeompoint_test.py +++ b/tests/main/tgeompoint_test.py @@ -331,14 +331,14 @@ def test_copy_constructor(self, temporal): 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]), + 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 + upper_inc=True, )