Skip to content

Commit

Permalink
Merge pull request #62 from Diviloper/meos-sync
Browse files Browse the repository at this point in the history
Sync with MEOS and fix bugs
  • Loading branch information
Diviloper authored Jul 30, 2024
2 parents 5b8eb7c + c495d26 commit 4b1a2c5
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 70 deletions.
2 changes: 1 addition & 1 deletion pymeos/collections/base/spanset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
35 changes: 24 additions & 11 deletions pymeos/main/tpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)]

Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion pymeos/temporal/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand All @@ -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
"""
Expand All @@ -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(
Expand Down
11 changes: 5 additions & 6 deletions tests/main/tbool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
),
),
],
Expand Down
11 changes: 5 additions & 6 deletions tests/main/tfloat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
),
),
],
Expand Down
53 changes: 28 additions & 25 deletions tests/main/tgeogpoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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]}"
),
),
],
Expand Down Expand Up @@ -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):
Expand Down
23 changes: 13 additions & 10 deletions tests/main/tgeompoint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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]}"
),
),
],
Expand Down
9 changes: 4 additions & 5 deletions tests/main/tint_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
),
),
],
Expand Down
9 changes: 4 additions & 5 deletions tests/main/ttext_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]}"
),
),
],
Expand Down

0 comments on commit 4b1a2c5

Please sign in to comment.