[GRASS-SVN] r40767 - in grass-addons/vector: . v.points.cog
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 1 06:40:00 EST 2010
Author: hamish
Date: 2010-02-01 06:39:59 -0500 (Mon, 01 Feb 2010)
New Revision: 40767
Added:
grass-addons/vector/v.points.cog/
grass-addons/vector/v.points.cog/Makefile
grass-addons/vector/v.points.cog/description.html
grass-addons/vector/v.points.cog/v.points.cog
Log:
module to calc center of gravity of clusters
Added: grass-addons/vector/v.points.cog/Makefile
===================================================================
--- grass-addons/vector/v.points.cog/Makefile (rev 0)
+++ grass-addons/vector/v.points.cog/Makefile 2010-02-01 11:39:59 UTC (rev 40767)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.points.cog
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Property changes on: grass-addons/vector/v.points.cog/Makefile
___________________________________________________________________
Added: svn:mime-type
+ text/x-makefile
Added: svn:eol-style
+ native
Added: grass-addons/vector/v.points.cog/description.html
===================================================================
--- grass-addons/vector/v.points.cog/description.html (rev 0)
+++ grass-addons/vector/v.points.cog/description.html 2010-02-01 11:39:59 UTC (rev 40767)
@@ -0,0 +1,52 @@
+<h2>DESCRIPTION</h2>
+
+
+<em>v.points.cog</em> condenses points or centroids sharing
+a common attribute into a single point in a new vector map at their
+average position (center of gravity).
+<p>
+For this to work well your clusters of points must be gregarious
+(Gaussian distribution) - if two groups of points habitate in two
+corners of the map the output point will fall in the center and
+match niether well.
+<p>
+If needed you can use <em>v.digit</em> to adjust point positions
+created by this module. <!-- repel 2 points if v.distance < minimum? -->
+
+<!--<p> appropriate for lat/lon? -->
+<!-- does label have to be string -->
+
+
+<h2>EXAMPLE</h2>
+
+Create single points at the average of all points in the
+<tt>bugsites</tt> map, and place a single label there.
+
+<div class="code"><pre>
+v.points.cog in=bugsites out=bug_cog column=str1
+
+d.vect -c bugsites color=none icon=basic/circle
+
+d.vect bug_cog disp=attr attrcol=str1 lcolor=black \
+ lsize=14 xref=center yref=center bgcolor=white
+</pre></div>
+
+
+<H2>SEE ALSO</H2>
+<em>
+<A HREF="v.label.sa.html">v.label.sa</A><br>
+<A HREF="v.label.html">v.label</A><br>
+<A HREF="v.digit.html">v.digit</A>
+</em>
+
+
+<H2>AUTHOR</H2>
+
+Hamish Bowman<BR>
+<i>Dept. Marine Science<br>
+University of Otago<br>
+Dunedin, New Zealand</i>
+<BR>
+
+<p>
+<i>Last changed: $Date$</i>
Property changes on: grass-addons/vector/v.points.cog/description.html
___________________________________________________________________
Added: svn:mime-type
+ text/html
Added: svn:keywords
+ Author Date Id
Added: svn:eol-style
+ native
Added: grass-addons/vector/v.points.cog/v.points.cog
===================================================================
--- grass-addons/vector/v.points.cog/v.points.cog (rev 0)
+++ grass-addons/vector/v.points.cog/v.points.cog 2010-02-01 11:39:59 UTC (rev 40767)
@@ -0,0 +1,127 @@
+#!/bin/sh
+#
+############################################################################
+#
+# MODULE: v.points.cog
+#
+# AUTHOR(S): Hamish Bowman
+#
+# PURPOSE: Condense points or centroids sharing a common attribute into a single point
+#
+# COPYRIGHT: (c) 2010 Hamish Bowman, and the GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+#############################################################################
+#%Module
+#% description: Condense points or centroids sharing a common attribute into a single point.
+#% keywords: vector, cluster
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,vector,vector
+#% description: Name of input vector map
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new,vector,vector
+#% description: Name for output vector map
+#% required : yes
+#%end
+#%option
+#% key: column
+#% type: string
+#% description: Column containing common attribute
+#% required : yes
+#%end
+#%option
+#% key: layer
+#% type: integer
+#% answer: 1
+#% description: Layer number
+#% required: no
+#%end
+
+##%option
+##% key: type
+##% type: string
+##% description: Feature type(s)
+##% options: point,centroid
+##% answer: point
+##% required: no
+##% multiple: yes
+##%end
+
+
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program." 1>&2
+ exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+ exec g.parser "$0" "$@"
+fi
+
+MAP="$GIS_OPT_INPUT"
+COLUMN="$GIS_OPT_COLUMN"
+LAYER="$GIS_OPT_LAYER"
+
+# check for input map
+eval `g.findfile element=vector file="$MAP"`
+if [ ! "$file" ] ; then
+ g.message -e "Vector map <$MAP> does not exist."
+ exit 1
+fi
+
+# check for column
+if [ `v.info -c "$MAP" layer="$LAYER" --quiet | cut -f2 -d'|' | grep -c "^$COLUMN$"` -ne 1 ] ; then
+ g.message -e "Column <$COLUMN> not found."
+ exit 1
+fi
+
+# get column details so we can recreate it
+DB=`v.db.connect "$MAP" -g layer="$LAYER" fs='|' | cut -f4 -d'|'`
+COLUMN_DESC=`db.describe -c table="$MAP" database="$DB" | grep " $COLUMN:" | cut -f3- -d:`
+if [ `echo "$COLUMN_DESC" | grep -c CHARACTER` -eq 1 ] ; then
+ COLUMN_TYPE="string"
+ COLUMN_LEN=`echo "$COLUMN_DESC" | cut -f2 -d:`
+ COLUMN_DEFN="varchar($COLUMN_LEN)"
+else
+ COLUMN_TYPE="number"
+ COLUMN_DEFN=`echo "$COLUMN_DESC" | cut -f1 -d:`
+fi
+
+# cheap hack to avoid conflict
+if [ $COLUMN = "cat" ] ; then
+ OUT_COLUMN="cat_"
+else
+ OUT_COLUMN="$COLUMN"
+fi
+
+
+(
+IFS='|'
+for ITEM in `v.db.select "$MAP" -c column="$COLUMN" layer="$LAYER" | sort | uniq | tr '\n' '|'` ; do
+ #echo "[$ITEM]"
+ if [ "$COLUMN_TYPE" = "string" ] ; then
+ WHERE_STR="$COLUMN = '$ITEM'"
+ else
+ WHERE_STR="$COLUMN = $ITEM"
+ fi
+
+ v.out.ascii "$MAP" column="$COLUMN" layer="$LAYER" where="$WHERE_STR" | \
+ awk -F'|' \
+ 'BEGIN { sum_x=0; sum_y=0; i=0 }
+ { sum_x += $1; sum_y += $2; i++ }
+ END { if(i>0) { printf("%.15g|%.15g|%s\n", sum_x/i, sum_y/i, $4) } }'
+done
+) | v.in.ascii out="$GIS_OPT_OUTPUT" columns="x double, y double, $OUT_COLUMN $COLUMN_DEFN"
+#echo columns="x double, y double, $OUT_COLUMN $COLUMN_DEFN"
+
+
+exit
Property changes on: grass-addons/vector/v.points.cog/v.points.cog
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/x-sh
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list