Skip to content

Commit 57968d6

Browse files
ninsblsaket0187petrasovaa
authored
t.rast.list: allow method gran with where option (#7678)
* enable where with method gran * enable where with method gran, set '' to None for gran * add gran-where test, move to tools --------- Co-authored-by: SAKET KUMAR MALL <72020337+saket0187@users.noreply.github.com> Co-authored-by: Anna Petrasova <kratochanna@gmail.com>
1 parent e50e16c commit 57968d6

4 files changed

Lines changed: 127 additions & 113 deletions

File tree

python/grass/temporal/abstract_space_time_dataset.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,9 @@ def sample_by_dataset_sql(
11041104

11051105
return obj_list
11061106

1107-
def get_registered_maps_as_objects_by_granularity(self, gran=None, dbif=None):
1107+
def get_registered_maps_as_objects_by_granularity(
1108+
self, gran: str | None = None, where: str | None = None, dbif=None
1109+
):
11081110
"""Return all registered maps as ordered (by start_time) object list
11091111
with "gap" map objects (id==None) for spatio-temporal topological
11101112
operations that require the temporal extent only.
@@ -1143,6 +1145,8 @@ def get_registered_maps_as_objects_by_granularity(self, gran=None, dbif=None):
11431145
weeks, month, months, year, years". The unit of the
11441146
relative time granule is always the space time dataset
11451147
unit and can not be changed.
1148+
:param where: The SQL where statement to select a subset of
1149+
the registered maps without "WHERE"
11461150
:param dbif: The database interface to be used
11471151
11481152
:return: ordered list of map lists. Each list represents a single
@@ -1158,16 +1162,19 @@ def get_registered_maps_as_objects_by_granularity(self, gran=None, dbif=None):
11581162
if not check:
11591163
self.msgr.fatal(_('Wrong granularity: "%s"') % str(gran))
11601164

1161-
start, end = self.get_temporal_extent_as_tuple()
1165+
maps = self.get_registered_maps_as_objects(
1166+
dbif=dbif, order="start_time", where=where
1167+
)
11621168

1163-
if start is None or end is None:
1169+
if not maps:
11641170
return None
11651171

1166-
maps = self.get_registered_maps_as_objects(dbif=dbif, order="start_time")
1172+
start = maps[0].get_temporal_extent_as_tuple()[0]
1173+
end_extend = maps[-1].get_temporal_extent_as_tuple()
1174+
end = end_extend[1] if end_extend[1] is not None else end_extend[0]
11671175

1168-
if not maps:
1176+
if start is None or end is None:
11691177
return None
1170-
11711178
# We need to adjust the end time in case the dataset has no
11721179
# interval time, so we can catch time instances at the end
11731180
if self.get_map_time() != "interval":

python/grass/temporal/list_stds.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,12 @@ def _get_get_registered_maps_as_objects_with_method(dataset, where, method, gran
279279
return dataset.get_registered_maps_as_objects(
280280
where=where, order="start_time", dbif=dbif
281281
)
282-
if method != "gran":
283-
msg = f"Invalid method '{method}'"
284-
raise ValueError(msg)
285-
if where:
286-
msg = f"The where parameter is not supported with method={method}"
287-
raise ValueError(msg)
288-
if gran is not None and gran != "":
282+
if method == "gran":
289283
return dataset.get_registered_maps_as_objects_by_granularity(
290-
gran=gran, dbif=dbif
284+
gran=gran, where=where, dbif=dbif
291285
)
292-
return dataset.get_registered_maps_as_objects_by_granularity(dbif=dbif)
286+
msg = f"Invalid method '{method}'"
287+
raise ValueError(msg)
293288

294289

295290
def _get_get_registered_maps_as_objects_delta_gran(
@@ -511,6 +506,8 @@ def list_maps_of_stds(
511506
dataset is used
512507
:param outpath: The path to file where to save output
513508
"""
509+
if gran == "":
510+
gran = None
514511
if not output_format:
515512
if method == "comma":
516513
output_format = "line"

temporal/t.rast.list/t.rast.list.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,6 @@ def main():
272272
).format(name=column, method=method),
273273
)
274274
)
275-
if method == "gran" and where:
276-
gs.fatal(
277-
message_option_value_excludes_option(
278-
option_name="method",
279-
option_value=method,
280-
excluded_option_name="where",
281-
reason=_("All maps are always listed"),
282-
)
283-
)
284275

285276
# Make sure the temporal database exists
286277
tgis.init()

0 commit comments

Comments
 (0)