[GRASS-SVN] r29684 - in grass-addons: . r.rast4d r.rast4d/bin r.rast4d/globals r.rast4d/lib r.rast4d/sql

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 12 15:06:37 EST 2008


Author: neteler
Date: 2008-01-12 15:06:37 -0500 (Sat, 12 Jan 2008)
New Revision: 29684

Added:
   grass-addons/r.rast4d/
   grass-addons/r.rast4d/QuickStart.txt
   grass-addons/r.rast4d/README
   grass-addons/r.rast4d/TODO
   grass-addons/r.rast4d/bin/
   grass-addons/r.rast4d/bin/init_db.sh
   grass-addons/r.rast4d/bin/tg.list
   grass-addons/r.rast4d/bin/tg.remove
   grass-addons/r.rast4d/bin/tg.update
   grass-addons/r.rast4d/db/
   grass-addons/r.rast4d/globals/
   grass-addons/r.rast4d/globals/defines.sh
   grass-addons/r.rast4d/lib/
   grass-addons/r.rast4d/lib/TODO
   grass-addons/r.rast4d/lib/insert_raster.sh
   grass-addons/r.rast4d/lib/remove_raster.sh
   grass-addons/r.rast4d/r.rast4d.init
   grass-addons/r.rast4d/sql/
   grass-addons/r.rast4d/sql/TODO
   grass-addons/r.rast4d/sql/create_name_list_table.sql
   grass-addons/r.rast4d/sql/create_raster_categorie_table.sql
   grass-addons/r.rast4d/sql/create_raster_metadata_table.sql
   grass-addons/r.rast4d/sql/create_raster_table.sql
   grass-addons/r.rast4d/sql/create_raster_time_table.sql
   grass-addons/r.rast4d/sql/create_temporal_raster_metadata_table.sql
   grass-addons/r.rast4d/sql/create_temporal_raster_table.sql
   grass-addons/r.rast4d/test.csv
Log:
Soeren Gebbert: r.rast4d + tg.* - raster time series SQL support

Added: grass-addons/r.rast4d/QuickStart.txt
===================================================================
--- grass-addons/r.rast4d/QuickStart.txt	                        (rev 0)
+++ grass-addons/r.rast4d/QuickStart.txt	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,75 @@
+You need:
+ - grass63
+ - sqlite3
+ - a valid grass location
+and the will to read sql and bash code if an error occures :)
+
+Be sure you are in a GRASS location!
+Stay in the directoy containing the QuickStart file you are reading now,
+this is very important!
+The sqlite3 database will be created in the ./db/ directory.
+Use a graphical frontend to explore the database structure or read the 
+code in the sql directoy.
+
+* ./r.rast4d.init
+Start r.rast4d.init to create the database,
+- if the database already exists, nothing will be performed
+- if you want to create a new database just remove the one in 
+  the ./db/ directory and run r.rast4d.init again
+
+* bin/tg.update
+Use tg.update to register/update your raster maps in the sqlite table
+
+* bin/tg.list
+Use tg.list to show the registered maps, performe sql where statements on the view
+and use the order option to order your data
+
+* bin/tg.remove
+Remove the raster map entries from the database
+The maps are not removed from grass!
+
+###########################################
+
+How to upload many raster maps?
+
+The maps need to have a valid time stamp (r.timestamp).
+Then (we assume a wildcard for raster names):
+
+ for i in `g.mlist type=rast pat="rastname*"` ; do
+   bin/tg.update $i
+ done
+
+###########################################
+Sören Gebbert 	
+to Markus, me
+Apr 5 2007
+
+Fertig,
+ich habe den Prototypen hoffentlich so modifiziert dass er mit Punkten im Namen umgehen kann.
+Außerdem werden die Raster timestamps (erzeugt mit r.timestamp) ausgewertet
+und die vtime_start mit dem ersten auftretenden timestamp gesetzt.
+
+Der erste timestamp sollte vollständig sein, sonst funzt es nicht.
+Es ist ein ziemlicher Hack weil ich in Eile bin. :/
+
+Beispiel mit 4 registrierten Maps:
+
+GRASS 6.3.cvs > bin/tg.list rast select=name,vtime_start
+select name,vtime_start from raster_view where ctime > DATETIME('1950-01-01 10:00:00') order by name
+test.1.1|1999-06-08 13:10:20
+test.1.2|1999-06-09 13:10:20
+test.1.3|2000-01-14 13:10:20
+test.1.4|2000-01-24 13:10:20
+
+GRASS 6.3.cvs > r.timestamp test.1.1
+8 Jun 1999 13:10:20
+
+GRASS 6.3.cvs > r.timestamp test.1.2
+9 Jun 1999 13:10:20
+
+GRASS 6.3.cvs > r.timestamp test.1.3
+14 Jan 2000 13:10:20
+
+GRASS 6.3.cvs > r.timestamp test.1.4
+24 Jan 2000 13:10:20
+


