[GRASS-SVN] r50286 - in grass/trunk/temporal: . t.connect tr.register

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jan 18 19:32:44 EST 2012


Author: huhabla
Date: 2012-01-18 16:32:44 -0800 (Wed, 18 Jan 2012)
New Revision: 50286

Added:
   grass/trunk/temporal/t.connect/
   grass/trunk/temporal/t.connect/Makefile
   grass/trunk/temporal/t.connect/main.c
   grass/trunk/temporal/t.connect/t.connect.html
Modified:
   grass/trunk/temporal/Makefile
   grass/trunk/temporal/tr.register/test.tr.register.sh
Log:
New module to specify the TGIS database connection


Modified: grass/trunk/temporal/Makefile
===================================================================
--- grass/trunk/temporal/Makefile	2012-01-19 00:12:10 UTC (rev 50285)
+++ grass/trunk/temporal/Makefile	2012-01-19 00:32:44 UTC (rev 50286)
@@ -1,6 +1,7 @@
 MODULE_TOPDIR = ..
 
 SUBDIRS = \
+	t.connect \
 	t.create \
 	t.support \
 	t.topology \

Added: grass/trunk/temporal/t.connect/Makefile
===================================================================
--- grass/trunk/temporal/t.connect/Makefile	                        (rev 0)
+++ grass/trunk/temporal/t.connect/Makefile	2012-01-19 00:32:44 UTC (rev 50286)
@@ -0,0 +1,12 @@
+
+MODULE_TOPDIR = ../..
+
+LIBES = $(TEMPORALLIB) $(DBMILIB) $(GISLIB)
+DEPENDENCIES = $(TEMPORALDEP) $(DBMIDEP) $(GISDEP)
+
+PGM = t.connect
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
+

Added: grass/trunk/temporal/t.connect/main.c
===================================================================
--- grass/trunk/temporal/t.connect/main.c	                        (rev 0)
+++ grass/trunk/temporal/t.connect/main.c	2012-01-19 00:32:44 UTC (rev 50286)
@@ -0,0 +1,155 @@
+
+/****************************************************************************
+ *
+ * MODULE:       db.connect
+ * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
+ *               Alex Shevlakov <sixote yahoo.com>, 
+ *               Glynn Clements <glynn gclements.plus.com>,
+ *               Markus Neteler <neteler itc.it>,
+ *               Hamish Bowman <hamish_b yahoo com>
+ *               Martin Landa <landa.martin gmail.com> ('d' flag)
+ * PURPOSE:      set parameters for connection to database
+ * COPYRIGHT:    (C) 2002-2010 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.
+ *
+ *****************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/temporal.h>
+#include <grass/glocale.h>
+
+int main(int argc, char *argv[])
+{
+    dbConnection conn;
+    struct Flag *print, *check_set_default, *def, *sh;
+    struct Option *driver, *database;
+    struct GModule *module;
+
+    /* Initialize the GIS calls */
+    G_gisinit(argv[0]);
+
+    /* Set description */
+    module = G_define_module();
+    G_add_keyword(_("database"));
+    G_add_keyword(_("attribute table"));
+    G_add_keyword(_("connection settings"));
+    module->description =
+	_("Prints/sets general TGIS DB connection for current mapset.");
+
+    print = G_define_flag();
+    print->key = 'p';
+    print->description = _("Print current connection parameters and exit");
+    print->guisection = _("Print");
+
+    check_set_default = G_define_flag();
+    check_set_default->key = 'c';
+    check_set_default->description =
+	_("Check connection parameters, set if uninitialized, and exit");
+    check_set_default->guisection = _("Set");
+    
+    def = G_define_flag();
+    def->key = 'd';
+    def->label = _("Set from default settings and exit");
+    def->description = _("Overwrite current settings if initialized");
+    def->guisection = _("Set");
+    
+    sh = G_define_flag();
+    sh->key = 'g';
+    sh->description = _("Print current connection parameter in shell style and exit");
+    sh->guisection = _("Set");
+
+    driver = G_define_standard_option(G_OPT_DB_DRIVER);
+    driver->options = "sqlite,pg";
+    driver->answer = (char *) tgis_get_default_driver_name();
+    driver->guisection = _("Set");
+
+    database = G_define_standard_option(G_OPT_DB_DATABASE);
+    database->answer = (char *) tgis_get_default_database_name();
+    database->guisection = _("Set");
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+    if (print->answer) {
+        if(sh->answer) {
+            if (tgis_get_connection(&conn) == DB_OK) {
+                fprintf(stdout, "driver=%s\n",
+                        conn.driverName ? conn.driverName : "");
+                fprintf(stdout, "database=%s\n",
+                        conn.databaseName ? conn.databaseName : "");
+            }
+            else
+                G_fatal_error(_("Temporal GIS database connection not defined. "
+                                "Run t.connect."));
+
+        } else {
+	/* get and print connection */
+            if (tgis_get_connection(&conn) == DB_OK) {
+                fprintf(stdout, "driver:%s\n",
+                        conn.driverName ? conn.driverName : "");
+                fprintf(stdout, "database:%s\n",
+                        conn.databaseName ? conn.databaseName : "");
+            }
+            else
+                G_fatal_error(_("Temporal GIS database connection not defined. "
+                                "Run t.connect."));
+        }
+
+	exit(EXIT_SUCCESS);
+    }
+
+    if (check_set_default->answer) {
+	/* check connection and set to system-wide default in required */
+	tgis_get_connection(&conn);
+
+	if (!conn.driverName && !conn.databaseName) {
+
+	    tgis_set_default_connection();
+	    tgis_get_connection(&conn);
+
+	    G_important_message(_("Default TGIS driver / database set to:\n"
+				  "driver: %s\ndatabase: %s"), conn.driverName,
+				conn.databaseName);
+	}
+	/* they must be a matched pair, so if one is set but not the other
+	   then give up and let the user figure it out */
+	else if (!conn.driverName) {
+	    G_fatal_error(_("Default TGIS driver is not set"));
+	}
+	else if (!conn.databaseName) {
+	    G_fatal_error(_("Default TGIS database is not set"));
+	}
+
+	/* connection either already existed or now exists */
+	exit(EXIT_SUCCESS);
+    }
+
+
+    if (def->answer) {
+	tgis_set_default_connection();
+	tgis_get_connection(&conn);
+	
+	G_important_message(_("Default driver / database set to:\n"
+			      "driver: %s\ndatabase: %s"), conn.driverName,
+			    conn.databaseName);
+	exit(EXIT_SUCCESS);
+    }
+    
+    /* set connection */
+    tgis_get_connection(&conn);	/* read current */
+
+    if (driver->answer)
+	conn.driverName = driver->answer;
+
+    if (database->answer)
+	conn.databaseName = database->answer;
+
+    tgis_set_connection(&conn);
+
+    exit(EXIT_SUCCESS);
+}

