En raison du déménagement des baies serveurs, les services gitlab.irstea.fr et mattermost.irstea.fr seront interrompus le samedi 2 octobre 2021 au matin. Ils devraient revenir à la normale dans la journée.

Unverified Commit 4ad6c679 authored by Julien Veyssier's avatar Julien Veyssier
Browse files

one more pipe in step2


Signed-off-by: default avatarJulien Veyssier <eneiluj@posteo.net>
parent 03034438
......@@ -20,6 +20,7 @@ try:
except Exception as e:
import configparser as ConfigParser
import grass.script as grass
from grass.script.utils import decode, encode
import struct, math, csv, shutil
from osgeo import gdal
......@@ -504,19 +505,20 @@ def main(parms_file, nbProc, generator=False):
grass.run_command('r.mapcalc', expression='basins=basins+1', overwrite='True', stdout=DEVNULL, stderr=DEVNULL)
print('---------- HRU-delin Step 2 : Reclassifying the watersheds')
recl_watersheds_file = os.path.join(directory_out, 'reclass_watersheds_rules')
with open(recl_watersheds_file, 'w') as rules_ws:
ds = ogr.Open(gauges_reloc_file)
reloc_lyr = ds.GetLayer()
for gauge in reloc_lyr:
geom = gauge.GetGeometryRef()
gauge_x, gauge_y = geom.GetX(), geom.GetY()
out = grass.read_command('r.what', map=basins, coordinates='%s,%s' % (gauge_x, gauge_y), stdout=DEVNULL, stderr=DEVNULL).decode('utf-8')
cat_grass = out.split('|')[3].strip('\n')
rules_ws.write(cat_grass.strip() + ':' + cat_grass.strip() + ':' + str(int(gauge.GetField(col_name))) + '\n')
################
basins_rcl = 'basins_rcl'
grass.run_command('r.recode', input=basins, output=basins_rcl, overwrite='True', rules=recl_watersheds_file, stdout=DEVNULL, stderr=DEVNULL)
pRecode = grass.feed_command('r.recode', input=basins, output=basins_rcl, overwrite='True', rules='-', quiet=True)
ds = ogr.Open(gauges_reloc_file)
reloc_lyr = ds.GetLayer()
for gauge in reloc_lyr:
geom = gauge.GetGeometryRef()
gauge_x, gauge_y = geom.GetX(), geom.GetY()
out = decode(grass.read_command('r.what', map=basins, coordinates='%s,%s' % (gauge_x, gauge_y)))
cat_grass = out.rstrip(os.linesep).split('|')[3].strip()
pRecode.stdin.write(encode('%s:%s:%s\n' % (cat_grass, cat_grass, int(gauge.GetField(col_name)))))
pRecode.stdin.close()
pRecode.wait()
grass.run_command('r.out.gdal',
input=basins_rcl,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment