[GRASS-SVN] r72709 - grass-addons/grass7/raster/r.lfp

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 14 20:39:14 PDT 2018


Author: hcho
Date: 2018-05-14 20:39:14 -0700 (Mon, 14 May 2018)
New Revision: 72709

Modified:
   grass-addons/grass7/raster/r.lfp/r.lfp.html
   grass-addons/grass7/raster/r.lfp/r.lfp.py
Log:
Use r.path for correct tracing; Output vector map (deprecating v.lfp)

Modified: grass-addons/grass7/raster/r.lfp/r.lfp.html
===================================================================
--- grass-addons/grass7/raster/r.lfp/r.lfp.html	2018-05-15 02:04:36 UTC (rev 72708)
+++ grass-addons/grass7/raster/r.lfp/r.lfp.html	2018-05-15 03:39:14 UTC (rev 72709)
@@ -1,11 +1,11 @@
 <h2>DESCRIPTION</h2>
 <em>r.lfp</em> calculates the longest flow path for a given outlet point and
-creates a new raster map with a thin line representing the longest flow path.
+creates a new vector map with the longest flow path.
 This module requires the <em>r.stream.distance</em> addon.
 
 <h2>NOTES</h2>
 
-<em>r.lfp</em> creates a longest flow path raster map using a drainage
+<em>r.lfp</em> creates a longest flow path vector map using a drainage
 direction raster map and the coordinates of an outlet point. The module
 internally runs <em>r.stream.distance</em> twice to calculate flow length
 downstream and upstream raster maps, and combines them to get the longest flow
@@ -35,7 +35,6 @@
 <h2>SEE ALSO</h2>
 
 <em>
-<a href="v.lfp.html">v.lfp</a>,
 <a href="r.watershed.html">r.watershed</a>,
 <a href="r.stream.extract.html">r.stream.extract</a>,
 <a href="r.stream.distance.html">r.stream.distance</a>

Modified: grass-addons/grass7/raster/r.lfp/r.lfp.py
===================================================================
--- grass-addons/grass7/raster/r.lfp/r.lfp.py	2018-05-15 02:04:36 UTC (rev 72708)
+++ grass-addons/grass7/raster/r.lfp/r.lfp.py	2018-05-15 03:39:14 UTC (rev 72709)
@@ -21,8 +21,8 @@
 #%option G_OPT_R_INPUT
 #% description: Name of input drainage direction raster map
 #%end
-#%option G_OPT_R_OUTPUT
-#% description: Name for output longest flow path raster map
+#%option G_OPT_V_OUTPUT
+#% description: Name for output longest flow path vector map
 #%end
 #%option G_OPT_M_COORDS
 #% description: Coordinates of outlet point
@@ -124,25 +124,46 @@
     except CalledModuleError:
         grass.fatal(_("Cannot create the longest flow path raster map"))
 
-    # thin the longest flow path raster map
+    # find the headwater cells
+    heads = prefix + "heads"
     try:
-        grass.run_command("r.thin", input=lfp, output=output)
+        grass.run_command("r.mapcalc", overwrite=True,
+                          expression="%s=if(!isnull(%s)&&%s>=%f,1,null())" % (heads, lfp, flds, min))
     except CalledModuleError:
-        grass.fatal(_("Cannot thin the longest flow path raster map"))
+        grass.fatal(_("Cannot find the headwater cells"))
 
+    # create the headwater vector map
+    try:
+        grass.run_command("r.to.vect", overwrite=True,
+                          input=heads, output=heads, type="point")
+    except CalledModuleError:
+        grass.fatal(_("Cannot create the headwater vector map"))
+
+    # calculate the longest flow path in vector format
+    try:
+        grass.run_command("r.path", input=input, vector_path=output, start_points=heads)
+    except CalledModuleError:
+        grass.fatal(_("Cannot create the longest flow path vector map"))
+
     # remove intermediate outputs
     grass.run_command("g.remove", flags="f", type="raster,vector",
                       pattern="%s*" % prefix)
 
-    # write metadata
-    tmphist = grass.tempfile()
-    f = open(tmphist, "w+")
-    f.write(os.environ["CMDLINE"])
-    f.close()
+    # write history if supported
+    version = grass.version()
+    if version["revision"] != "exported":
+        # the revision number is available
+        version = int(version["revision"][1:])
+    else:
+        # some binary distributions don't build from the SVN repository and
+        # revision is not available; use the libgis revision as a fallback in
+        # this case
+        version = int(version["libgis_revision"])
 
-    grass.run_command("r.support", map=output, title="Longest flow path",
-                      loadhistory=tmphist, description="generated by r.lfp")
-    grass.try_remove(tmphist)
+    if version >= 70740:
+        # v.support -h added in r70740
+        grass.run_command("v.support", flags="h", map=output,
+                          cmdhist=os.environ["CMDLINE"])
 
 
 if __name__ == "__main__":



More information about the grass-commit mailing list