[GRASS-SVN] r39820 - grass/trunk/scripts/v.db.addcolumn
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Nov 26 17:32:44 EST 2009
Author: martinl
Date: 2009-11-26 17:32:43 -0500 (Thu, 26 Nov 2009)
New Revision: 39820
Added:
grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.html
grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.py
Removed:
grass/trunk/scripts/v.db.addcolumn/v.db.addcol.html
grass/trunk/scripts/v.db.addcolumn/v.db.addcol.py
Log:
v.db.addcol renamed to v.db.addcolumn
Deleted: grass/trunk/scripts/v.db.addcolumn/v.db.addcol.html
===================================================================
--- grass/trunk/scripts/v.db.addcolumn/v.db.addcol.html 2009-11-26 21:57:08 UTC (rev 39819)
+++ grass/trunk/scripts/v.db.addcolumn/v.db.addcol.html 2009-11-26 22:32:43 UTC (rev 39820)
@@ -1,47 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.db.addcolumn</em> adds one or more column(s) to the attribute table
-connected to a given vector map. It automatically checks the connection for the
-specified layer.
-
-<h2>NOTES</h2>
-
-v.db.addcolumn is a front-end to <em>db.execute</em> to allow easier usage.
-
-The supported types of columns depend on the database backend. However, all
-backends should support VARCHAR, INT, DOUBLE PRECISION and DATE. The default
-dbf backend supports only these types.
-
-The existing database connection(s) can be verified with <em>v.db.connect</em>.
-
-<h2>EXAMPLES</h2>
-
-Adding a single column:<br>
-<div class="code"><pre>
-v.db.addcolumn sentiero_brenta_points columns="slope double precision"
-v.info -c sentiero_brenta_points
-</pre></div>
-
-<p>
-Adding two columns:<br>
-<div class="code"><pre>
-v.db.addcolumn sentiero_brenta_points columns="slope double precision,myname varchar(15)"
-v.info -c sentiero_brenta_points
-</pre></div>
-
-<h2>SEE ALSO</h2>
-
-<em><a HREF="db.execute.html">db.execute</a></em>,
-<em><a HREF="v.db.addtable.html">v.db.addtable</a></em>,
-<em><a HREF="v.db.connect.html">v.db.connect</a></em>,
-<em><a HREF="v.db.dropcolumn.html">v.db.dropcolumn</a></em>,
-<em><a HREF="v.db.droptable.html">v.db.droptable</a></em>,
-<em><a HREF="v.db.select.html">v.db.select</a></em>,
-<em><a HREF="v.db.update.html">v.db.update</a></em>
-
-
-<h2>AUTHOR</h2>
-
-Moritz Lennert (mlennert at club.worldonline.be)
-
-<p><i>Last changed: $Date$</i>
Deleted: grass/trunk/scripts/v.db.addcolumn/v.db.addcol.py
===================================================================
--- grass/trunk/scripts/v.db.addcolumn/v.db.addcol.py 2009-11-26 21:57:08 UTC (rev 39819)
+++ grass/trunk/scripts/v.db.addcolumn/v.db.addcol.py 2009-11-26 22:32:43 UTC (rev 39820)
@@ -1,92 +0,0 @@
-#!/usr/bin/env python
-#
-############################################################################
-#
-# MODULE: v.db.addcolumnumn
-# AUTHOR(S): Moritz Lennert
-# Converted to Python by Glynn Clements
-# PURPOSE: interface to db.execute to add a column to the attribute table
-# connected to a given vector map
-# COPYRIGHT: (C) 2005 by 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: Adds one or more columns to the attribute table connected to a given vector map.
-#% keywords: vector
-#% keywords: database
-#% keywords: attribute table
-#%End
-
-#%option
-#% key: map
-#% type: string
-#% gisprompt: old,vector,vector
-#% key_desc : name
-#% description: Vector map for which to edit attribute table
-#% required : yes
-#%end
-
-#%option
-#% key: layer
-#% type: integer
-#% description: Layer where to add column
-#% answer: 1
-#% required : no
-#%end
-
-#%option
-#% key: columns
-#% type: string
-#% description: Name and type of the new column(s) ('name type [,name type, ...]' - types depend on database backend, but all support VARCHAR(), INT, DOUBLE PRECISION and DATE)
-#% required : yes
-#%end
-
-import sys
-import os
-import grass.script as grass
-
-def main():
- map = options['map']
- layer = options['layer']
- columns = options['columns']
- columns = [col.strip() for col in columns.split(',')]
-
- # does map exist in CURRENT mapset?
- mapset = grass.gisenv()['MAPSET']
- exists = bool(grass.find_file(map, element = 'vector', mapset = mapset)['file'])
-
- if not exists:
- grass.fatal(_("Vector map <%s> not found in current mapset") % map)
-
- try:
- f = grass.vector_db(map)[int(layer)]
- except KeyError:
- grass.fatal(_("There is no table connected to this map. Run v.db.connect or v.db.addtable first."))
- table = f['table']
- database = f['database']
- driver = f['driver']
-
- colnum = len(columns)
-
- for col in columns:
- if not col:
- grass.fatal(_("There is an empty column. Did you leave a trailing comma?"))
-
- p = grass.feed_command('db.execute', input = '-', database = database, driver = driver)
- p.stdin.write("ALTER TABLE %s ADD COLUMN %s" % (table, col))
- p.stdin.close()
- if p.wait() != 0:
- grass.fatal(_("Unable to add column <%s>.") % col)
-
- # write cmd history:
- grass.vector_history(map)
-
-if __name__ == "__main__":
- options, flags = grass.parser()
- main()
Copied: grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.html (from rev 39817, grass/trunk/scripts/v.db.addcolumn/v.db.addcol.html)
===================================================================
--- grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.html (rev 0)
+++ grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.html 2009-11-26 22:32:43 UTC (rev 39820)
@@ -0,0 +1,47 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.db.addcolumn</em> adds one or more column(s) to the attribute table
+connected to a given vector map. It automatically checks the connection for the
+specified layer.
+
+<h2>NOTES</h2>
+
+v.db.addcolumn is a front-end to <em>db.execute</em> to allow easier usage.
+
+The supported types of columns depend on the database backend. However, all
+backends should support VARCHAR, INT, DOUBLE PRECISION and DATE. The default
+dbf backend supports only these types.
+
+The existing database connection(s) can be verified with <em>v.db.connect</em>.
+
+<h2>EXAMPLES</h2>
+
+Adding a single column:<br>
+<div class="code"><pre>
+v.db.addcolumn sentiero_brenta_points columns="slope double precision"
+v.info -c sentiero_brenta_points
+</pre></div>
+
+<p>
+Adding two columns:<br>
+<div class="code"><pre>
+v.db.addcolumn sentiero_brenta_points columns="slope double precision,myname varchar(15)"
+v.info -c sentiero_brenta_points
+</pre></div>
+
+<h2>SEE ALSO</h2>
+
+<em><a HREF="db.execute.html">db.execute</a></em>,
+<em><a HREF="v.db.addtable.html">v.db.addtable</a></em>,
+<em><a HREF="v.db.connect.html">v.db.connect</a></em>,
+<em><a HREF="v.db.dropcolumn.html">v.db.dropcolumn</a></em>,
+<em><a HREF="v.db.droptable.html">v.db.droptable</a></em>,
+<em><a HREF="v.db.select.html">v.db.select</a></em>,
+<em><a HREF="v.db.update.html">v.db.update</a></em>
+
+
+<h2>AUTHOR</h2>
+
+Moritz Lennert (mlennert at club.worldonline.be)
+
+<p><i>Last changed: $Date$</i>
Copied: grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.py (from rev 39817, grass/trunk/scripts/v.db.addcolumn/v.db.addcol.py)
===================================================================
--- grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.py (rev 0)
+++ grass/trunk/scripts/v.db.addcolumn/v.db.addcolumn.py 2009-11-26 22:32:43 UTC (rev 39820)
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+#
+############################################################################
+#
+# MODULE: v.db.addcolumnumn
+# AUTHOR(S): Moritz Lennert
+# Converted to Python by Glynn Clements
+# PURPOSE: interface to db.execute to add a column to the attribute table
+# connected to a given vector map
+# COPYRIGHT: (C) 2005 by 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: Adds one or more columns to the attribute table connected to a given vector map.
+#% keywords: vector
+#% keywords: database
+#% keywords: attribute table
+#%End
+
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,vector,vector
+#% key_desc : name
+#% description: Vector map for which to edit attribute table
+#% required : yes
+#%end
+
+#%option
+#% key: layer
+#% type: integer
+#% description: Layer where to add column
+#% answer: 1
+#% required : no
+#%end
+
+#%option
+#% key: columns
+#% type: string
+#% description: Name and type of the new column(s) ('name type [,name type, ...]' - types depend on database backend, but all support VARCHAR(), INT, DOUBLE PRECISION and DATE)
+#% required : yes
+#%end
+
+import sys
+import os
+import grass.script as grass
+
+def main():
+ map = options['map']
+ layer = options['layer']
+ columns = options['columns']
+ columns = [col.strip() for col in columns.split(',')]
+
+ # does map exist in CURRENT mapset?
+ mapset = grass.gisenv()['MAPSET']
+ exists = bool(grass.find_file(map, element = 'vector', mapset = mapset)['file'])
+
+ if not exists:
+ grass.fatal(_("Vector map <%s> not found in current mapset") % map)
+
+ try:
+ f = grass.vector_db(map)[int(layer)]
+ except KeyError:
+ grass.fatal(_("There is no table connected to this map. Run v.db.connect or v.db.addtable first."))
+ table = f['table']
+ database = f['database']
+ driver = f['driver']
+
+ colnum = len(columns)
+
+ for col in columns:
+ if not col:
+ grass.fatal(_("There is an empty column. Did you leave a trailing comma?"))
+
+ p = grass.feed_command('db.execute', input = '-', database = database, driver = driver)
+ p.stdin.write("ALTER TABLE %s ADD COLUMN %s" % (table, col))
+ p.stdin.close()
+ if p.wait() != 0:
+ grass.fatal(_("Unable to add column <%s>.") % col)
+
+ # write cmd history:
+ grass.vector_history(map)
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
More information about the grass-commit
mailing list