Property changes on: grass-addons/r.rast4d/QuickStart.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: grass-addons/r.rast4d/README
===================================================================
--- grass-addons/r.rast4d/README	                        (rev 0)
+++ grass-addons/r.rast4d/README	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,15 @@
+/****************************************************************************
+ *
+ * MODULE:       r.rast4d, tg.*
+ * AUTHOR(S):    Sören Gebbert
+ * PURPOSE:      To provide SQL based time series support for raster maps.
+ *               Raster maps are registered in a SQLite table for easy retrieval
+ *
+ * COPYRIGHT:    (C) 2007 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.
+ *
+ *****************************************************************************/
+

Added: grass-addons/r.rast4d/TODO
===================================================================
--- grass-addons/r.rast4d/TODO	                        (rev 0)
+++ grass-addons/r.rast4d/TODO	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,20 @@
+The following modules must be implemented:
+ tg.copy -- to copy raster table entries + time + metadata
+ tg.rename -- rename existing raster table entries + metadata + time
+ t.info -- infos about temproal raster maps
+ t.create -- to create temporal raster maps
+ t.register -- register raster maps in the temporal datatypeas (temporal raster map)
+ t.unregister -- unregister raster maps from temporal datatypes (temporal raster map)
+
+See also: lib/TODO
+
+FIXME
+ VTIME_END: make controllable by user
+
+    lib/insert_raster.sh
+    ...
+    VTIME_START=$GLOBAL_DATE_VAR
+    VTIME_END="DATETIME('$VTIME_START', '+10 years')"
+
+    -> als Parameter in tg.update einbauen.
+

Added: grass-addons/r.rast4d/bin/init_db.sh
===================================================================
--- grass-addons/r.rast4d/bin/init_db.sh	                        (rev 0)
+++ grass-addons/r.rast4d/bin/init_db.sh	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,16 @@
+#!/bin/sh
+#this script creates the database tables needed to store raster and temporal map informations
+
+#create the raster and temporal tables
+cat $SQL_DIR/create_raster_table.sql | sed s/TABLE_NAME/$RASTER_TABLE_NAME/ | $DBM $DATABASE 
+cat $SQL_DIR/create_raster_time_table.sql | sed s/TABLE_NAME/$RASTER_TIME_TABLE_NAME/ | $DBM $DATABASE 
+cat $SQL_DIR/create_raster_metadata_table.sql | sed s/TABLE_NAME/$RASTER_METADATA_TABLE_NAME/ | $DBM $DATABASE 
+cat $SQL_DIR/create_temporal_raster_table.sql | sed s/TABLE_NAME/$TEMPORAL_RASTER_TABLE_NAME/ | $DBM $DATABASE 
+cat $SQL_DIR/create_temporal_raster_metadata_table.sql | sed s/TABLE_NAME/$TEMPORAL_RASTER_METADATA_TABLE_NAME/ | $DBM $DATABASE 
+
+# create the raster view
+echo  "create view $RASTER_VIEW_NAME as select * from $RASTER_TABLE_NAME, $RASTER_TIME_TABLE_NAME, $RASTER_METADATA_TABLE_NAME where $RASTER_TABLE_NAME.name = $RASTER_TIME_TABLE_NAME.name AND $RASTER_TABLE_NAME.name = $RASTER_TIME_TABLE_NAME.name AND $RASTER_METADATA_TABLE_NAME.name = $RASTER_TIME_TABLE_NAME.name;" | $DBM $DATABASE
+
+#register trigger functions
+
+echo "SQL tables created"


Property changes on: grass-addons/r.rast4d/bin/init_db.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: grass-addons/r.rast4d/bin/tg.list
===================================================================
--- grass-addons/r.rast4d/bin/tg.list	                        (rev 0)
+++ grass-addons/r.rast4d/bin/tg.list	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,71 @@
+#!/bin/sh
+############################################################################
+#
+# AUTHOR(S):    Soeren Gebbert soerengebbert <at> gmx <dot> de
+# PURPOSE:      grass temporal data management
+# COPYRIGHT:    (C) 2007 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: List all registered raster maps in the grass sqlite database
+#%  keywords: general, database
+#%End
+#%option
+#% key: type
+#% type: string
+#% description: Data type
+#% answer: rast
+#% options: rast
+#% required : no
+#%END
+#%option
+#% key: selection
+#% type: string
+#% description: The columns which should be selected
+#% answer: name,creator,datatype,ctime
+#% options: name,ctime,mtime,vtime_start,vtime_end,min,max,category_num,datatype,rows,cols,creator
+#% multiple: yes
+#% required : yes
+#%END
+#%option
+#% key: where
+#% type: string
+#% description: The where statement for data filtering
+#% answer: ctime > DATETIME('1950-01-01 10:00:00') 
+#% required : no
+#%END
+#%option
+#% key: order
+#% type: string
+#% description: The order of the data
+#% answer: name
+#% options: name,ctime,mtime,vtime_start,vtime_end,min,max,category_num,datatype,rows,cols,creator
+#% required : no
+#%END
+
+
+#Only run if started in GRASS
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program."
+ exit 1
+fi
+
+#Parse the arguments, if g.parser not work, skip the test's
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+  if [ $? -ne 0 ] ; then
+    echo "g.parser failed, no Test available"
+  exit 1
+  fi
+fi
+
+source globals/defines.sh
+echo "select $GIS_OPT_SELECTION from $RASTER_VIEW_NAME where $GIS_OPT_WHERE order by $GIS_OPT_ORDER"
+$DBM $DATABASE "select $GIS_OPT_SELECTION from $RASTER_VIEW_NAME where $GIS_OPT_WHERE order by $GIS_OPT_ORDER"
+
+exit 0
+


