[GRASS-SVN] r61929 - in grass/trunk/scripts: . v.to.lines

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Sep 13 17:16:07 PDT 2014


Author: lucadelu
Date: 2014-09-13 17:16:07 -0700 (Sat, 13 Sep 2014)
New Revision: 61929

Added:
   grass/trunk/scripts/v.to.lines/
   grass/trunk/scripts/v.to.lines/v.to.lines.py
Removed:
   grass/trunk/scripts/v.to.lines/v.to.lines.py
Modified:
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/v.to.lines/v.to.lines.html
Log:
scripts: add v.to.lines from addons

Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2014-09-13 23:17:47 UTC (rev 61928)
+++ grass/trunk/scripts/Makefile	2014-09-14 00:16:07 UTC (rev 61929)
@@ -68,6 +68,7 @@
 	v.report \
 	v.out.gps \
 	v.pack \
+        v.to.lines \
 	v.unpack \
 	v.what.vect \
 	wxpyimgview \

Modified: grass/trunk/scripts/v.to.lines/v.to.lines.html
===================================================================
--- grass-addons/grass7/vector/v.to.lines/v.to.lines.html	2014-09-11 23:20:33 UTC (rev 61866)
+++ grass/trunk/scripts/v.to.lines/v.to.lines.html	2014-09-14 00:16:07 UTC (rev 61929)
@@ -1,14 +1,16 @@
 <h2>DESCRIPTION</h2>
 
 <em>v.to.lines</em> converts vector polygons (boundaries) to lines as well
-as vector points to lines via triangulations. This script is a wrapper
-script to <em>>v.category</em>, <em>v.delaunay</em>, and <em>v.edit</em>.
+as vector points to lines via triangulations.
 
 <h2>NOTES</h2>
 
 <em>v.to.lines</em> is able to convert point data (via triangulation)
 and areas to lines (via boundary to line conversion).
 
+This script is a wrapper script to <em>>v.category</em>,
+<em>v.delaunay</em>, and <em>v.edit</em>.
+
 <h2>EXAMPLES</h2>
 
 The examples are for the North Carolina sample dataset location:

