|
@@ -115,10 +115,11 @@ import grass.script as grass
|
|
def cleanup():
|
|
def cleanup():
|
|
"""Delete temporary direction map."""
|
|
"""Delete temporary direction map."""
|
|
if tmp_maps:
|
|
if tmp_maps:
|
|
- try:
|
|
|
|
- grass.run_command("g.remove", flags='f', quiet=True, type='raster', name=tmp_maps)
|
|
|
|
- except:
|
|
|
|
- pass
|
|
|
|
|
|
+ try:
|
|
|
|
+ grass.run_command("g.remove", flags='f', quiet=True, type='raster', name=tmp_maps)
|
|
|
|
+ except:
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
|
|
def main():
|
|
def main():
|
|
valmap = options['input']
|
|
valmap = options['input']
|
|
@@ -131,15 +132,14 @@ def main():
|
|
global tmp_maps
|
|
global tmp_maps
|
|
tmp_maps = False
|
|
tmp_maps = False
|
|
atexit.register(cleanup)
|
|
atexit.register(cleanup)
|
|
-
|
|
|
|
|
|
+
|
|
if not dirmap:
|
|
if not dirmap:
|
|
- # get directions with r.fill.dir, without sink filling
|
|
|
|
- dirmap = "%s_tmp_%d" % (valmap, os.getpid())
|
|
|
|
- fill_map = "%s_fill_%d" % (valmap, os.getpid())
|
|
|
|
- area_map = "%s_area_%d" % (valmap, os.getpid())
|
|
|
|
- tmp_maps = dirmap + ',' + fill_map + ',' + area_map
|
|
|
|
- print tmp_maps
|
|
|
|
- grass.run_command("r.fill.dir", input=valmap, output=fill_map, direction=dirmap, areas=area_map, flags='f', format='grass');
|
|
|
|
|
|
+ # get directions with r.fill.dir, without sink filling
|
|
|
|
+ dirmap = "%s_tmp_%d" % (valmap, os.getpid())
|
|
|
|
+ fill_map = "%s_fill_%d" % (valmap, os.getpid())
|
|
|
|
+ area_map = "%s_area_%d" % (valmap, os.getpid())
|
|
|
|
+ tmp_maps = dirmap + ',' + fill_map + ',' + area_map
|
|
|
|
+ grass.run_command("r.fill.dir", input=valmap, output=fill_map, direction=dirmap, areas=area_map, flags='f', format='grass')
|
|
|
|
|
|
# create args for r.path
|
|
# create args for r.path
|
|
kwargs = {}
|
|
kwargs = {}
|
|
@@ -147,24 +147,23 @@ def main():
|
|
kwargs['values'] = valmap
|
|
kwargs['values'] = valmap
|
|
kwargs['format'] = 'degree'
|
|
kwargs['format'] = 'degree'
|
|
if start_coords:
|
|
if start_coords:
|
|
- kwargs['start_coordinates'] = start_coords
|
|
|
|
|
|
+ kwargs['start_coordinates'] = start_coords
|
|
if start_pnts:
|
|
if start_pnts:
|
|
- kwargs['start_points'] = start_pnts
|
|
|
|
|
|
+ kwargs['start_points'] = start_pnts
|
|
if rpathmap:
|
|
if rpathmap:
|
|
- kwargs['raster_path'] = rpathmap
|
|
|
|
|
|
+ kwargs['raster_path'] = rpathmap
|
|
if vpathmap:
|
|
if vpathmap:
|
|
- kwargs['vector_path'] = vpathmap
|
|
|
|
|
|
+ kwargs['vector_path'] = vpathmap
|
|
|
|
|
|
pathflags = ''
|
|
pathflags = ''
|
|
if flags['c']:
|
|
if flags['c']:
|
|
- pathflags += 'c'
|
|
|
|
|
|
+ pathflags += 'c'
|
|
if flags['a']:
|
|
if flags['a']:
|
|
- pathflags += 'a'
|
|
|
|
|
|
+ pathflags += 'a'
|
|
if flags['n']:
|
|
if flags['n']:
|
|
- pathflags += 'n'
|
|
|
|
|
|
+ pathflags += 'n'
|
|
|
|
|
|
grass.run_command("r.path", flags=pathflags, **kwargs)
|
|
grass.run_command("r.path", flags=pathflags, **kwargs)
|
|
-
|
|
|
|
|
|
|
|
return 0
|
|
return 0
|
|
|
|
|