Skip to content

Commit

Permalink
t.rast.neighbors: transfer semantic label (#2218)
Browse files Browse the repository at this point in the history
* t.rast.neighbors: add option to transfer semantic labels, update manual
  • Loading branch information
metzm committed Feb 20, 2022
1 parent 05e5df2 commit aa92643
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions temporal/t.rast.neighbors/t.rast.neighbors.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ <h2>DESCRIPTION</h2>
processing using a SQL WHERE statement. The number of CPU's to be used
for parallel processing can be specified with the <em>nprocs</em>
option to speedup the computation on multi-core system.
<p>
Semantic labels are needed to relate output raster maps to input raster
maps. E.g. with <em>method=stddev</em>, the user needs to know the
spatial extent, the time stamp and the semantic label to determine
which stddev map corresponds to which input map.

<h2>EXAMPLE</h2>

Expand Down
22 changes: 22 additions & 0 deletions temporal/t.rast.neighbors/t.rast.neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
# % multiple: no
# %end

# %option
# % key: semantic_labels
# % type: string
# % options: input,method
# % description: Set semantic labels
# % descriptions: input;copy semantic labels from input to output;method;append method name to input label if existing, otherwise use method name
# % answer: input
# % required: no
# % multiple: no
# %end

# %option
# % key: nprocs
# % type: integer
Expand Down Expand Up @@ -120,6 +131,7 @@ def main():
method = options["method"]
nprocs = options["nprocs"]
time_suffix = options["suffix"]
new_labels = options["semantic_labels"]

# Make sure the temporal database exists
tgis.init()
Expand Down Expand Up @@ -187,6 +199,16 @@ def main():
overwrite=overwrite,
dbif=dbif,
)
semantic_label = map.metadata.get_semantic_label()
if new_labels == "input":
if semantic_label is not None:
new_map.set_semantic_label(semantic_label)
elif new_labels == "method":
if semantic_label is not None:
semantic_label = f"{semantic_label}_{method}"
else:
semantic_label = method
new_map.set_semantic_label(semantic_label)
new_maps.append(new_map)

mod = copy.deepcopy(neighbor_module)
Expand Down

0 comments on commit aa92643

Please sign in to comment.