Property changes on: grass-addons/r.rast4d/bin/tg.list
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/r.rast4d/bin/tg.remove
===================================================================
--- grass-addons/r.rast4d/bin/tg.remove	                        (rev 0)
+++ grass-addons/r.rast4d/bin/tg.remove	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,55 @@
+#!/bin/sh
+############################################################################
+#
+# AUTHOR(S):    Soeren Gebbert soerengebbert <at> gmx <dot> de
+# PURPOSE:      grass temporal data management
+# COPYRIGHT:    (C) 2007 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: Register or Update raster maps in the grass sqlite database
+#%  keywords: raster, database
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Raster map to register or update
+#% required : yes
+#% multiple: yes
+#%END
+
+
+#Only run if started in GRASS
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program."
+ exit 1
+fi
+
+#Parse the arguments, if g.parser not work, skip the test's
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+  if [ $? -ne 0 ] ; then
+    echo "g.parser failed, no Test available"
+  exit 1
+  fi
+fi
+
+# source some library functions
+source lib/remove_raster.sh
+
+# remove the table entries
+for i in `echo $GIS_OPT_INPUT | sed s/,/\ /g | xargs` ; do
+  remove_raster_map $i
+  remove_raster_map_metadata $i
+  remove_raster_map_time $i
+# do not really remove the raster maps  
+#  g.remove rast=$i
+done
+
+exit 0
+


Property changes on: grass-addons/r.rast4d/bin/tg.remove
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/r.rast4d/bin/tg.update
===================================================================
--- grass-addons/r.rast4d/bin/tg.update	                        (rev 0)
+++ grass-addons/r.rast4d/bin/tg.update	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,55 @@
+#!/bin/sh
+############################################################################
+#
+# AUTHOR(S):    Soeren Gebbert soerengebbert <at> gmx <dot> de
+# PURPOSE:      grass temporal data management
+# COPYRIGHT:    (C) 2007 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: Register or Update raster maps in the grass sqlite database
+#%  keywords: raster, database
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Raster map to register or update
+#% required : yes
+#% multiple: no
+#%END
+
+
+#Only run if started in GRASS
+if [ -z "$GISBASE" ] ; then
+ echo "You must be in GRASS GIS to run this program."
+ exit 1
+fi
+
+#Parse the arguments, if g.parser not work, skip the test's
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+  exec g.parser "$0" "$@"
+  if [ $? -ne 0 ] ; then
+    echo "g.parser failed, no Test available"
+  exit 1
+  fi
+fi
+
+# source some library functions
+source lib/insert_raster.sh
+
+echo $GIS_OPT_INPUT
+
+# create/update the table entries
+for i in `echo $GIS_OPT_INPUT | sed s/,/\ /g` ; do
+  echo "processing map $i"
+  insert_raster_map $i
+  insert_raster_map_metadata $i
+  insert_raster_map_time $i
+done
+
+exit 0


Property changes on: grass-addons/r.rast4d/bin/tg.update
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/r.rast4d/globals/defines.sh
===================================================================
--- grass-addons/r.rast4d/globals/defines.sh	                        (rev 0)
+++ grass-addons/r.rast4d/globals/defines.sh	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+#definitions
+export BASE="`pwd`"
+export DB_DIR="$BASE/db"
+export BIN_DIR="$BASE/bin"
+export LIB_DIR="$BASE/lib"
+export SQL_DIR="$BASE/sql"
+export DATABASE=$DB_DIR/database.sqlite
+export PATH=$BIN_DIR:$PATH
+export DBM="sqlite3"
+
+# Table name definitions
+export RASTER_VIEW_NAME="raster_view"
+export RASTER_TABLE_NAME="raster_table"
+export RASTER_TIME_TABLE_NAME="raster_time_table"
+export RASTER_METADATA_TABLE_NAME="raster_metadata_table"
+export TEMPORAL_VIEW_NAME="temporal_view"
+export TEMPORAL_RASTER_TABLE_NAME="temporal_raster_table"
+export TEMPORAL_RASTER_METADATA_TABLE_NAME="temporal_raster_metadata_table"
+
+export RASTER_REFERENCE_TABLE_PREFIX="raster_reference_table"
+export RASTER_GROUP_TABLE_PREFIX="raster_group_table"
+export RASTER_TEMPORAL_TABLE_PREFIX="raster_temporal_table"
+export RASTER_METADATA_TABLE_PREFIX="raster_metadata_table"
+export RASTER_CATEGORY_TABLE_PREFIX="raster_category_table"
+


