[GRASS-SVN] r61616 - in grass-addons/grass7/vector: . v.to.lines
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 14 04:57:33 PDT 2014
Author: neteler
Date: 2014-08-14 04:57:33 -0700 (Thu, 14 Aug 2014)
New Revision: 61616
Added:
grass-addons/grass7/vector/v.to.lines/
grass-addons/grass7/vector/v.to.lines/v.to.lines.html
grass-addons/grass7/vector/v.to.lines/v.to.lines.py
Removed:
grass-addons/grass7/vector/v.polytoline/
grass-addons/grass7/vector/v.to.lines/v.polytoline.html
grass-addons/grass7/vector/v.to.lines/v.polytoline.py
Modified:
grass-addons/grass7/vector/Makefile
grass-addons/grass7/vector/v.to.lines/Makefile
Log:
Addons: v.polytoline renamed to v.to.lines; point support added
Modified: grass-addons/grass7/vector/Makefile
===================================================================
--- grass-addons/grass7/vector/Makefile 2014-08-14 11:16:25 UTC (rev 61615)
+++ grass-addons/grass7/vector/Makefile 2014-08-14 11:57:33 UTC (rev 61616)
@@ -9,6 +9,7 @@
v.link.precip \
v.median \
v.net.turntable \
+ v.to.lines \
v.out.ply \
v.surf.icw
Modified: grass-addons/grass7/vector/v.to.lines/Makefile
===================================================================
--- grass-addons/grass7/vector/v.polytoline/Makefile 2014-08-14 03:51:17 UTC (rev 61613)
+++ grass-addons/grass7/vector/v.to.lines/Makefile 2014-08-14 11:57:33 UTC (rev 61616)
@@ -1,6 +1,6 @@
MODULE_TOPDIR = ../..
-PGM = v.polytoline
+PGM = v.to.lines
include $(MODULE_TOPDIR)/include/Make/Script.make
Deleted: grass-addons/grass7/vector/v.to.lines/v.polytoline.html
===================================================================
--- grass-addons/grass7/vector/v.polytoline/v.polytoline.html 2014-08-14 03:51:17 UTC (rev 61613)
+++ grass-addons/grass7/vector/v.to.lines/v.polytoline.html 2014-08-14 11:57:33 UTC (rev 61616)
@@ -1,26 +0,0 @@
-<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$</i>
Deleted: grass-addons/grass7/vector/v.to.lines/v.polytoline.py
===================================================================
--- grass-addons/grass7/vector/v.polytoline/v.polytoline.py 2014-08-14 03:51:17 UTC (rev 61613)
+++ grass-addons/grass7/vector/v.to.lines/v.polytoline.py 2014-08-14 11:57:33 UTC (rev 61616)
@@ -1,98 +0,0 @@
-#!/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)
- input_tmp = '{inp}_tmp_{pid}'.format(inp=input, pid=pid)
- remove_names = "%s,%s" % (out_type, input_tmp)
- 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-addons/grass7/vector/v.to.lines/v.to.lines.html (from rev 61613, grass-addons/grass7/vector/v.polytoline/v.polytoline.html)
===================================================================
--- grass-addons/grass7/vector/v.to.lines/v.to.lines.html (rev 0)
+++ grass-addons/grass7/vector/v.to.lines/v.to.lines.html 2014-08-14 11:57:33 UTC (rev 61616)
@@ -0,0 +1,43 @@
+<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>.
+
+<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).
+
+<h2>EXAMPLES</h2>
+
+The examples are for the North Carolina sample dataset location:
+
+<h3>Area to line conversion</h3>
+
+<div class="code"><pre>
+v.to.lines input=boundary_municp output=boundary_municp_lines
+</pre></div>
+
+<h3>Area to line conversion</h3>
+<div class="code"><pre>
+v.to.lines input=geodetic_pts output=geodetic_pts_lines
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.category.html">v.category</a>,
+<a href="v.delaunay.html">v.delaunay</a>,
+<a href="v.edit.html">v.edit</a>,
+<a href="v.to.points.html">v.to.points</a>,
+<a href="v.type.html">v.type</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Luca Delucchi, Fondazione Edmund Mach
+
+<p>
+<i>Last changed: $Date$</i>
Copied: grass-addons/grass7/vector/v.to.lines/v.to.lines.py (from rev 61613, grass-addons/grass7/vector/v.polytoline/v.polytoline.py)
===================================================================
--- grass-addons/grass7/vector/v.to.lines/v.to.lines.py (rev 0)
+++ grass-addons/grass7/vector/v.to.lines/v.to.lines.py 2014-08-14 11:57:33 UTC (rev 61616)
@@ -0,0 +1,113 @@
+#!/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()
More information about the grass-commit
mailing list