[GRASS-SVN] r54743 - in grass-addons/grass6/vector: . v.line.center

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 21 14:30:30 PST 2013


Author: msieczka
Date: 2013-01-21 14:30:30 -0800 (Mon, 21 Jan 2013)
New Revision: 54743

Added:
   grass-addons/grass6/vector/v.line.center/
   grass-addons/grass6/vector/v.line.center/Makefile
   grass-addons/grass6/vector/v.line.center/description.html
   grass-addons/grass6/vector/v.line.center/v.line.center
Log:
Submitting v.line.center addon shell script.

Added: grass-addons/grass6/vector/v.line.center/Makefile
===================================================================
--- grass-addons/grass6/vector/v.line.center/Makefile	                        (rev 0)
+++ grass-addons/grass6/vector/v.line.center/Makefile	2013-01-21 22:30:30 UTC (rev 54743)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.line.center
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/grass6/vector/v.line.center/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass6/vector/v.line.center/description.html
===================================================================
--- grass-addons/grass6/vector/v.line.center/description.html	                        (rev 0)
+++ grass-addons/grass6/vector/v.line.center/description.html	2013-01-21 22:30:30 UTC (rev 54743)
@@ -0,0 +1,35 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.line.center</em> creates an <b>output</b> vector map which contains the
+same number of vector points as there are in the <b>input</b> map, with each point
+located in the middle of the lenght of an input vector line, if he line
+has a category in the <b>layer</b> of the input map.
+
+<p>
+Points in the <b>output</b> vector map have categories only in layer 1. Their category
+numbers match those of input vector lines.
+
+<h2>NOTES</h2>
+
+<ul>
+1. Requires GRASS 6.x.<br>
+2. Only input lines with categories are processed. Categories must be unique. If they
+are not, the script will print warnings like "Unable to get point on line" and will
+produce rubbish.
+Use <b>v.category</b> to adjust category assignment first, if needed.
+</ul>
+
+<h2>SEE ALSO</h2>
+
+<em>
+	<a href="v.category.html">v.category</a>,
+	<a href="v.segment.html">v.segment</a>,
+	<a href="v.clean.html">v.clean</a>
+</em>
+
+<h2>AUTHOR</h2>
+
+Maciej Sieczka
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass-addons/grass6/vector/v.line.center/description.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass6/vector/v.line.center/v.line.center
===================================================================
--- grass-addons/grass6/vector/v.line.center/v.line.center	                        (rev 0)
+++ grass-addons/grass6/vector/v.line.center/v.line.center	2013-01-21 22:30:30 UTC (rev 54743)
@@ -0,0 +1,134 @@
+#!/bin/sh
+#
+############################################################################
+#
+# MODULE:       v.line.center
+#
+# AUTHOR(S):    Maciej Sieczka
+#
+# PURPOSE:      Create a vector map of points, each located in the center of
+#               one input line.
+#
+# VERSION:      1.0.1, developed over Grass 6.3 CVS 2007.01.24
+#
+# COPYRIGHT:    (c) 2007 Maciej Sieczka
+#
+# NOTES:        This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+# CHANGELOG:
+#
+# 1.0.1: first public release
+
+#%Module
+#%  description: Create a points vector map with each point located in the center of one input line.
+#%END
+
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,vector,vector
+#% description: Input lines vector
+#% required : yes
+#%END
+
+#%option
+#% key: layer
+#% type: integer
+#% answer: 1
+#% description: Input layer number
+#% required : yes
+#%END
+
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new,dig,vector
+#% description: Output points vector
+#% required : yes
+#%END
+
+# called from Grass?
+if [ -z "$GISBASE" ]; then
+ echo "ERROR: You must be in GRASS GIS to run this program." >&2
+ exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ]; then
+  exec g.parser "$0" "$@"
+fi
+
+# check if we have awk
+if [ ! -x "`which awk`" ]; then
+  g.message -e '"awk" executable required but not found' 1>&2
+  exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+INPUT="$GIS_OPT_INPUT"
+OUTPUT="$GIS_OPT_OUTPUT"
+LAYER=$GIS_OPT_LAYER
+
+# check if output vector exists
+#eval `g.gisenv`
+#g.findfile elem=vector file="$OUTPUT" mapset="$MAPSET" > /dev/null
+# if [ $? -eq 0 ] ; then
+#  echo "ERROR: The output vector <"$OUTPUT"> already exists in current mapset." 1>&2
+#  exit 1
+# fi
+
+# set up temporary files
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ]; then
+  g.message -e "Unable to create temporary files." 1>&2
+  exit 1
+fi
+
+PROG=`basename $0 | sed 's/\./_/g'`
+# UNQ=`basename $TMP | sed 's/\./_/g'`"_${PROG}"
+
+# define the cleanup procedure
+cleanup() {
+ rm -f $TMP \
+ ${TMP}.${PROG}.offsets
+}
+
+# what to do in case of user break:
+exitprocedure() {
+ g.message -w 'User break!' 1>&2
+ cleanup
+ exit 1
+}
+# shell check for user break (signal list: trap -l)
+trap "exitprocedure" 2 3 15
+
+
+
+### DO IT ###
+
+# Prepare the input for v.segment that will extract center points of each line,
+# excluding the first and the last offset.
+
+v.to.db --q -p map="$INPUT" layer=$LAYER type=line option=length column=dummy | awk -F "|" 'NR>1 {printf "%s","P "$1" "$1" "; printf "%.16f\n",$2/2}' > "${TMP}.${PROG}.offsets"
+
+# Pipe offsets into v.segment. The output are points located exactly in the
+# center of the input lines.
+
+v.segment --q llayer=$LAYER input="$INPUT" output="$OUTPUT" file="${TMP}.${PROG}.offsets"
+
+
+
+### ALL DONE ###
+
+cleanup
+
+echo 1>&2
+g.message 'Done.' 1>&2
+echo 1>&2


Property changes on: grass-addons/grass6/vector/v.line.center/v.line.center
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list