Skip to content

Commit ec86f6b

Browse files
committed
Move tiling and splitting functions from TPoint to TGeomPoint, since they are not available for TGeogPoints.
1 parent c1f5f2c commit ec86f6b

1 file changed

Lines changed: 148 additions & 148 deletions

File tree

pymeos/main/tpoint.py

Lines changed: 148 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,154 +1115,6 @@ def shortest_line(
11151115
raise TypeError(f"Operation not supported with type {other.__class__}")
11161116
return gserialized_to_shapely_geometry(result, 10)
11171117

1118-
# ------------------------- Tiling Operations -----------------------------
1119-
def tile(
1120-
self,
1121-
size: float,
1122-
duration: Optional[Union[timedelta, str]] = None,
1123-
origin: Optional[shpb.BaseGeometry] = None,
1124-
start: Union[datetime, str, None] = None,
1125-
remove_empty: Optional[bool] = False,
1126-
) -> List[TG]:
1127-
"""
1128-
Split the temporal point into segments following the tiling of the
1129-
bounding box.
1130-
1131-
Args:
1132-
size: The size of the spatial tiles. If `self` has a spatial
1133-
dimension and this argument is not provided, the tiling will be
1134-
only temporal.
1135-
duration: The duration of the temporal tiles. If `self` has a time
1136-
dimension and this argument is not provided, the tiling will be
1137-
only spatial.
1138-
origin: The origin of the spatial tiling. If not provided, the
1139-
origin will be (0, 0, 0).
1140-
start: The start time of the temporal tiling. If not provided,
1141-
the start time used by default is Monday, January 3, 2000.
1142-
remove_empty: If True, remove the tiles that are empty.
1143-
1144-
Returns:
1145-
A list of :class:`TPoint` objects.
1146-
1147-
See Also:
1148-
:meth:`STBox.tile`
1149-
"""
1150-
from ..boxes import STBox
1151-
1152-
bbox = STBox.from_tpoint(self)
1153-
tiles = bbox.tile(size, duration, origin, start)
1154-
if remove_empty:
1155-
return [x for x in (self.at(tile) for tile in tiles) if x]
1156-
else:
1157-
return [self.at(tile) for tile in tiles]
1158-
1159-
# ------------------------- Split Operations ------------------------------
1160-
def space_split(
1161-
self,
1162-
xsize: float,
1163-
ysize: Optional[float] = None,
1164-
zsize: Optional[float] = None,
1165-
origin: Optional[shpb.BaseGeometry] = None,
1166-
bitmatrix: bool = False,
1167-
include_border: bool = True,
1168-
) -> List[Temporal]:
1169-
"""
1170-
Splits `self` into fragments with respect to space buckets
1171-
1172-
Args:
1173-
xsize: Size of the x dimension.
1174-
ysize: Size of the y dimension.
1175-
zsize: Size of the z dimension.
1176-
origin: The origin of the spatial tiling. If not provided, the
1177-
origin will be (0, 0, 0).
1178-
bitmatrix: If True, use a bitmatrix to speed up the process.
1179-
include_border: If True, include the upper border in the box.
1180-
1181-
Returns:
1182-
A list of temporal points.
1183-
1184-
MEOS Functions:
1185-
tpoint_value_split
1186-
"""
1187-
ysz = ysize if ysize is not None else xsize
1188-
zsz = zsize if zsize is not None else xsize
1189-
gs = (
1190-
geo_to_gserialized(origin, isinstance(self, TGeogPoint))
1191-
if origin is not None
1192-
else (
1193-
pgis_geography_in("Point(0 0 0)", -1)
1194-
if isinstance(self, TGeogPoint)
1195-
else pgis_geometry_in("Point(0 0 0)", -1)
1196-
)
1197-
)
1198-
fragments, values, count = tpoint_space_split(
1199-
self._inner, xsize, ysz, zsz, gs, bitmatrix, include_border
1200-
)
1201-
from ..factory import _TemporalFactory
1202-
1203-
return [_TemporalFactory.create_temporal(fragments[i]) for i in range(count)]
1204-
1205-
def space_time_split(
1206-
self,
1207-
xsize: float,
1208-
duration: Union[str, timedelta],
1209-
ysize: Optional[float] = None,
1210-
zsize: Optional[float] = None,
1211-
origin: Optional[shpb.BaseGeometry] = None,
1212-
time_start: Optional[Union[str, datetime]] = None,
1213-
bitmatrix: bool = False,
1214-
include_border: bool = True,
1215-
) -> List[Temporal]:
1216-
"""
1217-
Splits `self` into fragments with respect to space and tstzspan buckets.
1218-
1219-
Args:
1220-
xsize: Size of the x dimension.
1221-
ysize: Size of the y dimension.
1222-
zsize: Size of the z dimension.
1223-
duration: Duration of the tstzspan buckets.
1224-
origin: The origin of the spatial tiling. If not provided, the
1225-
origin will be (0, 0, 0).
1226-
time_start: Start time of the first tstzspan bucket. If None, the
1227-
start time used by default is Monday, January 3, 2000.
1228-
bitmatrix: If True, use a bitmatrix to speed up the process.
1229-
include_border: If True, include the upper border in the box.
1230-
1231-
Returns:
1232-
A list of temporal floats.
1233-
1234-
MEOS Functions:
1235-
tfloat_value_time_split
1236-
"""
1237-
ysz = ysize if ysize is not None else xsize
1238-
zsz = zsize if zsize is not None else xsize
1239-
dt = (
1240-
timedelta_to_interval(duration)
1241-
if isinstance(duration, timedelta)
1242-
else pg_interval_in(duration, -1)
1243-
)
1244-
gs = (
1245-
geo_to_gserialized(origin, isinstance(self, TGeogPoint))
1246-
if origin is not None
1247-
else (
1248-
pgis_geography_in("Point(0 0 0)", -1)
1249-
if isinstance(self, TGeogPoint)
1250-
else pgis_geometry_in("Point(0 0 0)", -1)
1251-
)
1252-
)
1253-
if time_start is None:
1254-
st = pg_timestamptz_in("2000-01-03", -1)
1255-
else:
1256-
st = (
1257-
datetime_to_timestamptz(time_start)
1258-
if isinstance(time_start, datetime)
1259-
else pg_timestamptz_in(time_start, -1)
1260-
)
1261-
fragments, points, times, count = tpoint_space_time_split(
1262-
self._inner, xsize, ysz, zsz, dt, gs, st, bitmatrix, include_border
1263-
)
1264-
return [Temporal._factory(fragments[i]) for i in range(count)]
1265-
12661118

12671119
class TPointInst(
12681120
TInstant[shpb.BaseGeometry, TG, TI, TS, TSS], TPoint[TG, TI, TS, TSS], ABC
@@ -1534,6 +1386,154 @@ def to_dataframe(self) -> GeoDataFrame:
15341386
}
15351387
return gpd.GeoDataFrame(data, crs=self.srid()).set_index(keys=["time"])
15361388

1389+
# ------------------------- Tiling Operations -----------------------------
1390+
def tile(
1391+
self,
1392+
size: float,
1393+
duration: Optional[Union[timedelta, str]] = None,
1394+
origin: Optional[shpb.BaseGeometry] = None,
1395+
start: Union[datetime, str, None] = None,
1396+
remove_empty: Optional[bool] = False,
1397+
) -> List[TG]:
1398+
"""
1399+
Split the temporal point into segments following the tiling of the
1400+
bounding box.
1401+
1402+
Args:
1403+
size: The size of the spatial tiles. If `self` has a spatial
1404+
dimension and this argument is not provided, the tiling will be
1405+
only temporal.
1406+
duration: The duration of the temporal tiles. If `self` has a time
1407+
dimension and this argument is not provided, the tiling will be
1408+
only spatial.
1409+
origin: The origin of the spatial tiling. If not provided, the
1410+
origin will be (0, 0, 0).
1411+
start: The start time of the temporal tiling. If not provided,
1412+
the start time used by default is Monday, January 3, 2000.
1413+
remove_empty: If True, remove the tiles that are empty.
1414+
1415+
Returns:
1416+
A list of :class:`TPoint` objects.
1417+
1418+
See Also:
1419+
:meth:`STBox.tile`
1420+
"""
1421+
from ..boxes import STBox
1422+
1423+
bbox = STBox.from_tpoint(self)
1424+
tiles = bbox.tile(size, duration, origin, start)
1425+
if remove_empty:
1426+
return [x for x in (self.at(tile) for tile in tiles) if x]
1427+
else:
1428+
return [self.at(tile) for tile in tiles]
1429+
1430+
# ------------------------- Split Operations ------------------------------
1431+
def space_split(
1432+
self,
1433+
xsize: float,
1434+
ysize: Optional[float] = None,
1435+
zsize: Optional[float] = None,
1436+
origin: Optional[shpb.BaseGeometry] = None,
1437+
bitmatrix: bool = False,
1438+
include_border: bool = True,
1439+
) -> List[Temporal]:
1440+
"""
1441+
Splits `self` into fragments with respect to space buckets
1442+
1443+
Args:
1444+
xsize: Size of the x dimension.
1445+
ysize: Size of the y dimension.
1446+
zsize: Size of the z dimension.
1447+
origin: The origin of the spatial tiling. If not provided, the
1448+
origin will be (0, 0, 0).
1449+
bitmatrix: If True, use a bitmatrix to speed up the process.
1450+
include_border: If True, include the upper border in the box.
1451+
1452+
Returns:
1453+
A list of temporal points.
1454+
1455+
MEOS Functions:
1456+
tpoint_value_split
1457+
"""
1458+
ysz = ysize if ysize is not None else xsize
1459+
zsz = zsize if zsize is not None else xsize
1460+
gs = (
1461+
geo_to_gserialized(origin, isinstance(self, TGeogPoint))
1462+
if origin is not None
1463+
else (
1464+
pgis_geography_in("Point(0 0 0)", -1)
1465+
if isinstance(self, TGeogPoint)
1466+
else pgis_geometry_in("Point(0 0 0)", -1)
1467+
)
1468+
)
1469+
fragments, values, count = tpoint_space_split(
1470+
self._inner, xsize, ysz, zsz, gs, bitmatrix, include_border
1471+
)
1472+
from ..factory import _TemporalFactory
1473+
1474+
return [_TemporalFactory.create_temporal(fragments[i]) for i in range(count)]
1475+
1476+
def space_time_split(
1477+
self,
1478+
xsize: float,
1479+
duration: Union[str, timedelta],
1480+
ysize: Optional[float] = None,
1481+
zsize: Optional[float] = None,
1482+
origin: Optional[shpb.BaseGeometry] = None,
1483+
time_start: Optional[Union[str, datetime]] = None,
1484+
bitmatrix: bool = False,
1485+
include_border: bool = True,
1486+
) -> List[Temporal]:
1487+
"""
1488+
Splits `self` into fragments with respect to space and tstzspan buckets.
1489+
1490+
Args:
1491+
xsize: Size of the x dimension.
1492+
ysize: Size of the y dimension.
1493+
zsize: Size of the z dimension.
1494+
duration: Duration of the tstzspan buckets.
1495+
origin: The origin of the spatial tiling. If not provided, the
1496+
origin will be (0, 0, 0).
1497+
time_start: Start time of the first tstzspan bucket. If None, the
1498+
start time used by default is Monday, January 3, 2000.
1499+
bitmatrix: If True, use a bitmatrix to speed up the process.
1500+
include_border: If True, include the upper border in the box.
1501+
1502+
Returns:
1503+
A list of temporal floats.
1504+
1505+
MEOS Functions:
1506+
tfloat_value_time_split
1507+
"""
1508+
ysz = ysize if ysize is not None else xsize
1509+
zsz = zsize if zsize is not None else xsize
1510+
dt = (
1511+
timedelta_to_interval(duration)
1512+
if isinstance(duration, timedelta)
1513+
else pg_interval_in(duration, -1)
1514+
)
1515+
gs = (
1516+
geo_to_gserialized(origin, isinstance(self, TGeogPoint))
1517+
if origin is not None
1518+
else (
1519+
pgis_geography_in("Point(0 0 0)", -1)
1520+
if isinstance(self, TGeogPoint)
1521+
else pgis_geometry_in("Point(0 0 0)", -1)
1522+
)
1523+
)
1524+
if time_start is None:
1525+
st = pg_timestamptz_in("2000-01-03", -1)
1526+
else:
1527+
st = (
1528+
datetime_to_timestamptz(time_start)
1529+
if isinstance(time_start, datetime)
1530+
else pg_timestamptz_in(time_start, -1)
1531+
)
1532+
fragments, points, times, count = tpoint_space_time_split(
1533+
self._inner, xsize, ysz, zsz, dt, gs, st, bitmatrix, include_border
1534+
)
1535+
return [Temporal._factory(fragments[i]) for i in range(count)]
1536+
15371537
# ------------------------- Ever and Always Comparisons -------------------
15381538
def always_equal(self, value: Union[shpb.BaseGeometry, TGeomPoint]) -> bool:
15391539
"""

0 commit comments

Comments
 (0)