Added: grass/trunk/temporal/t.connect/t.connect.html
===================================================================
--- grass/trunk/temporal/t.connect/t.connect.html	                        (rev 0)
+++ grass/trunk/temporal/t.connect/t.connect.html	2012-01-19 00:32:44 UTC (rev 50286)
@@ -0,0 +1,44 @@
+<h2>DESCRIPTION</h2>
+
+<em>t.connect</em> allows the user to set the temporal GIS database connection.
+
+<h2>NOTES</h2>
+
+Values are stored in the mapset's <tt>VAR</tt> file;
+the connection is not tested for validity.
+<p>The <b>-d</b> flag will set the default TGIS connection parameters. 
+A sqlite3 database "tgis.db" will be created in the PERMANET directory of the current location.
+<p>The <b>-p</b> flag will display the current TGIS connection parameters. 
+<p>The <b>-pg</b> flag will display the current TGIS connection parameters using shell style. 
+<p>The <b>-c</b> flag will silently check if the TGIS connection parameters have
+been set, and if not will set them to use GRASS's default values.
+
+<h2>Note</h2>
+The default TGIS database of type sqlite3 is located in the PERMANENT mapset directory.
+Temporal GIS content from all created mapsets will be stored here. In case
+you have thousends of maps to register in the temporal database or you need concurrent read 
+and write access in the TGIS database, consider to use a postgresql database instead.
+
+<h3>SQLite</h3>
+
+<div class="code"><pre>
+t.connect driver=sqlite database='$GISDBASE/$LOCATION_NAME/PERMANENT/tgis.db'
+t.connect -p
+t.info -s
+</pre></div>
+<p>The SQLite database is created automatically when used the first time.
+
+<h3>PostgreSQL</h3>
+In case you use a postgresql database, you will need to specify the TGIS database connection 
+for each mapset.
+<div class="code"><pre>
+t.connect driver=pg database="dbname=grass_test user=soeren password=abcdefgh"
+t.connect -p
+t.info -s
+</pre></div>
+
+<h2>AUTHOR</h2>
+
+Soeren Gebbert, vTI/AK Braunschweig
+
+<p><i>Last changed: $Date: 2011-11-08 22:24:20 +0100 (Di, 08. Nov 2011) $</i>

Modified: grass/trunk/temporal/tr.register/test.tr.register.sh
===================================================================
--- grass/trunk/temporal/tr.register/test.tr.register.sh	2012-01-19 00:12:10 UTC (rev 50285)
+++ grass/trunk/temporal/tr.register/test.tr.register.sh	2012-01-19 00:32:44 UTC (rev 50286)
@@ -78,7 +78,7 @@
 tr.register input=precip_abs7 maps=prec_1,prec_2,prec_3,prec_4,prec_5,prec_6 start="2001-01-01" end="2002-01-01"
 t.info -g type=strds input=precip_abs7
 tr.list input=precip_abs7
-t.topology -t input=precip_abs7
+t.topology input=precip_abs7
 
 t.remove type=rast input=prec_1,prec_2,prec_3
 t.remove type=strds input=precip_abs1,precip_abs2,precip_abs3,precip_abs4,precip_abs5,precip_abs6,precip_abs7



More information about the grass-commit mailing list