#!/bin/sh # ############################################################################ # # MODULE: v.line.center # # AUTHOR(S): Maciej Sieczka, sieczka@biol.uni.wroc.pl # Intitute of Plant Biology, Wroclaw University, Poland # # 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: Developed within the course and for the purpose of the CAVES # project http://caves.cfpm.org, funded under the EU 6FP NEST # programme. # # 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 test "$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 echo "ERROR: awk required, please install awk or gawk first." 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 echo "ERROR: 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 \rm -f $TMP.${PROG}.offsets } # what to do in case of user break: exitprocedure() { echo "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 -p map="$INPUT" layer=$LAYER type=line option=length units=me 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. cat $TMP.${PROG}.offsets | v.segment llayer=$LAYER input="$INPUT" output="$OUTPUT" > /dev/null ### ALL DONE ### cleanup echo 1>&2 echo "Done." 1>&2 echo 1>&2