Property changes on: grass-addons/r.rast4d/globals/defines.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: grass-addons/r.rast4d/lib/TODO
===================================================================
--- grass-addons/r.rast4d/lib/TODO	                        (rev 0)
+++ grass-addons/r.rast4d/lib/TODO	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,4 @@
+* functions for renaming raster maps and temporal raster maps 
+* functions to create and remove temporal raster maps 
+* functions to fill the metadata, categorie, group and temproal table with data
+

Added: grass-addons/r.rast4d/lib/insert_raster.sh
===================================================================
--- grass-addons/r.rast4d/lib/insert_raster.sh	                        (rev 0)
+++ grass-addons/r.rast4d/lib/insert_raster.sh	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,205 @@
+#!/bin/sh
+# functions to insert or update raster map entries to the grass sql database 
+
+source globals/defines.sh
+
+#this var is used to store the computed sqlite timestamps
+GLOBAL_DATE_VAR="" 
+
+#pasre the grass date format and convert it into sqlite date format
+parse_timestamp() #arguments are DAY MONTH YEAR TIME
+{
+DAY=$1
+MONTH=$2
+YEAR=$3
+TIME=$4
+
+# change the month to MM!!!! :/
+MONTH=`echo $MONTH | sed s/Jan/01/`
+MONTH=`echo $MONTH | sed s/Feb/02/`
+MONTH=`echo $MONTH | sed s/Mar/03/`
+MONTH=`echo $MONTH | sed s/Apr/04/`
+MONTH=`echo $MONTH | sed s/May/05/`
+MONTH=`echo $MONTH | sed s/Jun/06/`
+MONTH=`echo $MONTH | sed s/Jul/07/`
+MONTH=`echo $MONTH | sed s/Aug/08/`
+MONTH=`echo $MONTH | sed s/Sep/09/`
+MONTH=`echo $MONTH | sed s/Oct/10/`
+MONTH=`echo $MONTH | sed s/Nov/11/`
+MONTH=`echo $MONTH | sed s/Dec/12/`
+#change the day to DD
+if [ `expr $DAY \< 10` -eq 1 ] ; then
+DAY="0$DAY"
+fi
+
+GLOBAL_DATE_VAR="$YEAR-$MONTH-$DAY $TIME"
+}
+
+
+# insert or update a raster map entry in the raster map table
+insert_raster_map () 
+{
+MAPNAME=$1
+BASE_MAP=""
+COLOR="unknown"
+CAT_NUM=""
+GROUP_TABLE="${RASTER_GROUP_TABLE_PREFIX}_${MAPNAME}"
+REFERENCE_TABLE="${RASTER_REFERENCE_TABLE_PREFIX}_${MAPNAME}"
+METADATA_TABLE="${RASTER_METADATA_TABLE_PREFIX}_${MAPNAME}"
+CATEGORY_TABLE="${RASTER_CATEGORY_TABLE_PREFIX}_${MAPNAME}"
+TEMPORAL_TABLE="${RASTER_TEMPORAL_TABLE_PREFIX}_${MAPNAME}"
+
+# get the number of cats
+CAT_NUM=`r.info $MAPNAME | grep "Categories:" | awk '{print $9}'` 
+
+# create or update the database table
+STRING=`$DBM $DATABASE "select name from $RASTER_TABLE_NAME where name='$MAPNAME'"`
+if [ "$STRING" = "" ] ; then
+  echo "INSERT NEW $RASTER_TABLE_NAME ENTRY $MAPNAME"
+
+  SQL_DATATYPE_STRING="(name, base_map, reference_table, color, group_table, temporal_table, metadata_table, category_table, category_num)"
+  SQL_VALUE_STRING="('$MAPNAME', '$BASE_MAP', '$REFERENCE_TABLE','$COLOR', '$GROUP_TABLE', '$TEMPORAL_TABLE', '$METADATA_TABLE', '$CATEGORY_TABLE', '$CAT_NUM')"
+
+  $DBM $DATABASE "INSERT INTO $RASTER_TABLE_NAME $SQL_DATATYPE_STRING values $SQL_VALUE_STRING"
+
+  #create the raster map tables
+  #cat $SQL_DIR/create_name_list_table.sql | sed s/TABLE_NAME/$REFERENCE_TABLE/ | $DBM $DATABASE 
+  #cat $SQL_DIR/create_name_list_table.sql | sed s/TABLE_NAME/$GROUP_TABLE/ | $DBM $DATABASE 
+  #cat $SQL_DIR/create_name_list_table.sql | sed s/TABLE_NAME/$TEMPORAL_TABLE/ | $DBM $DATABASE 
+  #cat $SQL_DIR/create_raster_metadata_table.sql | sed s/TABLE_NAME/$METADATA_TABLE/ | $DBM $DATABASE 
+  #cat $SQL_DIR/create_raster_categorie_table.sql | sed s/TABLE_NAME/$CATEGORY_TABLE/ | $DBM $DATABASE 
+
+else
+  echo "UPDATE $RASTER_TABLE_NAME ENTRY $MAPNAME"
+  $DBM $DATABASE "UPDATE $RASTER_TABLE_NAME SET base_map='$BASE_MAP' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $RASTER_TABLE_NAME SET color='$COLOR' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $RASTER_TABLE_NAME SET category_num='$CAT_NUM' WHERE name='$MAPNAME'"
+fi
+}
+
+#insert or update an entry in the global raster metadata table
+insert_raster_map_metadata ()
+{
+MAPNAME=$1
+METADATA_TABLE="${RASTER_METADATA_TABLE_NAME}"
+PROJECTION=`g.proj -w`
+ROWS=`r.info $MAPNAME | grep "Rows:" | awk '{print $3}'`
+COLS=`r.info $MAPNAME | grep "Columns" | awk '{print $3}'`
+CELLNUM=`r.info $MAPNAME | grep "Total Cells:" | awk '{print $4}'`
+eval `r.info -t $MAPNAME`
+eval `r.info -g $MAPNAME`
+eval `r.info -s $MAPNAME`
+eval `r.info -r $MAPNAME`
+CREATOR=`r.info $MAPNAME | grep "Login of Creator:" | awk '{print $7}'`
+MTIME="DATETIME('NOW')"
+COMMENTS=`r.info -h $MAPNAME`
+DATA_SOURCE=""
+DESCRIPTION=""
+ADDITIONAL_DATA=""
+
+#echo $MAPNAME
+#echo $METADATA_TABLE
+#echo $PROJECTION
+#echo $ROWS
+#echo $COLS
+#echo $CELLNUM
+#echo $datatype
+#echo $north
+#echo $south
+#echo $west
+#echo $east
+#echo $nsres
+#echo $ewres
+#echo $min
+#echo $max
+#echo $CREATOR
+#echo $MTIME
+#echo $DATA_SOURCE
+#echo $COMMENTS
+#echo $DESCRIPTION
+#echo $ADDITIONAL_DATA
+
+
+# insert or update
+STRING=`$DBM $DATABASE "select name from $METADATA_TABLE where name='$MAPNAME'"` 
+if [ "$STRING" = "" ] ; then
+  echo "INSERT NEW $METADATA_TABLE ENTRY $MAPNAME"
+  SQL_DATATYPE_STRING="(name, projection, datatype, rows, cols, cell_num, north, south, west, east, ns_res,
+		      ew_res, min, max, mtime, creator, data_source, comments, description, additional_data)"
+  SQL_VALUE_STRING="('$MAPNAME', '$PROJECTION', '$datatype', '$ROWS', '$COLS', '$CELLNUM', '$north', '$south', '$west', '$east', 
+		   '$nsres' , '$ewres', '$min', '$max', $MTIME, '$CREATOR', '$DATA_SOURCE', '$COMMENTS', '$DESCRIPTION' , '$ADDITIONAL_DATA')"  
+  $DBM $DATABASE "INSERT INTO $METADATA_TABLE $SQL_DATATYPE_STRING values $SQL_VALUE_STRING"
+else
+  echo "UPDATE $METADATA_TABLE ENTRY $MAPNAME"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET projection='$PROJECTION' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET datatype='$datatype' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET rows='$ROWS' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET cols='$COLS' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET cell_num='$CELLNUM' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET north='$north' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET south='$south' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET west='$west' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET east='$east' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET ns_res='$nsres' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET ew_res='$ewres' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET min='$min' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET max='$max' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET mtime=$MTIME WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET creator='$CREATOR' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET data_source='$DATA_SOURCE' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET comments='$COMMENTS' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET description='$DESCRIPTION' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $METADATA_TABLE SET additional_data='$ADDITIONAL_DATA' WHERE name='$MAPNAME'"
+fi
+
+}
+
+# insert or update a raster map entry in the raster map time table
+insert_raster_map_time () 
+{
+MAPNAME=$1
+YEAR=`r.info $MAPNAME | grep Date: | awk '{print $9}'`
+MONTH=`r.info $MAPNAME | grep Date: | awk '{print $6}'`
+DAY=`r.info $MAPNAME | grep Date: | awk '{print $7}'`
+TIME=`r.info $MAPNAME | grep Date: | awk '{print $8}'`
+
+# the sqlite3 time format is YYYY-MM-DD HH:MM:SS
+parse_timestamp $DAY $MONTH $YEAR $TIME 
+CTIME=$GLOBAL_DATE_VAR
+MTIME="DATETIME('NOW')"
+
+#the real grass timestamps
+DAY=`r.timestamp $MAPNAME | awk '{print $1}'`
+MONTH=`r.timestamp $MAPNAME | awk '{print $2}'` 
+YEAR=`r.timestamp $MAPNAME | awk '{print $3}'` 
+TIME=`r.timestamp $MAPNAME | awk '{print $4}'` 
+# the sqlite3 time format is YYYY-MM-DD HH:MM:SS
+parse_timestamp $DAY $MONTH $YEAR $TIME 
+VTIME_START=$GLOBAL_DATE_VAR
+VTIME_END="DATETIME('$VTIME_START', '+10 years')"
+
+#echo $CTIME
+#echo $MTIME
+#echo $VTIME_START
+#echo $VTIME_END
+
+# insert or update 
+STRING=`$DBM $DATABASE "select name from $RASTER_TIME_TABLE_NAME where name='$MAPNAME'"`
+if [ "$STRING" = "" ] ; then
+  echo "INSERT NEW $RASTER_TIME_TABLE_NAME ENTRY $MAPNAME"
+
+  SQL_DATATYPE_STRING="(name, ctime, mtime, vtime_start, vtime_end)"
+  SQL_VALUE_STRING="('$MAPNAME', '$CTIME', $MTIME, '$VTIME_START', $VTIME_END)"
+
+  $DBM $DATABASE "INSERT INTO $RASTER_TIME_TABLE_NAME $SQL_DATATYPE_STRING values $SQL_VALUE_STRING"
+
+else
+  echo "UPDATE $RASTER_TIME_TABLE_NAME ENTRY $MAPNAME"
+  $DBM $DATABASE "UPDATE $RASTER_TIME_TABLE_NAME SET ctime='$CTIME' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $RASTER_TIME_TABLE_NAME SET mtime=$MTIME WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $RASTER_TIME_TABLE_NAME SET vtime_start='$VTIME_START' WHERE name='$MAPNAME'"
+  $DBM $DATABASE "UPDATE $RASTER_TIME_TABLE_NAME SET vtime_end=$VTIME_END WHERE name='$MAPNAME'"
+fi
+exit
+}
+


