[GRASS-SVN] r58384 - in grass-addons/grass7/vector: . v.polytoline

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 4 06:14:26 PST 2013


Author: lucadelu
Date: 2013-12-04 06:14:26 -0800 (Wed, 04 Dec 2013)
New Revision: 58384

Added:
   grass-addons/grass7/vector/v.polytoline/
   grass-addons/grass7/vector/v.polytoline/Makefile
   grass-addons/grass7/vector/v.polytoline/v.polytoline.html
   grass-addons/grass7/vector/v.polytoline/v.polytoline.py
Log:
add new module to convert polygon to line

Added: grass-addons/grass7/vector/v.polytoline/Makefile
===================================================================
--- grass-addons/grass7/vector/v.polytoline/Makefile	                        (rev 0)
+++ grass-addons/grass7/vector/v.polytoline/Makefile	2013-12-04 14:14:26 UTC (rev 58384)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.polytoline
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/vector/v.polytoline/v.polytoline.html
===================================================================
--- grass-addons/grass7/vector/v.polytoline/v.polytoline.html	                        (rev 0)
+++ grass-addons/grass7/vector/v.polytoline/v.polytoline.html	2013-12-04 14:14:26 UTC (rev 58384)
@@ -0,0 +1,26 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.polytoline</em> is useful to convert polygonal vector to lines
+
+<h2>EXAMPLES</h2>
+
+<div class="code"><pre>
+v.polytoline input=boundary_municp output=boundary_municp_line
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em><a href="v.type.html">v.type</a></em>, 
+<em><a href="v.edit.html">v.edit</a></em>,
+<em><a href="v.category.html">v.category</a></em>,
+
+
+
+
+<h2>AUTHOR</h2>
+
+Luca Delucchi, Fondazione Edmund Mach
+
+<p>
+<i>Last changed: $Date: 2013-12-04 14:56:45 +0100 (Tue, 08 Nov 2011) $</i>

Added: grass-addons/grass7/vector/v.polytoline/v.polytoline.py
===================================================================
--- grass-addons/grass7/vector/v.polytoline/v.polytoline.py	                        (rev 0)
+++ grass-addons/grass7/vector/v.polytoline/v.polytoline.py	2013-12-04 14:14:26 UTC (rev 58384)
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+############################################################################
+#
+# MODULE:       v.polytoline
+# AUTHOR(S):    Luca delucchi
+#
+# PURPOSE:      Convert polygon to line
+# COPYRIGHT:    (C) 2013 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.
+#
+#############################################################################
+
+#%module
+#% description: Convert polygon to line.
+#% keywords: vector
+#% keywords: geometry
+#%end
+
+#%option G_OPT_V_INPUT
+#%end
+
+#%option G_OPT_V_OUTPUT
+#%end
+
+import grass.script as grass
+import os
+
+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)
+    if in_info['areas'] == 0 and in_info['boundaries'] == 0:
+        grass.fatal(_("The input vector seems not to be polygon"))
+    pid = os.getpid()
+    out_type = '{inp}_type_{pid}'.format(inp=input, pid=pid)
+    if 0 != grass.run_command('v.type', input=input, output=out_type, \
+                              from_type='boundary', to_type='line', \
+                              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', quiet=quiet, \
+                              cats='{mi}-{ma}'.format(mi=min_cat, ma=max_cat)):
+        grass.fatal(_("Error removing centroids"))
+    if 0 != grass.run_command('v.category', input=out_type, option='add',
+                              output=output, quiet=quiet, overwrite=overwrite):
+        grass.run_command('g.remove', vect=out_type, quiet=quiet)
+        grass.fatal(_("Error adding categories"))
+    grass.run_command('g.remove', vect=out_type, quiet=quiet)
+
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    main()



More information about the grass-commit mailing list