-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtpoint.py
More file actions
2291 lines (1853 loc) · 74.1 KB
/
tpoint.py
File metadata and controls
2291 lines (1853 loc) · 74.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import annotations
from abc import ABC
from typing import (
Optional,
List,
TYPE_CHECKING,
Set,
Tuple,
Union,
TypeVar,
Type,
overload,
)
import shapely.geometry as shp
import shapely.geometry.base as shpb
from pymeos_cffi import *
from .tbool import TBool
from .tfloat import TFloat, TFloatInst, TFloatSeq, TFloatSeqSet
from ..collections import *
from ..mixins import TSimplifiable
from ..temporal import Temporal, TInstant, TSequence, TSequenceSet, TInterpolation
if TYPE_CHECKING:
from ..boxes import STBox, Box
from geopandas import GeoDataFrame
def import_geopandas():
try:
import geopandas as gpd
return gpd
except ImportError:
print("Geopandas not found. Please install geopandas to use this function.")
raise
TG = TypeVar("TG", bound="TPoint")
TI = TypeVar("TI", bound="TPointInst")
TS = TypeVar("TS", bound="TPointSeq")
TSS = TypeVar("TSS", bound="TPointSeqSet")
Self = TypeVar("Self", bound="TPoint")
TF = TypeVar("TF", bound="TFloat", covariant=True)
class TPoint(Temporal[shp.Point, TG, TI, TS, TSS], TSimplifiable, ABC):
"""
Abstract class for temporal points.
"""
_projection_cache: dict[tuple[int, int], "LWPROJ"] = {}
# ------------------------- Constructors ----------------------------------
def __init__(self, _inner) -> None:
super().__init__()
@classmethod
def from_hexwkb(cls: Type[Self], hexwkb: str, srid: Optional[int] = None) -> Self:
result = super().from_hexwkb(hexwkb)
return result.set_srid(srid) if srid is not None else result
# ------------------------- Output ----------------------------------------
def __str__(self):
"""
Returns the string representation of the temporal point.
Returns:
A new :class:`str` representing the temporal point.
MEOS Functions:
tpoint_out
"""
return tpoint_as_text(self._inner, 15)
def as_wkt(self, precision: int = 15) -> str:
"""
Returns the temporal point as a WKT string.
Args:
precision: The precision of the returned geometry.
Returns:
A new :class:`str` representing the temporal point.
MEOS Functions:
tpoint_out
"""
return tpoint_as_text(self._inner, precision)
def as_ewkt(self, precision: int = 15) -> str:
"""
Returns the temporal point as an EWKT string.
Args:
precision: The precision of the returned geometry.
Returns:
A new :class:`str` representing the temporal point .
MEOS Functions:
tpoint_as_ewkt
"""
return tpoint_as_ewkt(self._inner, precision)
def as_geojson(
self, option: int = 1, precision: int = 15, srs: Optional[str] = None
) -> str:
"""
Returns the trajectory of the temporal point as a GeoJSON string.
Args:
option: The option to use when serializing the trajectory.
precision: The precision of the returned geometry.
srs: The spatial reference system of the returned geometry.
Returns:
A new GeoJSON string representing the trajectory of the temporal point.
MEOS Functions:
gserialized_as_geojson
"""
return geo_as_geojson(tpoint_trajectory(self._inner), option, precision, srs)
def to_shapely_geometry(self, precision: int = 15) -> shpb.BaseGeometry:
"""
Returns the trajectory of the temporal point as a Shapely geometry.
Args:
precision: The precision of the returned geometry.
Returns:
A new :class:`~shapely.geometry.base.BaseGeometry` representing the
trajectory.
MEOS Functions:
gserialized_to_shapely_geometry
"""
return gserialized_to_shapely_geometry(
tpoint_trajectory(self._inner), precision
)
# ------------------------- Accessors -------------------------------------
def bounding_box(self) -> STBox:
"""
Returns the bounding box of the `self`.
Returns:
An :class:`~pymeos.boxes.STBox` representing the bounding box.
MEOS Functions:
tpoint_to_stbox
"""
from ..boxes import STBox
return STBox(_inner=tpoint_to_stbox(self._inner))
def values(self, precision: int = 15) -> List[shp.Point]:
"""
Returns the values of the temporal point.
Returns:
A :class:`list` of :class:`~shapely.geometry.Point` with the values.
MEOS Functions:
temporal_instants
"""
return [i.value(precision=precision) for i in self.instants()]
def start_value(self, precision: int = 15) -> shp.Point:
"""
Returns the start value of the temporal point.
Returns:
A :class:`~shapely.geometry.Point` with the start value.
MEOS Functions:
tpoint_start_value
"""
return gserialized_to_shapely_point(tpoint_start_value(self._inner), precision)
def end_value(self, precision: int = 15) -> shp.Point:
"""
Returns the end value of the temporal point.
Returns:
A :class:`~shapely.geometry.Point` with the end value.
MEOS Functions:
tpoint_end_value
"""
return gserialized_to_shapely_point(tpoint_end_value(self._inner), precision)
def value_set(self, precision: int = 15) -> Set[shp.Point]:
"""
Returns the set of values of `self`.
Note that when the interpolation is linear, the set will contain only the waypoints.
Returns:
A :class:`set` of :class:`~shapely.geometry.Point` with the values.
MEOS Functions:
tpoint_values
"""
values, count = tpoint_values(self._inner)
return {
gserialized_to_shapely_point(values[i], precision) for i in range(count)
}
def value_at_timestamp(self, timestamp: datetime, precision: int = 15) -> shp.Point:
"""
Returns the value of the temporal point at the given timestamp.
Args:
timestamp: A :class:`datetime` representing the timestamp.
precision: An :class:`int` representing the precision of the coordinates.
Returns:
A :class:`~shapely.geometry.Point` with the value.
MEOS Functions:
tpoint_value_at_timestamp
"""
return gserialized_to_shapely_point(
tpoint_value_at_timestamptz(
self._inner, datetime_to_timestamptz(timestamp), True
)[0],
precision,
)
def length(self) -> float:
"""
Returns the length of the trajectory.
Returns:
A :class:`float` with the length of the trajectory.
MEOS Functions:
tpoint_length
"""
return tpoint_length(self._inner)
def cumulative_length(self) -> TFloat:
"""
Returns the cumulative length of the trajectory.
Returns:
A :class:`TFloat` with the cumulative length of the trajectory.
MEOS Functions:
tpoint_cumulative_length
"""
result = tpoint_cumulative_length(self._inner)
return Temporal._factory(result)
def speed(self) -> TFloat:
"""
Returns the speed of the temporal point.
Returns:
A :class:`TFloat` with the speed of the temporal point.
MEOS Functions:
tpoint_speed
"""
result = tpoint_speed(self._inner)
return Temporal._factory(result)
def x(self) -> TF:
"""
Returns the x coordinate of the temporal point.
Returns:
A :class:`TFloat` with the x coordinate of the temporal point.
MEOS Functions:
tpoint_get_x
"""
result = tpoint_get_x(self._inner)
return Temporal._factory(result)
def y(self) -> TF:
"""
Returns the y coordinate of the temporal point.
Returns:
A :class:`TFloat` with the y coordinate of the temporal point.
MEOS Functions:
tpoint_get_y
"""
result = tpoint_get_y(self._inner)
return Temporal._factory(result)
def z(self) -> TF:
"""
Returns the z coordinate of the temporal point.
Returns:
A :class:`TFloat` with the z coordinate of the temporal point.
MEOS Functions:
tpoint_get_z
"""
result = tpoint_get_z(self._inner)
return Temporal._factory(result)
def has_z(self) -> bool:
"""
Returns whether the temporal point has a z coordinate.
Returns:
A :class:`bool` indicating whether the temporal point has a z coordinate.
MEOS Functions:
tpoint_start_value
"""
return self.bounding_box().has_z()
def stboxes(self) -> List[STBox]:
"""
Returns a collection of :class:`STBox`es representing the bounding boxes of the segments of the temporal point.
Returns:
A :class:`list` of :class:`STBox`es.
MEOS Functions:
tpoint_stboxes
"""
from ..boxes import STBox
result, count = tpoint_stboxes(self._inner)
return [STBox(_inner=result + i) for i in range(count)]
def is_simple(self) -> bool:
"""
Returns whether the temporal point is simple. That is, whether it does not self-intersect.
Returns:
A :class:`bool` indicating whether the temporal point is simple.
MEOS Functions:
tpoint_is_simple
"""
return tpoint_is_simple(self._inner)
def bearing(self, other: Union[shpb.BaseGeometry, TPoint]) -> TFloat:
"""
Returns the temporal bearing between the temporal point and `other`.
Args:
other: An object to check the bearing to.
Returns:
A new :class:`TFloat` indicating the temporal bearing between the temporal point and `other`.
MEOS Functions:
bearing_tpoint_point, bearing_tpoint_tpoint
"""
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = bearing_tpoint_point(self._inner, gs, False)
elif isinstance(other, TPoint):
result = bearing_tpoint_tpoint(self._inner, other._inner)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return Temporal._factory(result)
def direction(self) -> float:
"""
Returns the azimuth of the temporal point between the start and end locations.
Returns:
A new :class:`TFloatSeqSet` indicating the direction of the temporal point.
MEOS Functions:
tpoint_direction
"""
return tpoint_direction(self._inner)
def azimuth(self) -> TFloatSeqSet:
"""
Returns the temporal azimuth of the temporal point.
Returns:
A new :class:`TFloatSeqSet` indicating the temporal azimuth of the temporal point.
MEOS Functions:
tpoint_azimuth
"""
result = tpoint_azimuth(self._inner)
return Temporal._factory(result)
def angular_difference(self) -> TFloatSeqSet:
"""
Returns the angular_difference of the temporal point.
Returns:
A new :class:`TFloatSeqSet` indicating the temporal angular_difference of the temporal point.
MEOS Functions:
tpoint_angular_difference
"""
result = tpoint_angular_difference(self._inner)
return Temporal._factory(result)
def time_weighted_centroid(self, precision: int = 15) -> shp.Point:
"""
Returns the time weighted centroid of the temporal point.
Args:
precision: The precision of the returned geometry.
Returns:
A new :class:`~shapely.geometry.base.BaseGeometry` indicating the time weighted centroid of the temporal point.
MEOS Functions:
tpoint_twcentroid
"""
return gserialized_to_shapely_geometry(tpoint_twcentroid(self._inner), precision) # type: ignore
# ------------------------- Spatial Reference System ----------------------
def srid(self) -> int:
"""
Returns the SRID.
Returns:
An :class:`int` representing the SRID.
MEOS Functions:
tpoint_srid
"""
return tpoint_srid(self._inner)
def set_srid(self: Self, srid: int) -> Self:
"""
Returns a new TPoint with the given SRID.
"""
return self.__class__(_inner=tpoint_set_srid(self._inner, srid))
# ------------------------- Transformations -------------------------------
def round(self, max_decimals: int = 0) -> TPoint:
"""
Round the coordinate values to a number of decimal places.
Returns:
A new :class:`TGeomPoint` object.
MEOS Functions:
tpoint_round
"""
result = tpoint_round(self._inner, max_decimals)
return Temporal._factory(result)
def make_simple(self) -> List[TPoint]:
"""
Split the temporal point into a collection of simple temporal points.
Returns:
A :class:`list` of :class:`TPoint`es.
MEOS Functions:
tpoint_make_simple
"""
result, count = tpoint_make_simple(self._inner)
return [Temporal._factory(result[i]) for i in range(count)]
def expand(self, other: Union[int, float]) -> STBox:
"""
Expands ``self`` with `other`.
The result is equal to ``self`` but with the spatial dimensions
expanded by `other` in all directions.
Args:
other: The object to expand ``self`` with.
Returns:
A new :class:`STBox` instance.
MEOS Functions:
tpoint_expand_space
"""
from ..boxes import STBox
result = tpoint_expand_space(self._inner, float(other))
return STBox(_inner=result)
def transform(self: Self, srid: int) -> Self:
"""
Returns a new :class:`TPoint` of the same subclass of ``self`` transformed to another SRID
Args:
srid: The desired SRID
Returns:
A new :class:`TPoint` instance
MEOS Functions:
tpoint_transform
"""
srids = (self.srid(), srid)
if srids not in self._projection_cache:
self._projection_cache[srids] = lwproj_transform(*srids)
result = tpoint_transform_pj(self._inner, srid, self._projection_cache[srids])
return Temporal._factory(result)
# ------------------------- Restrictions ----------------------------------
def at(self, other: Union[shpb.BaseGeometry, GeoSet, STBox, Time]) -> TG:
"""
Returns a new temporal object with the values of `self` restricted to `other`.
Args:
other: An object to restrict the values of `self` to.
Returns:
A new :TPoint: with the values of `self` restricted to `other`.
MEOS Functions:
tpoint_at_value, tpoint_at_stbox, temporal_at_values,
temporal_at_timestamp, temporal_at_tstzset, temporal_at_tstzspan, temporal_at_tstzspanset
"""
from ..boxes import STBox
if isinstance(other, shp.Point):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tpoint_at_value(self._inner, gs)
elif isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tpoint_at_geom_time(self._inner, gs, None, None)
elif isinstance(other, GeoSet):
result = temporal_at_values(self._inner, other._inner)
elif isinstance(other, STBox):
result = tpoint_at_stbox(self._inner, other._inner, True)
else:
return super().at(other)
return Temporal._factory(result)
def minus(self, other: Union[shpb.BaseGeometry, GeoSet, STBox, Time]) -> TG:
"""
Returns a new temporal object with the values of `self` restricted to the complement of `other`.
Args:
other: An object to restrict the values of `self` to the complement of.
Returns:
A new :TPoint: with the values of `self` restricted to the complement of `other`.
MEOS Functions:
tpoint_minus_value, tpoint_minus_stbox, temporal_minus_values,
temporal_minus_timestamp, temporal_minus_tstzset, temporal_minus_tstzspan, temporal_minus_tstzspanset
"""
from ..boxes import STBox
if isinstance(other, shp.Point):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tpoint_minus_value(self._inner, gs)
elif isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tpoint_minus_geom_time(self._inner, gs, None, None)
elif isinstance(other, GeoSet):
result = temporal_minus_values(self._inner, other._inner)
elif isinstance(other, STBox):
result = tpoint_minus_stbox(self._inner, other._inner, True)
else:
return super().minus(other)
return Temporal._factory(result)
# ------------------------- Position Operations ---------------------------
def is_left(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is left to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if left, False otherwise.
See Also:
:meth:`TsTzSpan.is_before`
"""
return self.bounding_box().is_left(other)
def is_over_or_left(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is over or left to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if over or left, False otherwise.
See Also:
:meth:`TsTzSpan.is_over_or_before`
"""
return self.bounding_box().is_over_or_left(other)
def is_right(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is right to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if right, False otherwise.
See Also:
:meth:`TsTzSpan.is_after`
"""
return self.bounding_box().is_right(other)
def is_over_or_right(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is over or right to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if over or right, False otherwise.
See Also:
:meth:`TsTzSpan.is_over_or_before`
"""
return self.bounding_box().is_over_or_right(other)
def is_below(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is below to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if below, False otherwise.
See Also:
:meth:`TsTzSpan.is_before`
"""
return self.bounding_box().is_below(other)
def is_over_or_below(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is over or below to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if over or below, False otherwise.
See Also:
:meth:`TsTzSpan.is_over_or_before`
"""
return self.bounding_box().is_over_or_below(other)
def is_above(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is above to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if above, False otherwise.
See Also:
:meth:`TsTzSpan.is_after`
"""
return self.bounding_box().is_above(other)
def is_over_or_above(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is over or above to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if over or above, False otherwise.
See Also:
:meth:`TsTzSpan.is_over_or_before`
"""
return self.bounding_box().is_over_or_above(other)
def is_front(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is front to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if front, False otherwise.
See Also:
:meth:`TsTzSpan.is_before`
"""
return self.bounding_box().is_front(other)
def is_over_or_front(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is over or front to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if over or front, False otherwise.
See Also:
:meth:`TsTzSpan.is_over_or_before`
"""
return self.bounding_box().is_over_or_front(other)
def is_behind(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is behind to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if behind, False otherwise.
See Also:
:meth:`TsTzSpan.is_after`
"""
return self.bounding_box().is_behind(other)
def is_over_or_behind(self, other: Union[Temporal, Box]) -> bool:
"""
Returns whether the bounding box of `self` is over or behind to the bounding box of `other`.
Args:
other: A box or a temporal object to compare to `self`.
Returns:
True if over or behind, False otherwise.
See Also:
:meth:`TsTzSpan.is_over_or_before`
"""
return self.bounding_box().is_over_or_behind(other)
# ------------------------- Ever Spatial Relationships --------------------
def is_ever_contained_in(self, container: Union[shpb.BaseGeometry, STBox]) -> bool:
"""
Returns whether the temporal point is ever contained by `container`.
Args:
container: An object to check for containing `self`.
Returns:
A :class:`bool` indicating whether the temporal point is ever contained by `container`.
MEOS Functions:
econtains_geo_tpoint
"""
from ..boxes import STBox
if isinstance(container, shpb.BaseGeometry):
gs = geo_to_gserialized(container, isinstance(self, TGeogPoint))
result = econtains_geo_tpoint(gs, self._inner)
elif isinstance(container, STBox):
result = econtains_geo_tpoint(stbox_to_geo(container._inner), self._inner)
else:
raise TypeError(f"Operation not supported with type {container.__class__}")
return result == 1
def is_ever_disjoint(self, other: TPoint) -> bool:
"""
Returns whether the temporal point is ever disjoint from `other`.
Args:
other: An object to check for disjointness with.
Returns:
A :class:`bool` indicating whether the temporal point is ever disjoint from `other`.
MEOS Functions:
edisjoint_tpoint_geo, edisjoint_tpoint_tpoint
"""
if isinstance(other, TPoint):
result = edisjoint_tpoint_tpoint(self._inner, other._inner)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return result == 1
def is_ever_within_distance(
self, other: Union[shpb.BaseGeometry, TPoint, STBox], distance: float
) -> bool:
"""
Returns whether the temporal point is ever within `distance` of `other`.
Args:
other: An object to check the distance to.
distance: The distance to check in units of the spatial reference system.
Returns:
A :class:`bool` indicating whether the temporal point is ever within `distance` of `other`.
MEOS Functions:
edwithin_tpoint_geo, edwithin_tpoint_tpoint
"""
from ..boxes import STBox
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = edwithin_tpoint_geo(self._inner, gs, distance)
elif isinstance(other, STBox):
result = edwithin_tpoint_geo(
self._inner, stbox_to_geo(other._inner), distance
)
elif isinstance(other, TPoint):
result = edwithin_tpoint_tpoint(self._inner, other._inner, distance)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return result == 1
def ever_intersects(self, other: Union[shpb.BaseGeometry, TPoint, STBox]) -> bool:
"""
Returns whether the temporal point ever intersects `other`.
Args:
other: An object to check for intersection with.
Returns:
A :class:`bool` indicating whether the temporal point ever intersects `other`.
MEOS Functions:
eintersects_tpoint_geo, eintersects_tpoint_tpoint
"""
from ..boxes import STBox
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = eintersects_tpoint_geo(self._inner, gs)
elif isinstance(other, STBox):
result = eintersects_tpoint_geo(self._inner, stbox_to_geo(other._inner))
elif isinstance(other, TPoint):
result = eintersects_tpoint_tpoint(self._inner, other._inner)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return result == 1
def ever_touches(self, other: Union[shpb.BaseGeometry, STBox]) -> bool:
"""
Returns whether the temporal point ever touches `other`.
Args:
other: An object to check for touching with.
Returns:
A :class:`bool` indicating whether the temporal point ever touches `other`.
MEOS Functions:
etouches_tpoint_geo
"""
from ..boxes import STBox
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = etouches_tpoint_geo(self._inner, gs)
elif isinstance(other, STBox):
result = etouches_tpoint_geo(self._inner, stbox_to_geo(other._inner))
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return result == 1
# ------------------------- Temporal Spatial Relationships ----------------
def is_spatially_contained_in(
self, container: Union[shpb.BaseGeometry, STBox]
) -> TBool:
"""
Returns a new temporal boolean indicating whether the temporal point is contained by `container`.
Args:
container: An object to check for containing `self`.
Returns:
A new :TBool: indicating whether the temporal point is contained by `container`.
MEOS Functions:
tcontains_geo_tpoint
"""
from ..boxes import STBox
if isinstance(container, shpb.BaseGeometry):
gs = geo_to_gserialized(container, isinstance(self, TGeogPoint))
result = tcontains_geo_tpoint(gs, self._inner, False, False)
elif isinstance(container, STBox):
gs = stbox_to_geo(container._inner)
result = tcontains_geo_tpoint(gs, self._inner, False, False)
else:
raise TypeError(f"Operation not supported with type {container.__class__}")
return Temporal._factory(result)
def disjoint(self, other: Union[shpb.BaseGeometry, STBox]) -> TBool:
"""
Returns a new temporal boolean indicating whether the temporal point intersects `other`.
Args:
other: An object to check for intersection with.
Returns:
A new :TBool: indicating whether the temporal point intersects `other`.
MEOS Functions:
tintersects_tpoint_geo
"""
from ..boxes import STBox
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tdisjoint_tpoint_geo(self._inner, gs, False, False)
elif isinstance(other, STBox):
result = tdisjoint_tpoint_geo(
self._inner, stbox_to_geo(other._inner), False, False
)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return Temporal._factory(result)
def within_distance(
self, other: Union[shpb.BaseGeometry, TPoint, STBox], distance: float
) -> TBool:
"""
Returns a new temporal boolean indicating whether the temporal point is within `distance` of `other`.
Args:
other: An object to check the distance to.
distance: The distance to check in units of the spatial reference system.
Returns:
A new :TBool: indicating whether the temporal point is within `distance` of `other`.
MEOS Functions:
tdwithin_tpoint_geo, tdwithin_tpoint_tpoint
"""
from ..boxes import STBox
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tdwithin_tpoint_geo(self._inner, gs, distance, False, False)
elif isinstance(other, STBox):
result = tdwithin_tpoint_geo(
self._inner, stbox_to_geo(other._inner), distance, False, False
)
elif isinstance(other, TPoint):
result = tdwithin_tpoint_tpoint(
self._inner, other._inner, distance, False, False
)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return Temporal._factory(result)
def intersects(self, other: Union[shpb.BaseGeometry, STBox]) -> TBool:
"""
Returns a new temporal boolean indicating whether the temporal point intersects `other`.
Args:
other: An object to check for intersection with.
Returns:
A new :TBool: indicating whether the temporal point intersects `other`.
MEOS Functions:
tintersects_tpoint_geo
"""
from ..boxes import STBox
if isinstance(other, shpb.BaseGeometry):
gs = geo_to_gserialized(other, isinstance(self, TGeogPoint))
result = tintersects_tpoint_geo(self._inner, gs, False, False)
elif isinstance(other, STBox):
result = tintersects_tpoint_geo(
self._inner, stbox_to_geo(other._inner), False, False
)
else:
raise TypeError(f"Operation not supported with type {other.__class__}")
return Temporal._factory(result)
def touches(self, other: Union[shpb.BaseGeometry, STBox]) -> TBool:
"""
Returns a new temporal boolean indicating whether the temporal point touches `other`.
Args:
other: An object to check for touching with.
Returns:
A new :TBool: indicating whether the temporal point touches `other`.