Skip to content

Commit

Permalink
v.rast.bufferstats: support for raster with categories (#481)
Browse files Browse the repository at this point in the history
* v.rast.bufferstats: added capabilities to save categories name instead number
  • Loading branch information
lucadelu committed Mar 16, 2021
1 parent 7b6c76a commit 6b1d90e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion grass7/vector/v.rast.bufferstats/v.rast.bufferstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ def main():
stats.inputs.sort = 'desc'
stats.inputs.null_value = 'null'
stats.flags.quiet = True
stats.flags.l = True
if percent:
stats.flags.p = True
stats.flags.n = True
Expand Down Expand Up @@ -595,7 +596,14 @@ def main():

area_tot = 0
for l in t_stats:
updates.append('\t{}_{}'.format(prefix, l.rstrip('%')))
# check if raster maps has category or not
if len(l.split('=')) == 2:
updates.append('\t{}_{}'.format(prefix, l.rstrip('%')))
else:
vals = l.split("=")
updates.append('\t{}_{} = {}'.format(prefix,
vals[-2].strip(),
vals[-1].strip().rstrip('%')))
if l.split('_b{} ='.format(b_str))[0].split('_')[-1] != 'null':
area_tot = area_tot + float(l.rstrip('%').split('= ')[1])
if not percent:
Expand Down

0 comments on commit 6b1d90e

Please sign in to comment.