[GRASS-SVN] r38821 - in grass-addons: . db db/db.join

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 21 11:05:47 EDT 2009


Author: neteler
Date: 2009-08-21 11:05:47 -0400 (Fri, 21 Aug 2009)
New Revision: 38821

Added:
   grass-addons/db/
   grass-addons/db/db.join/
   grass-addons/db/db.join/Makefile
   grass-addons/db/db.join/db.join
   grass-addons/db/db.join/description.html
Log:
new db.join

Added: grass-addons/db/db.join/Makefile
===================================================================
--- grass-addons/db/db.join/Makefile	                        (rev 0)
+++ grass-addons/db/db.join/Makefile	2009-08-21 15:05:47 UTC (rev 38821)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = db.join
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/db/db.join/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/db/db.join/db.join
===================================================================
--- grass-addons/db/db.join/db.join	                        (rev 0)
+++ grass-addons/db/db.join/db.join	2009-08-21 15:05:47 UTC (rev 38821)
@@ -0,0 +1,96 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE:       db.join
+# AUTHOR(S):    Markus Neteler
+# PURPOSE:      Join a table into another table
+# COPYRIGHT:    (C) 2009 by Markus Neteler 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: Allows to join a table into another table.
+#% keywords: database, attribute table
+#%End
+
+#%option
+#% key: table
+#% type: string
+#% key_desc : name
+#% description: Table to join into
+#% gisprompt: old_dbtable,dbtable,dbtable
+#% required : yes
+#%end
+
+#%option
+#% key: column
+#% type: string
+#% description: Join column in first table
+#% required : yes
+#% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
+#%end
+
+#%option
+#% key: otable
+#% type: string
+#% key_desc : name
+#% description: Other table name
+#% required : yes
+#% gisprompt: old_dbtable,dbtable,dbtable
+#%end
+
+#%option
+#% key: ocolumn
+#% type: string
+#% description: Join column in other table
+#% required : yes
+#% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
+#%end
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." >&2
+ exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+fi
+
+driver=`db.connect -p | grep "^driver" | cut -d':' -f2`
+if [ "$driver" = "dbf" ] ; then
+   g.message -e "JOIN is not supported for tables stored in DBF format."
+   exit 1
+fi
+
+COLLIST=`db.describe  -c "$GIS_OPT_TABLE" | grep '^Column ' | sed 's+ ++g' | cut -d':' -f2`
+OCOLLIST=`db.describe  -c "$GIS_OPT_OTABLE" | grep '^Column ' | sed 's+ ++g' | cut -d':' -f2`
+# heck, types may have white space
+OCOLTYPES=`db.describe -c "$GIS_OPT_OTABLE" | grep '^Column ' | sed 's+ ++g' | cut -d':' -f3 | tr -s ' ' '_'`
+
+i=1
+for col in $OCOLLIST ; do
+  CURRTYPE=`echo $OCOLTYPES | cut -d' ' -f$i | tr -s '_' ' '`
+  # we cannot have the same column name twice
+  for incol in $COLLIST ; do
+      if [ "$col" = "$incol" ] ; then
+         col=${col}b
+      fi
+  done
+  echo "ALTER TABLE $GIS_OPT_TABLE ADD COLUMN $col $OCURRTYPE" | db.execute
+  if [ $? -ne 0 ] ; then
+	g.message -e "Cannot continue."
+	exit 1
+  fi
+  echo "UPDATE $GIS_OPT_TABLE SET $col=(SELECT $col
+        FROM $GIS_OPT_OTABLE WHERE $GIS_OPT_OTABLE.$GIS_OPT_OCOLUMN=$GIS_OPT_TABLE.$GIS_OPT_COLUMN);" | db.execute
+  i=`expr $i + 1`
+done
+
+g.message message="Table <$GIS_OPT_OTABLE> JOINed into <$GIS_OPT_TABLE>"
+
+exit 0


Property changes on: grass-addons/db/db.join/db.join
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native

Added: grass-addons/db/db.join/description.html
===================================================================
--- grass-addons/db/db.join/description.html	                        (rev 0)
+++ grass-addons/db/db.join/description.html	2009-08-21 15:05:47 UTC (rev 38821)
@@ -0,0 +1,44 @@
+<h2>DESCRIPTION</h2>
+
+<em>db.join</em> joins the content of one attribute table into another
+attribute table through common attributes.
+
+<h2>NOTES</h2>
+
+<em>db.join</em> is a front-end to <em>db.execute</em> to allow easier usage.
+
+The attribute table must be stored in a SQL database (SQLite, PostgreSQL,
+MySQL, ODBC, ...). The DBF backend is not supported. Tables can be
+imported with <em>db.in.ogr</em>.
+
+<h2>EXAMPLE</h2>
+
+
+<div class="code"><pre>
+# join soils_legend into mysoils attribute table
+db.join mysoils col=label otable=soils_legend ocol=shortname
+
+# verification of join
+db.select mysoils
+cat|label|id|shortname|longname
+1|Aab|||
+2|Ba|2|Ba|Barnum silt loam
+3|Bb|3|Bb|Barnum silt loam, channeled
+4|BcB|4|BcB|Boneek silt loam, 2 to 6
+5|BcC|5|BcC|Boneek silt loam, 6 to 9
+...
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="db.execute.html">db.execute</a></em>,
+<em><a HREF="db.in.ogr.html">db.in.ogr</a></em>,
+<em><a HREF="v.db.join.html">v.db.join</a></em><br>
+<em><a HREF="v.db.update.html">v.db.update</a></em><br>
+<em><a href="sql.html">GRASS SQL interface</a></em>
+
+<h2>AUTHOR</h2>
+
+Markus Neteler
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass-addons/db/db.join/description.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native



More information about the grass-commit mailing list