diff --git a/pymeos/collections/base/spanset.py b/pymeos/collections/base/spanset.py index 81d592ce..d4ce7a45 100644 --- a/pymeos/collections/base/spanset.py +++ b/pymeos/collections/base/spanset.py @@ -211,7 +211,7 @@ def spans(self) -> List[Span]: MEOS Functions: spanset_spans """ - return spanset_spans(self._inner) + return spanset_spanarr(self._inner) def __hash__(self) -> int: """ diff --git a/pymeos/main/tpoint.py b/pymeos/main/tpoint.py index 35f98686..04e9c36a 100644 --- a/pymeos/main/tpoint.py +++ b/pymeos/main/tpoint.py @@ -331,7 +331,7 @@ def stboxes(self) -> List[STBox]: """ from ..boxes import STBox - result, count = tpoint_stboxes(self._inner) + result, count = tpoint_stboxes(self._inner, self.num_instants()) return [STBox(_inner=result + i) for i in range(count)] def is_simple(self) -> bool: @@ -1165,7 +1165,8 @@ def space_split( ysize: Optional[float] = None, zsize: Optional[float] = None, origin: Optional[shpb.BaseGeometry] = None, - bitmatrix: Optional[bool] = False, + bitmatrix: bool = False, + include_border: bool = True, ) -> List[Temporal]: """ Splits `self` into fragments with respect to space buckets @@ -1177,6 +1178,7 @@ def space_split( origin: The origin of the spatial tiling. If not provided, the origin will be (0, 0, 0). bitmatrix: If True, use a bitmatrix to speed up the process. + include_border: If True, include the upper border in the box. Returns: A list of temporal points. @@ -1196,7 +1198,7 @@ def space_split( ) ) fragments, values, count = tpoint_space_split( - self._inner, xsize, ysz, zsz, gs, bitmatrix + self._inner, xsize, ysz, zsz, gs, bitmatrix, include_border ) from ..factory import _TemporalFactory @@ -1210,7 +1212,8 @@ def space_time_split( zsize: Optional[float] = None, origin: Optional[shpb.BaseGeometry] = None, time_start: Optional[Union[str, datetime]] = None, - bitmatrix: Optional[bool] = False, + bitmatrix: bool = False, + include_border: bool = True, ) -> List[Temporal]: """ Splits `self` into fragments with respect to space and tstzspan buckets. @@ -1225,6 +1228,7 @@ def space_time_split( time_start: Start time of the first tstzspan bucket. If None, the start time used by default is Monday, January 3, 2000. bitmatrix: If True, use a bitmatrix to speed up the process. + include_border: If True, include the upper border in the box. Returns: A list of temporal floats. @@ -1257,7 +1261,7 @@ def space_time_split( else pg_timestamptz_in(time_start, -1) ) fragments, points, times, count = tpoint_space_time_split( - self._inner, xsize, ysz, zsz, dt, gs, st, bitmatrix + self._inner, xsize, ysz, zsz, dt, gs, st, bitmatrix, include_border ) return [Temporal._factory(fragments[i]) for i in range(count)] @@ -2085,7 +2089,12 @@ def __init__( p = f'POINT({" ".join(str(x) for x in point)})' else: p = f"{point}" - self._inner = tgeompoint_in(f"SRID={srid};{p}@{timestamp}") + full_str = ( + f"SRID={srid};{p}@{timestamp}" + if srid is not None + else f"{p}@{timestamp}" + ) + self._inner = tgeompoint_in(full_str) class TGeogPointInst( @@ -2112,12 +2121,16 @@ def __init__( ) -> None: super().__init__(string=string, value=point, timestamp=timestamp, _inner=_inner) if self._inner is None: - p = ( - f"POINT({point[0]} {point[1]})" - if isinstance(point, tuple) - else f"{point}" + if isinstance(point, tuple): + p = f'POINT({" ".join(str(x) for x in point)})' + else: + p = f"{point}" + full_str = ( + f"SRID={srid};{p}@{timestamp}" + if srid is not None + else f"{p}@{timestamp}" ) - self._inner = tgeogpoint_in(f"SRID={srid};{p}@{timestamp}") + self._inner = tgeogpoint_in(full_str) class TGeomPointSeq( diff --git a/pymeos/temporal/temporal.py b/pymeos/temporal/temporal.py index 6ee3b3ec..cff0ea32 100644 --- a/pymeos/temporal/temporal.py +++ b/pymeos/temporal/temporal.py @@ -573,6 +573,7 @@ def temporal_sample( self, duration: Union[str, timedelta], start: Optional[Union[str, datetime]] = None, + interpolation: Optional[TInterpolation] = None, ) -> TG: """ Returns a new :class:`Temporal` downsampled with respect to ``duration``. @@ -583,6 +584,8 @@ def temporal_sample( start: A :class:`str` or :class:`datetime` with the start time of the temporal tiles. If None, the start time used by default is Monday, January 3, 2000. + interpolation: Interpolation of the resulting temporal object. If None, + defaults to the interpolation of ``self``. MEOS Functions: temporal_tsample """ @@ -596,7 +599,11 @@ def temporal_sample( dt = timedelta_to_interval(duration) else: dt = pg_interval_in(duration, -1) - result = temporal_tsample(self._inner, dt, st) + if interpolation is None: + intrp = self.interpolation() + else: + intrp = interpolation + result = temporal_tsample(self._inner, dt, st, intrp) return Temporal._factory(result) def temporal_precision( diff --git a/tests/main/tbool_test.py b/tests/main/tbool_test.py index 908a3348..4be963aa 100644 --- a/tests/main/tbool_test.py +++ b/tests/main/tbool_test.py @@ -1109,22 +1109,21 @@ def test_shift_scale_time(self): timedelta(hours=12), TBoolSeq("{True@2019-09-01, False@2019-09-02}"), ), - (tbs, timedelta(days=4), TBoolSeq("{True@2019-09-01}")), + (tbs, timedelta(days=4), TBoolSeq("[True@2019-09-01]")), ( tbs, timedelta(hours=12), TBoolSeq( - "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02}" + "[True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02]" ), ), (tbss, timedelta(days=4), TBoolSeq("{True@2019-09-01,True@2019-09-05}")), ( tbss, timedelta(hours=12), - TBoolSeq( - "{True@2019-09-01, True@2019-09-01 12:00:00, False@2019-09-02," - "True@2019-09-03, True@2019-09-03 12:00:00, True@2019-09-04, " - "True@2019-09-04 12:00:00, True@2019-09-05}" + TBoolSeqSet( + "{[t@2019-09-01 00:00:00+00, f@2019-09-02 00:00:00+00]," + " [t@2019-09-03 00:00:00+00, t@2019-09-05 00:00:00+00]}" ), ), ], diff --git a/tests/main/tfloat_test.py b/tests/main/tfloat_test.py index bf3bc41f..3ac74bde 100644 --- a/tests/main/tfloat_test.py +++ b/tests/main/tfloat_test.py @@ -1482,20 +1482,19 @@ def test_shift_scale_time(self): (tfi, timedelta(hours=12), TFloatInst("1.5@2019-09-01")), (tfds, timedelta(days=4), TFloatSeq("{1.5@2019-09-01}")), (tfds, timedelta(hours=12), TFloatSeq("{1.5@2019-09-01, 2.5@2019-09-02}")), - (tfs, timedelta(days=4), TFloatSeq("{1.5@2019-09-01}")), + (tfs, timedelta(days=4), TFloatSeq("[1.5@2019-09-01]")), ( tfs, timedelta(hours=12), - TFloatSeq("{1.5@2019-09-01, 2@2019-09-01 12:00:00, 2.5@2019-09-02}"), + TFloatSeq("[1.5@2019-09-01, 2.5@2019-09-02]"), ), (tfss, timedelta(days=4), TFloatSeq("{1.5@2019-09-01,1.5@2019-09-05}")), ( tfss, timedelta(hours=12), - TFloatSeq( - "{1.5@2019-09-01, 2@2019-09-01 12:00:00, 2.5@2019-09-02," - "1.5@2019-09-03, 1.5@2019-09-03 12:00:00, 1.5@2019-09-04, " - "1.5@2019-09-04 12:00:00, 1.5@2019-09-05}" + TFloatSeqSet( + "{[1.5@2019-09-01 00:00:00+00, 2.5@2019-09-02 00:00:00+00], " + "[1.5@2019-09-03 00:00:00+00, 1.5@2019-09-05 00:00:00+00]}" ), ), ], diff --git a/tests/main/tgeogpoint_test.py b/tests/main/tgeogpoint_test.py index d7cadfcd..5e803f9d 100644 --- a/tests/main/tgeogpoint_test.py +++ b/tests/main/tgeogpoint_test.py @@ -1196,8 +1196,14 @@ def test_has_z(self, temporal, expected): @pytest.mark.parametrize( "temporal, expected", [ - (tpi, []), - (tpds, []), + (tpi, [STBox("GEODSTBOX XT(((1,1),(1,1)),[2019-09-01, 2019-09-01])")]), + ( + tpds, + [ + STBox("GEODSTBOX XT(((1,1),(1,1)),[2019-09-01, 2019-09-01])"), + STBox("GEODSTBOX XT(((2,2),(2,2)),[2019-09-02, 2019-09-02])"), + ], + ), (tps, [STBox("GEODSTBOX XT(((1,1),(2,2)),[2019-09-01, 2019-09-02])")]), ( tpss, @@ -1705,13 +1711,11 @@ def test_shift_scale_time(self): timedelta(hours=12), TGeogPointSeq("{Point(1 1)@2019-09-01, Point(2 2)@2019-09-02}"), ), - (tps, timedelta(days=4), TGeogPointSeq("{Point(1 1)@2019-09-01}")), + (tps, timedelta(days=4), TGeogPointSeq("[Point(1 1)@2019-09-01]")), ( tps, timedelta(hours=12), - TGeogPointSeq( - "{Point(1 1)@2019-09-01, Point(1.5 1.5)@2019-09-01 12:00:00, Point(2 2)@2019-09-02}" - ), + TGeogPointSeq("[Point(1 1)@2019-09-01, Point(2 2)@2019-09-02]"), ), ( tpss, @@ -1721,10 +1725,9 @@ def test_shift_scale_time(self): ( tpss, timedelta(hours=12), - TGeogPointSeq( - "{Point(1 1)@2019-09-01, Point(1.5 1.5)@2019-09-01 12:00:00," - "Point(2 2)@2019-09-02, Point(1 1)@2019-09-03, Point(1 1)@2019-09-03 12:00:00, " - "Point(1 1)@2019-09-04, Point(1 1)@2019-09-04 12:00:00, Point(1 1)@2019-09-05}" + TGeogPointSeqSet( + "{[POINT(1 1)@2019-09-01, POINT(2 2)@2019-09-02], " + "[POINT(1 1)@2019-09-03, POINT(1 1)@2019-09-05]}" ), ), ], @@ -2366,26 +2369,26 @@ class TestTGeogPointEverSpatialOperations(TestTGeogPoint): ) @pytest.mark.parametrize( - "temporal, expected", + "temporal", [ - (tpi, True), - (tpds, True), - (tps, True), - (tpss, True), + tpi, + tpds, + tps, + tpss, ], ids=["Instant", "Discrete Sequence", "Sequence", "SequenceSet"], ) - def test_temporal_ever_contained_withindist_intersects(self, temporal, expected): - assert temporal.is_ever_within_distance(Point(1, 1), 1) == expected - assert ( - temporal.is_ever_within_distance(TGeogPointInst("Point(1 1)@2019-09-01"), 1) - == expected - ) - assert temporal.ever_intersects(Point(1, 1)) == expected - assert ( - temporal.ever_intersects(TGeogPointInst("Point(1 1)@2019-09-01")) - == expected + def test_temporal_ever_withindist_intersects(self, temporal): + assert temporal.is_ever_within_distance(Point(1, 1), 1) + print("Hey") + assert temporal.is_ever_within_distance( + TGeogPointInst("Point(1 1)@2019-09-01"), 1 ) + print("Hey") + assert temporal.ever_intersects(Point(1, 1)) + print("Hey") + assert temporal.ever_intersects(TGeogPointInst("Point(1 1)@2019-09-01")) + print("Hey") class TestTGeogPointTemporalSpatialOperations(TestTGeogPoint): diff --git a/tests/main/tgeompoint_test.py b/tests/main/tgeompoint_test.py index 5019ceb0..abb38b6a 100644 --- a/tests/main/tgeompoint_test.py +++ b/tests/main/tgeompoint_test.py @@ -1231,8 +1231,14 @@ def test_has_z(self, temporal, expected): @pytest.mark.parametrize( "temporal, expected", [ - (tpi, []), - (tpds, []), + (tpi, [STBox("STBOX XT(((1,1),(1,1)),[2019-09-01, 2019-09-01])")]), + ( + tpds, + [ + STBox("STBOX XT(((1,1),(1,1)),[2019-09-01, 2019-09-01])"), + STBox("STBOX XT(((2,2),(2,2)),[2019-09-02, 2019-09-02])"), + ], + ), (tps, [STBox("STBOX XT(((1,1),(2,2)),[2019-09-01, 2019-09-02])")]), ( tpss, @@ -1770,13 +1776,11 @@ def test_shift_scale_time(self): timedelta(hours=12), TGeomPointSeq("{Point(1 1)@2019-09-01, Point(2 2)@2019-09-02}"), ), - (tps, timedelta(days=4), TGeomPointSeq("{Point(1 1)@2019-09-01}")), + (tps, timedelta(days=4), TGeomPointSeq("[Point(1 1)@2019-09-01]")), ( tps, timedelta(hours=12), - TGeomPointSeq( - "{Point(1 1)@2019-09-01, Point(1.5 1.5)@2019-09-01 12:00:00, Point(2 2)@2019-09-02}" - ), + TGeomPointSeq("[Point(1 1)@2019-09-01, Point(2 2)@2019-09-02]"), ), ( tpss, @@ -1786,10 +1790,9 @@ def test_shift_scale_time(self): ( tpss, timedelta(hours=12), - TGeomPointSeq( - "{Point(1 1)@2019-09-01, Point(1.5 1.5)@2019-09-01 12:00:00," - "Point(2 2)@2019-09-02, Point(1 1)@2019-09-03, Point(1 1)@2019-09-03 12:00:00, " - "Point(1 1)@2019-09-04, Point(1 1)@2019-09-04 12:00:00, Point(1 1)@2019-09-05}" + TGeomPointSeqSet( + "{[POINT(1 1)@2019-09-01 00:00:00+00, POINT(2 2)@2019-09-02 00:00:00+00], " + "[POINT(1 1)@2019-09-03 00:00:00+00, POINT(1 1)@2019-09-05 00:00:00+00]}" ), ), ], diff --git a/tests/main/tint_test.py b/tests/main/tint_test.py index bf1cc6b5..03158221 100644 --- a/tests/main/tint_test.py +++ b/tests/main/tint_test.py @@ -1321,20 +1321,19 @@ def test_shift_scale_time(self): (tii, timedelta(hours=12), TIntInst("1@2019-09-01")), (tids, timedelta(days=4), TIntSeq("{1@2019-09-01}")), (tids, timedelta(hours=12), TIntSeq("{1@2019-09-01, 2@2019-09-02}")), - (tis, timedelta(days=4), TIntSeq("{1@2019-09-01}")), + (tis, timedelta(days=4), TIntSeq("[1@2019-09-01]")), ( tis, timedelta(hours=12), - TIntSeq("{1@2019-09-01, 1@2019-09-01 12:00:00, 2@2019-09-02}"), + TIntSeq("[1@2019-09-01, 2@2019-09-02]"), ), (tiss, timedelta(days=4), TIntSeq("{1@2019-09-01,1@2019-09-05}")), ( tiss, timedelta(hours=12), TIntSeq( - "{1@2019-09-01, 1@2019-09-01 12:00:00, 2@2019-09-02," - "1@2019-09-03, 1@2019-09-03 12:00:00, 1@2019-09-04, " - "1@2019-09-04 12:00:00, 1@2019-09-05}" + "{[1@2019-09-01 00:00:00+00, 2@2019-09-02 00:00:00+00], " + "[1@2019-09-03 00:00:00+00, 1@2019-09-05 00:00:00+00]}" ), ), ], diff --git a/tests/main/ttext_test.py b/tests/main/ttext_test.py index f41bc756..c3900997 100644 --- a/tests/main/ttext_test.py +++ b/tests/main/ttext_test.py @@ -1123,20 +1123,19 @@ def test_shift_scale(self): (tti, timedelta(hours=12), TTextInst("AAA@2019-09-01")), (ttds, timedelta(days=4), TTextSeq("{AAA@2019-09-01}")), (ttds, timedelta(hours=12), TTextSeq("{AAA@2019-09-01, BBB@2019-09-02}")), - (tts, timedelta(days=4), TTextSeq("{AAA@2019-09-01}")), + (tts, timedelta(days=4), TTextSeq("[AAA@2019-09-01]")), ( tts, timedelta(hours=12), - TTextSeq("{AAA@2019-09-01, AAA@2019-09-01 12:00:00, BBB@2019-09-02}"), + TTextSeq("[AAA@2019-09-01, BBB@2019-09-02]"), ), (ttss, timedelta(days=4), TTextSeq("{AAA@2019-09-01,AAA@2019-09-05}")), ( ttss, timedelta(hours=12), TTextSeq( - "{AAA@2019-09-01, AAA@2019-09-01 12:00:00, BBB@2019-09-02," - "AAA@2019-09-03, AAA@2019-09-03 12:00:00, AAA@2019-09-04, " - "AAA@2019-09-04 12:00:00, AAA@2019-09-05}" + "{[AAA@2019-09-01 00:00:00+00, BBB@2019-09-02 00:00:00+00], " + "[AAA@2019-09-03 00:00:00+00, AAA@2019-09-05 00:00:00+00]}" ), ), ],