Property changes on: grass-addons/r.rast4d/lib/insert_raster.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: grass-addons/r.rast4d/lib/remove_raster.sh
===================================================================
--- grass-addons/r.rast4d/lib/remove_raster.sh	                        (rev 0)
+++ grass-addons/r.rast4d/lib/remove_raster.sh	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,38 @@
+#!/bin/sh
+# functions to remove raster map entries to the grass sql database 
+
+source globals/defines.sh
+
+remove_raster_map () 
+{
+MAPNAME=$1
+GROUP_TABLE="${RASTER_GROUP_TABLE_PREFIX}_${MAPNAME}"
+REFERENCE_TABLE="${RASTER_REFERENCE_TABLE_PREFIX}_${MAPNAME}"
+METADATA_TABLE="${RASTER_METADATA_TABLE_PREFIX}_${MAPNAME}"
+CATEGORY_TABLE="${RASTER_CATEGORY_TABLE_PREFIX}_${MAPNAME}"
+TEMPORAL_TABLE="${RASTER_TEMPORAL_TABLE_PREFIX}_${MAPNAME}"
+
+#$DBM $DATABASE "DROP TABLE $REFERENCE_TABLE"
+#$DBM $DATABASE "DROP TABLE $METADATA_TABLE"
+#$DBM $DATABASE "DROP TABLE $GROUP_TABLE"
+#$DBM $DATABASE "DROP TABLE $CATEGORY_TABLE"
+#$DBM $DATABASE "DROP TABLE $TEMPORAL_TABLE"
+
+echo "REMOVE $MAPNAME FROM $RASTER_TABLE_NAME"
+$DBM $DATABASE "DELETE FROM $RASTER_TABLE_NAME  WHERE name='$MAPNAME'"
+
+}
+
+remove_raster_map_metadata ()
+{
+MAPNAME=$1
+echo "REMOVE $MAPNAME FROM $RASTER_METADATA_TABLE_NAME"
+$DBM $DATABASE "DELETE FROM $RASTER_METADATA_TABLE_NAME  WHERE name='$MAPNAME'"
+}
+
+remove_raster_map_time () 
+{
+MAPNAME=$1
+echo "REMOVE $MAPNAME FROM $RASTER_TIME_TABLE_NAME"
+$DBM $DATABASE "DELETE FROM $RASTER_TIME_TABLE_NAME  WHERE name='$MAPNAME'"
+}