Deleted: grass/trunk/scripts/v.to.lines/v.to.lines.py
===================================================================
--- grass-addons/grass7/vector/v.to.lines/v.to.lines.py	2014-09-11 23:20:33 UTC (rev 61866)
+++ grass/trunk/scripts/v.to.lines/v.to.lines.py	2014-09-14 00:16:07 UTC (rev 61929)
@@ -1,113 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-############################################################################
-#
-# MODULE:       v.to.lines (former v.polytoline)
-# AUTHOR(S):    Luca Delucchi
-#               point support added by Markus Neteler
-#
-# PURPOSE:      Converts polygons and points to lines
-# COPYRIGHT:    (C) 2013-2014 by the GRASS Development Team
-#
-#               This program is free software under the GNU General Public
-#               License (version 2). Read the file COPYING that comes with GRASS
-#               for details.
-# TODO
-#    support centroids (treat as points)?
-#############################################################################
-
-#%module
-#% description: Converts vector polygons or points to lines.
-#% keywords: vector
-#% keywords: geometry
-#%end
-
-#%option G_OPT_V_INPUT
-#%end
-
-#%option G_OPT_V_OUTPUT
-#%end
-
-import grass.script as grass
-import os, sys
-
-
-def main():
-    # Get the options
-    input = options["input"]
-    output = options["output"]
-
-    overwrite = grass.overwrite()
-
-    quiet = True
-
-    if grass.verbosity() > 2:
-        quiet = False
-
-    in_info = grass.vector_info(input)
-    # check for wild mixture of vector types
-    if in_info['points'] > 0 and in_info['boundaries'] > 0:
-        grass.fatal(_("The input vector map contains both polygons and points, cannot handle mixed types"))
-
-    # process points via triangulation, then exit
-    if in_info['points'] > 0:
-        layer=1 # hardcoded for now
-        grass.message(_("Processing point data (%d points found)...") % in_info['points'])
-        grass.run_command('v.delaunay', input=input, layer=layer, output=output)
-        sys.exit()
-
-    # process areas
-    if in_info['areas'] == 0 and in_info['boundaries'] == 0:
-        grass.fatal(_("The input vector map does not contain polygons"))
-    pid = os.getpid()
-    out_type = '{inp}_type_{pid}'.format(inp=input, pid=pid)
-    input_tmp = '{inp}_tmp_{pid}'.format(inp=input, pid=pid)
-    remove_names = "%s,%s" % (out_type, input_tmp)
-    grass.message(_("Processing area data (%d areas found)...") % in_info['areas'])
-    if 0 != grass.run_command('v.category', layer="2", type='boundary',
-                              option='add', input=input, out=input_tmp,
-                              quiet=quiet):
-        grass.run_command('g.remove', vect=input_tmp, quiet=quiet)
-        grass.fatal(_("Error creating layer 2"))
-    if 0 != grass.run_command('v.db.addtable', map=input_tmp, layer="2",
-                              columns="left integer,right integer",
-                              quiet=quiet):
-        grass.run_command('g.remove', vect=input_tmp, quiet=quiet)
-        grass.fatal(_("Error creating new table for layer 2"))
-    if 0 != grass.run_command('v.to.db', map=input_tmp, option="sides",
-                              columns="left,right", layer="2", quiet=quiet):
-        grass.run_command('g.remove', vect=input_tmp, quiet=quiet)
-        grass.fatal(_("Error populating new table for layer 2"))
-
-    if 0 != grass.run_command('v.type', input=input_tmp, output=out_type, \
-                              from_type='boundary', to_type='line', \
-                              quiet=quiet, layer="2"):
-        grass.run_command('g.remove', vect=remove_names, quiet=quiet)
-        grass.fatal(_("Error converting polygon to line"))
-    report = grass.read_command('v.category', flags='g', input=out_type,
-                                option='report', quiet=quiet).split('\n')
-    for r in report:
-        if r.find('centroid') != -1:
-            min_cat = report[0].split()[-2]
-            max_cat = report[0].split()[-1]
-            break
-    if 0 != grass.run_command('v.edit', map=out_type, tool='delete', \
-                              type='centroid', layer=2, quiet=quiet, \
-                              cats='{mi}-{ma}'.format(mi=min_cat, ma=max_cat)):
-        grass.run_command('g.remove', vect=remove_names, quiet=quiet)
-        grass.fatal(_("Error removing centroids"))
-
-    if 0 != grass.run_command('v.db.droptable', map=out_type, layer=1,
-                              flags='f', quiet=quiet):
-        grass.run_command('g.remove', vect=remove_names, quiet=quiet)
-        grass.fatal(_("Error removing table from layer 1"))
-    if 0 != grass.run_command('v.category', input=out_type, option='transfer',
-                              output=output, layer="2,1", quiet=quiet,
-                              overwrite=overwrite):
-        grass.run_command('g.remove', vect=remove_names, quiet=quiet)
-        grass.fatal(_("Error adding categories"))
-    grass.run_command('g.remove', vect=remove_names, quiet=quiet)
-
-if __name__ == "__main__":
-    options, flags = grass.parser()
-    main()

