#!/bin/sh ############################################################################ # # AUTHOR(S): Markus Neteler # PURPOSE: GRASS temporal data management: create decades # COPYRIGHT: (C) 2008 by Markus Neteler, 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: Calculate decades (10 days) from raster maps in in the grass sqlite database #% keywords: raster, database #%End #Only run if started in GRASS if [ -z "$GISBASE" ] ; then echo "You must be in GRASS GIS to run this program." >&2 exit 1 fi # GUI is not very useful here, skip it if no args are given if [ "$#" -gt 0 ] ; then if [ "$1" != "@ARGS_PARSED@" ] ; then exec g.parser "$0" "$@" fi else # no args given GIS_FLAG_A=0 GIS_FLAG_R=0 fi # source some library functions ### setup enviro vars ### eval `g.gisenv` : ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?} source ${GISBASE}/etc/r.rast4d/globals/defines.sh g.message "Calculating decades in table ..." echo " DROP TABLE raster_decades; CREATE TABLE raster_decades AS SELECT name, ctime, mtime, vtime_start, vtime_end, vtime_duration, year, month, day, m_decade FROM ( SELECT name, ctime, mtime, vtime_start, vtime_end, vtime_duration, substr(''||vtime_start,1,4) AS year, substr(''||vtime_start,6,2) AS month, substr(''||vtime_start,9,2) AS day, CASE substr(''||vtime_start,9,1) when '0' then 1 when '1' then 2 else 3 END AS m_decade FROM raster_time_table ) tmp GROUP BY year, month, day, m_decade ORDER BY year, month, day, m_decade;" | $GRAST4D_DBM $GRAST4D_DATABASE echo "Verify with: sqlite3 $GRAST4D_DATABASE" g.message "Done." exit 0