Property changes on: grass-addons/r.rast4d/lib/remove_raster.sh
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:eol-style
   + native

Added: grass-addons/r.rast4d/r.rast4d.init
===================================================================
--- grass-addons/r.rast4d/r.rast4d.init	                        (rev 0)
+++ grass-addons/r.rast4d/r.rast4d.init	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+source globals/defines.sh
+
+if [ ! -f $DATABASE ]
+  then
+  init_db.sh
+else
+  echo "$DATABASE already exists. Doing nothing. Remove that DB file to start over"
+fi


Property changes on: grass-addons/r.rast4d/r.rast4d.init
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/r.rast4d/sql/TODO
===================================================================
--- grass-addons/r.rast4d/sql/TODO	                        (rev 0)
+++ grass-addons/r.rast4d/sql/TODO	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,5 @@
+* Trigger functions
+* Support for groups
+* Support for volume maps
+* support for vector maps
+and a lot more stuff

Added: grass-addons/r.rast4d/sql/create_name_list_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_name_list_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_name_list_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,5 @@
+-- a simple table stroing strings
+-- this is used for group name tables, temproal name tables and so on
+CREATE TABLE TABLE_NAME (name VARCHAR(256) PRIMARY KEY);
+                          
+

Added: grass-addons/r.rast4d/sql/create_raster_categorie_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_raster_categorie_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_raster_categorie_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,9 @@
+-- This script will create the table managing all categories of a raster maps 
+-- this table should be altered if additional category columns are needed
+-- the specific column should be selected with a where statement, by default the column
+-- named "label" should be used
+CREATE TABLE TABLE_NAME (cat INTEGER PRIMARY KEY, -- the category number 
+			 value NUMERIC(25,15), -- the numerical value of the raster map using this category
+			 label VARCHAR(500) -- the label of the category
+                        );
+