Copied: grass/trunk/scripts/v.to.lines/v.to.lines.py (from rev 61923, grass-addons/grass7/vector/v.to.lines/v.to.lines.py)
===================================================================
--- grass/trunk/scripts/v.to.lines/v.to.lines.py	                        (rev 0)
+++ grass/trunk/scripts/v.to.lines/v.to.lines.py	2014-09-14 00:16:07 UTC (rev 61929)
@@ -0,0 +1,141 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       v.to.lines (former v.polytoline)
+# AUTHOR(S):    Luca Delucchi
+#               point support added by Markus Neteler
+#
+# PURPOSE:      Converts polygons and points to lines
+# COPYRIGHT:    (C) 2013-2014 by the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (version 2). Read the file COPYING that comes with GRASS
+#               for details.
+# TODO
+#    support centroids (treat as points)?
+#############################################################################
+
+#%module
+#% description: Converts vector polygons or points to lines.
+#% keywords: vector
+#% keywords: geometry
+#%end
+
+#%option G_OPT_V_INPUT
+#%end
+
+#%option G_OPT_V_OUTPUT
+#%end
+
+#%option
+#% key: method
+#% type: string
+#% description: Method used for point interpolation
+#% options: delaunay
+#% answer: delaunay
+#% guisection: Area
+#%end
+
+import grass.script as grass
+import os
+import sys
+
+
+def main():
+    # Get the options
+    input = options["input"]
+    output = options["output"]
+    method = options["method"]
+    min_cat = None
+    max_cat = None
+    point = None
+    overwrite = grass.overwrite()
+
+    quiet = True
+
+    if grass.verbosity() > 2:
+        quiet = False
+
+    in_info = grass.vector_info(input)
+    # check for wild mixture of vector types
+    if in_info['points'] > 0 and in_info['boundaries'] > 0:
+        grass.fatal(_("The input vector map contains both polygons and points,"
+                      " cannot handle mixed types"))
+
+    pid = os.getpid()
+    # process points via triangulation, then exit
+    if in_info['points'] > 0:
+        point = True
+        layer = 1  # hardcoded for now
+        out_temp = '{inp}_point_tmp_{pid}'.format(inp=input, pid=pid)
+        if method == 'delaunay':
+            grass.message(_("Processing point data (%d points found)...") % in_info['points'])
+            grass.run_command('v.delaunay', input=input, layer=layer,
+                              output=out_temp, quiet=quiet)
+
+        grass.run_command('v.db.addtable', map=out_temp, quiet=True)
+        input = out_temp
+        in_info = grass.vector_info(input)
+
+    # process areas
+    if in_info['areas'] == 0 and in_info['boundaries'] == 0:
+        grass.fatal(_("The input vector map does not contain polygons"))
+
+    out_type = '{inp}_type_{pid}'.format(inp=input, pid=pid)
+    input_tmp = '{inp}_tmp_{pid}'.format(inp=input, pid=pid)
+    remove_names = "%s,%s" % (out_type, input_tmp)
+    grass.message(_("Processing area data (%d areas found)...") % in_info['areas'])
+    if 0 != grass.run_command('v.category', layer="2", type='boundary',
+                              option='add', input=input, out=input_tmp,
+                              quiet=quiet):
+        grass.run_command('g.remove', vect=input_tmp, quiet=quiet)
+        grass.fatal(_("Error creating layer 2"))
+    if 0 != grass.run_command('v.db.addtable', map=input_tmp, layer="2",
+                              columns="left integer,right integer",
+                              quiet=quiet):
+        grass.run_command('g.remove', vect=input_tmp, quiet=quiet)
+        grass.fatal(_("Error creating new table for layer 2"))
+    if 0 != grass.run_command('v.to.db', map=input_tmp, option="sides",
+                              columns="left,right", layer="2", quiet=quiet):
+        grass.run_command('g.remove', vect=input_tmp, quiet=quiet)
+        grass.fatal(_("Error populating new table for layer 2"))
+
+    if 0 != grass.run_command('v.type', input=input_tmp, output=out_type,
+                              from_type='boundary', to_type='line',
+                              quiet=quiet, layer="2"):
+        grass.run_command('g.remove', vect=remove_names, quiet=quiet)
+        grass.fatal(_("Error converting polygon to line"))
+    report = grass.read_command('v.category', flags='g', input=out_type,
+                                option='report', quiet=quiet).split('\n')
+    for r in report:
+        if r.find('centroid') != -1:
+            min_cat = report[0].split()[-2]
+            max_cat = report[0].split()[-1]
+            break
+    if min_cat and max_cat:
+        if 0 != grass.run_command('v.edit', map=out_type, tool='delete',
+                                  type='centroid', layer=2, quiet=quiet,
+                                  cats='{mi}-{ma}'.format(mi=min_cat, ma=max_cat)):
+            grass.run_command('g.remove', vect=remove_names, quiet=quiet)
+            grass.fatal(_("Error removing centroids"))
+
+    try:
+        if 0 != grass.run_command('v.db.droptable', map=out_type, layer=1,
+                                  flags='f', quiet=True):
+            grass.run_command('g.remove', vect=remove_names, quiet=quiet)
+            grass.fatal(_("Error removing table from layer 1"))
+    except:
+        grass.warning(_("No table for layer %d" % 1))
+    if 0 != grass.run_command('v.category', input=out_type, option='transfer',
+                              output=output, layer="2,1", quiet=quiet,
+                              overwrite=overwrite):
+        grass.run_command('g.remove', vect=remove_names, quiet=quiet)
+        grass.fatal(_("Error adding categories"))
+    grass.run_command('g.remove', vect=remove_names, quiet=quiet)
+    if point:
+        grass.run_command('g.remove', vect=out_temp, quiet=quiet)
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()



More information about the grass-commit mailing list