[GRASS-SVN] r56478 - grass-addons/grass7/raster/r.fidimo

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 29 07:25:56 PDT 2013


Author: jradinger
Date: 2013-05-29 07:25:56 -0700 (Wed, 29 May 2013)
New Revision: 56478

Modified:
   grass-addons/grass7/raster/r.fidimo/r.fidimo.py
Log:
Changed distance raster (pseudo elevation map) to a buffered distance raster.
This is then input to r.watershed. Should solve the problem with small river segments.

Modified: grass-addons/grass7/raster/r.fidimo/r.fidimo.py
===================================================================
--- grass-addons/grass7/raster/r.fidimo/r.fidimo.py	2013-05-29 14:21:04 UTC (rev 56477)
+++ grass-addons/grass7/raster/r.fidimo/r.fidimo.py	2013-05-29 14:25:56 UTC (rev 56478)
@@ -49,10 +49,6 @@
 #% description: Column name indicating passability value (0-1) of barrier
 #% guisection: Stream parameters
 #%End
-#%Flag
-#% key: s
-#% description: Remove small river segments
-#%end
 #%option
 #% key: n_source
 #% type: string
@@ -415,39 +411,31 @@
 					  input = "river_raster_tmp_%d" % os.getpid(),
 					  output = "distance_raster_tmp_%d" % os.getpid(),
 					  start_coordinates = coors)
+
+	largest_cost_value = grass.raster_info("distance_raster_tmp_%d" % os.getpid())['max']
+	n_buffer_cells = 3
+
+	grass.run_command("r.buffer",
+					overwrite=True,
+					input="distance_raster_tmp_%d" % os.getpid(),
+					output="buffered_river_tmp_%d" % os.getpid(),
+					distances=n_buffer_cells*res)
+
+	grass.mapcalc("$distance_raster_buffered_tmp = if($buffered_river_tmp==2,$largest_cost_value*2,$distance_raster_tmp)",
+					distance_raster_buffered_tmp = "distance_raster_buffered_tmp_%d" % os.getpid(),
+					buffered_river_tmp = "buffered_river_tmp_%d" % os.getpid(),
+					largest_cost_value = "largest_cost_value_%d" % os.getpid(),
+					distance_raster_tmp = "distance_raster_tmp_%d" % os.getpid())
+
 	grass.run_command("r.watershed", #??? Set flag "s" for single flow ???
 					  flags = 'm', #depends on memory!! #
-					  elevation = "distance_raster_tmp_%d" % os.getpid(),
+					  elevation = "distance_raster_buffered_tmp_%d" % os.getpid(),
 					  drainage = "flow_direction_tmp_%d" % os.getpid(),
 					  stream = "stream_rwatershed_tmp_%d" % os.getpid(),
-					  threshold = "1",
+					  threshold = n_buffer_cells,
 					  overwrite = True)
 
-
-
-	#!!!! Here Problem when 1 cell river segments is in mainstem: gap in the middle of the river!
-	# Maybe solve with flag to choose either leave or remove small river sections!
-	#Removing small (1 cell) river segments and re-calculate distance raster and flow direction
-	# Why is there a problem with 1 cell river segments?
-	if flags['s']:
-		grass.mapcalc("$river_raster = if($stream_rwatershed>=0, $river_raster, null())",
-					 	 river_raster = "river_raster_tmp_%d" % os.getpid(),
-						 stream_rwatershed = "stream_rwatershed_tmp_%d" % os.getpid())
-		grass.run_command("r.cost",
-					  	flags = 'n',
-					  	overwrite = True,
-					  	input = "river_raster_tmp_%d" % os.getpid(),
-					  	output = "distance_raster_tmp_%d" % os.getpid(),
-					  	start_coordinates = coors)
-		grass.run_command("r.watershed",
-					  	flags = 'm', #depends on memory!! # !!! 
-					  	elevation = "distance_raster_tmp_%d" % os.getpid(),
-					  	drainage = "flow_direction_tmp_%d" % os.getpid(),
-					  	overwrite = True)
 	
-
-
-	
 	#Calculation of stream order (Shreve/Strahler)
 	grass.run_command("r.stream.order",
 					  streams = "stream_rwatershed_tmp_%d" % os.getpid(),



More information about the grass-commit mailing list