Added: grass-addons/r.rast4d/sql/create_raster_metadata_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_raster_metadata_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_raster_metadata_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,26 @@
+-- This script will create the table managing the metadata of one raster map
+CREATE TABLE TABLE_NAME (name VARCHAR(256) PRIMARY KEY, -- the name of the raster map
+                         projection CLOB , -- Projection information
+                         datatype VARCHAR(30), -- the map data type
+			 rows INTEGER, -- the number of rows
+			 cols INTEGER, -- the number of columns
+			 cell_num INTEGER, -- the number of cell
+			 north NUMERIC(15,10), -- coordinates of the northern edge
+			 south NUMERIC(15,10), -- coordinates of the southern edge
+			 west NUMERIC(15,10), -- coordinates of the western edge
+			 east NUMERIC(15,10), -- coordinates of the eastern edge
+			 ns_res NUMERIC(15,10), -- resolution in north/south direction
+			 ew_res NUMERIC(15,10), -- resolution in east/west direction
+			 min NUMERIC(25,15), --the minimum value
+			 max NUMERIC(25,15), --the maximum value
+			 mtime DATE, -- the modification time of the current entry
+			 creator VARCHAR(30), -- the login of the creator
+                         data_source CLOB , -- the source of the raster map
+                         comments CLOB , -- comments 
+                         description CLOB , -- the raster map description
+                         additional_data CLOB -- further metadata
+                        );
+-- this table is created once for all existing raster maps containing the actual metadata information
+-- and this table is created each time a new raster map is created containing the history of metadata
+-- for each update a new row of metadata will be added to create a history of metadata changes
+-- the table name is a combination of the raster map name and the suffix metadata 

Added: grass-addons/r.rast4d/sql/create_raster_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_raster_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_raster_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,22 @@
+-- This script will create the table managing all raster maps of grass
+-- inclusively categories, color tables, metadata and links to temporal data types
+CREATE TABLE TABLE_NAME (name VARCHAR(256) PRIMARY KEY,
+                         base_map VARCHAR(256) , -- the map of which this map is based on
+                         reference_table VARCHAR(300), -- the table containing all raster map names which are using this map as base map
+			 color CLOB, -- the color information is stored as CLOB
+                         group_table VARCHAR(300), -- the table containing all group names in which this raster map is registered
+                         temporal_table VARCHAR(300), -- the table containing all temporal raster map names 
+			 			      -- in which this raster map is registered
+                         metadata_table VARCHAR(300), -- the table containing the metadata history list (one row for each update)
+                         category_table VARCHAR(300), -- the category table
+                         category_num INTEGER -- number of categories
+                        );
+-- the names of the data tables are a combination of 
+-- the raster map name, which must be unique and the 
+-- table eg.: 
+-- if map name is slope the data tables will have the following names:
+--	raster_reference_table_slope
+--	raster_group_table_slope
+--	raster_metadata_table_slope
+-- 	raster_temporal_table_slope
+--	raster_category_table_slope

Added: grass-addons/r.rast4d/sql/create_raster_time_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_raster_time_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_raster_time_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,11 @@
+-- this table will list all raster maps 
+-- every time a raster map was created an entry will be 
+-- made setting the creation and modification time
+CREATE TABLE TABLE_NAME (name VARCHAR(256) PRIMARY KEY,
+                         ctime DATE, -- creation time
+                         mtime DATE, -- modification time
+                         vtime_start DATE, -- start valid time
+                         vtime_end DATE, -- end valid time
+			 vtime_duration DATE -- the duration time
+                        );
+

Added: grass-addons/r.rast4d/sql/create_temporal_raster_metadata_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_temporal_raster_metadata_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_temporal_raster_metadata_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,35 @@
+-- This script will create the table managing the metadata of one temporal raster map
+-- the temporal raster map region is used with all registered raster map, independently which kind of region
+-- the registered raster maps have
+CREATE TABLE TABLE_NAME (name VARCHAR(256) PRIMARY KEY, -- the name of the temporal raster map
+                         projection CLOB , -- Projection information for this temporal data type
+                         vtime_start DATE, -- start valid time
+                         vtime_end DATE, -- end valid time
+			 vtime_duration DATE, -- the duration time
+			 time_step DATE, -- the time step
+                         ctime DATE, -- creation time
+                         mtime DATE, -- modification time
+                         datatype VARCHAR(30), -- the temporal map data type
+			 rows INTEGER, -- the number of rows of the temporal region
+			 cols INTEGER, -- the number of columns  of the temporal region
+			 raster_num INTEGER, -- the number of registered raster maps
+			 cell_num INTEGER, -- the number of temporal cell (rows * cols * raster_num)
+			 north NUMERIC(15,10), -- coordinates of the northern edge
+			 south NUMERIC(15,10), -- coordinates of the southern edge
+			 west NUMERIC(15,10), -- coordinates of the western edge
+			 east NUMERIC(15,10), -- coordinates of the eastern edge
+			 ns_res NUMERIC(15,10), -- resolution in north/south direction
+			 ew_res NUMERIC(15,10), -- resolution in east/west direction
+			 min NUMERIC(25,15), --the minimum value
+			 max NUMERIC(25,15), --the maximum value
+			 modification_time DATE, -- the modification time of the current temporal map 
+			 creator VARCHAR(30), -- the login of the creator
+                         data_source CLOB , -- the source of the temporal raster map
+                         comments CLOB , -- comments 
+                         description CLOB , -- the temporal raster map description
+                         additonal_data CLOB -- further metadata
+                        );
+-- this table is created once for all existing raster maps containing the actual metadata information
+-- and this table is created each time a new raster map is created containing the history of metadata
+-- for each update a new row of metadata will be added to create a history of metadata changes
+-- this table name is a combination of the temporal raster map name and the suffix temporal_metadata 

Added: grass-addons/r.rast4d/sql/create_temporal_raster_table.sql
===================================================================
--- grass-addons/r.rast4d/sql/create_temporal_raster_table.sql	                        (rev 0)
+++ grass-addons/r.rast4d/sql/create_temporal_raster_table.sql	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,12 @@
+-- This script will create the table managing all temporal raster datatypes of grass
+-- inclusively metadata 
+ 
+CREATE TABLE TABLE_NAME (name VARCHAR(256) PRIMARY KEY, -- name of the temporal raster table
+                         raster_map_table VARCHAR(300), -- the table containing the list of all registered raster maps
+                         metadata_table VARCHAR(300) -- the table containing the metadata list (one row for each update)
+			);
+-- the names of the data tables are a combination of 
+-- the raster map name, which must be unique and the 
+-- table eg.: 
+-- if map name is slope the data tables will have the following names:
+--	temporal_metadata_table_slope

Added: grass-addons/r.rast4d/test.csv
===================================================================
--- grass-addons/r.rast4d/test.csv	                        (rev 0)
+++ grass-addons/r.rast4d/test.csv	2008-01-12 20:06:37 UTC (rev 29684)
@@ -0,0 +1,21 @@
+year|month|m_decade|obs_m_decade_days|precip_mean_daily_md|precip_days_md|tmin_mean_md|obs_tmin_mean_md|tmax_mean_md|obs_tmax_mean_md
+1961|1|1|10|6.2|6|2.5|10|6.8|10
+1961|1|2|10|6.48|3|-0.7|10|5.2|10
+1961|1|3|11|0.04|2|-1.27|11|4.82|11
+1961|2|1|10|2.2|3|1.3|10|8.7|10
+1961|2|2|10|0|0|3.6|10|14.4|10
+1961|2|3|8|0|0|4.25|8|13.63|8
+1961|3|1|10|0.22|2|4.9|10|16.5|10
+1961|3|2|10|1.6|2|7.1|10|18.4|10
+1961|3|3|11|0|0|4.45|11|14.82|11
+1961|4|1|10|2.62|5|11|10|19.1|10
+1961|4|2|10|5.74|7|11.5|10|20.8|10
+1961|4|3|10|5.9|8|11.5|10|19.8|10
+1961|5|1|10|5.6|4|12.5|10|22.7|10
+1961|5|2|10|3.38|3|10.2|10|20.3|10
+1961|5|3|11|10.73|8|12.18|11|21.18|11
+1961|6|1|10|7.88|9|14.1|10|22.3|10
+1961|6|2|10|3.38|5|16.1|10|26.6|10
+1961|6|3|10|11.34|4|18.7|10|29.6|10
+1961|7|1|10|2.54|1|17.2|10|27.5|10
+1961|7|2|10|8.56|7|16.1|10|26.1|10



More information about the grass-commit mailing list