[GRASS-SVN] r34843 - in grass-addons/raster: . r.convert

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 13 04:12:04 EST 2008


Author: hamish
Date: 2008-12-13 04:12:03 -0500 (Sat, 13 Dec 2008)
New Revision: 34843

Added:
   grass-addons/raster/r.convert/
   grass-addons/raster/r.convert/r.convert
   grass-addons/raster/r.convert/r.convert.all
Log:
scritps for converting raster maps into experimental GRASS 7 file layout, and back (trac #82)

Added: grass-addons/raster/r.convert/r.convert
===================================================================
--- grass-addons/raster/r.convert/r.convert	                        (rev 0)
+++ grass-addons/raster/r.convert/r.convert	2008-12-13 09:12:03 UTC (rev 34843)
@@ -0,0 +1,178 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       r.convert
+# AUTHOR:       M. Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE:      Converts a GRASS 4-6 raster map to a GRASS 7 raster map
+#		  *** EXPERIMENTAL GRASS 7 RASTER DIR FILE LAYOUT ***
+#
+# COPYRIGHT:    (c) 2007 Hamish Bowman, 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: Converts a GRASS 4-6 raster map to a GRASS 7 raster map format
+#% keywords: raster, import, conversion
+#%end
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of input raster map
+#% required: yes
+#%end
+#%flag
+#%  key: m
+#%  description: Move map instead of copying it
+#%end
+#%flag
+#%  key: r
+#%  description: Reverse action: Convert from GRASS 7 to GRASS 4-6 format
+#%end
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+LOCATION="$GISDBASE"/"$LOCATION_NAME"/"$MAPSET"
+
+cd "$LOCATION"
+
+
+# to copy or move?
+if [ $GIS_FLAG_M -eq 0 ] ; then
+   MVCMD="cp"
+else
+   MVCMD="mv"
+fi
+
+
+if [ $GIS_FLAG_R -eq 0 ] ; then
+
+    # make new $MAPSET/raster/ dir if needed
+    if [ ! -e raster ] ; then
+	mkdir raster
+    fi
+    if [ ! -d raster ] ; then
+	echo "ERROR: Could not convert map." 1>&2
+	exit 1
+    fi
+
+    g.findfile element=cell mapset=. file="$GIS_OPT_MAP" > /dev/null
+    if [ $? -ne 0 ] ; then
+	echo "Raster map <$GIS_OPT_MAP> not found in current mapset." 1>&2
+	exit 1
+    fi
+
+    # make new $MAPSET/raster/$MAPNAME dir
+    if [ ! -e "raster/$GIS_OPT_MAP" ] ; then
+	mkdir "raster/$GIS_OPT_MAP"
+    fi
+    if [ ! -d "raster/$GIS_OPT_MAP" ] ; then
+	echo "ERROR: Could not convert map." 1>&2
+	exit 1
+    fi
+
+    for ELEMENT in cats cell cellhd colr fcell grid3 hist ; do
+	if [ -e "$ELEMENT/$GIS_OPT_MAP" ] ; then
+	    $MVCMD "$ELEMENT/$GIS_OPT_MAP" "raster/$GIS_OPT_MAP/$ELEMENT"
+	    if  [ $? -ne 0 ] ; then
+		echo "ERROR converting map. (element: $ELEMENT)" 1>&2
+		exit 1
+	    fi
+	fi
+    done
+
+    if [ -d "cell_misc/$GIS_OPT_MAP/" ] ; then
+	$MVCMD "cell_misc/$GIS_OPT_MAP"/* "raster/$GIS_OPT_MAP/"
+	if  [ $? -ne 0 ] ; then
+	    echo "ERROR converting map. (element: cell_misc/)" 1>&2
+	    exit 1
+	fi
+
+	if [ $GIS_FLAG_M -eq 1 ] ; then
+	    rmdir "cell_misc/$GIS_OPT_MAP/"
+	    if  [ $? -ne 0 ] ; then
+		echo "WARNING: problem removing old map. (element: cell_misc/)" 1>&2
+	    fi
+	fi
+    fi
+
+else
+    # reverse: make a GRASS 6 map from a GRASS 7 map
+    if [ ! -d "raster/$GIS_OPT_MAP/" ] ; then
+	echo "Raster map <$GIS_OPT_MAP> not found in current mapset." 1>&2
+	exit 1
+    fi
+
+
+    for ELEMENT in cats cell cellhd colr fcell grid3 hist ; do
+	# make new $MAPSET/raster/ dir if needed
+	if [ ! -e $ELEMENT ] ; then
+	    mkdir $ELEMENT
+	fi
+	if [ ! -d $ELEMENT ] ; then
+	    echo "ERROR: Could not convert map." 1>&2
+	    exit 1
+	fi
+
+
+	if [ -e "raster/$GIS_OPT_MAP/$ELEMENT" ] ; then
+	    $MVCMD "raster/$GIS_OPT_MAP/$ELEMENT" "$ELEMENT/$GIS_OPT_MAP"
+	    if  [ $? -ne 0 ] ; then
+		echo "ERROR converting map. (element: $ELEMENT)" 1>&2
+		exit 1
+	    fi
+	fi
+    done
+
+    for ELEMENT in f_format f_quant f_range null range reclassed_to ; do
+	if [ -e "raster/$GIS_OPT_MAP/$ELEMENT" ] ; then
+	    if [ ! -e cell_misc ] ; then
+		mkdir cell_misc
+	    fi
+	    if [ ! -d cell_misc ] ; then
+		echo "ERROR: Could not convert map." 1>&2
+		exit 1
+	    fi
+
+	    if [ ! -e "cell_misc/$GIS_OPT_MAP" ] ; then
+		mkdir "cell_misc/$GIS_OPT_MAP"
+	    fi
+	    if [ ! -d "cell_misc/$GIS_OPT_MAP" ] ; then
+		echo "ERROR: Could not convert map." 1>&2
+		exit 1
+	    fi
+
+
+	    $MVCMD "raster/$GIS_OPT_MAP/$ELEMENT" "cell_misc/$GIS_OPT_MAP"
+	    if  [ $? -ne 0 ] ; then
+		echo "ERROR converting map. (element: $ELEMENT)" 1>&2
+		exit 1
+	    fi
+	fi
+    done
+
+    if [ $GIS_FLAG_M -eq 1 ] ; then
+	rmdir "raster/$GIS_OPT_MAP/"
+	if  [ $? -ne 0 ] ; then
+	    echo "WARNING: problem removing old map. Left over files:" 1>&2
+	    ls "raster/$GIS_OPT_MAP/"
+	fi
+    fi
+
+fi
+


Property changes on: grass-addons/raster/r.convert/r.convert
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/x-sh
Name: svn:eol-style
   + native

Added: grass-addons/raster/r.convert/r.convert.all
===================================================================
--- grass-addons/raster/r.convert/r.convert.all	                        (rev 0)
+++ grass-addons/raster/r.convert/r.convert.all	2008-12-13 09:12:03 UTC (rev 34843)
@@ -0,0 +1,55 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       r.convert.all
+# AUTHOR:       M. Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Converts all GRASS 4-6 raster maps in current mapset to
+#		 GRASS 7 raster map format
+# COPYRIGHT:    (c) 2007 Hamish Bowman, 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: Converts all GRASS 4-6 raster maps in current mapset to GRASS 7 raster map format
+#% keywords: raster, import, conversion, bulk
+#%end
+#%flag
+#%  key: m
+#%  description: Move maps instead of copying then
+#%end
+#%flag
+#%  key: r
+#%  description: Reverse action: Convert from GRASS 7 to GRASS 4-6 format
+#%end
+
+if  [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+if [ $GIS_FLAG_M -eq 1 ] ; then
+    MV_FLAG="-m"
+else
+    MV_FLAG=""
+fi
+
+if [ $GIS_FLAG_R -eq 1 ] ; then
+    REV_FLAG="-r"
+else
+    REV_FLAG=""
+fi
+
+
+for MAP in `g.mlist type=rast mapset=.` ; do
+    r.convert map="$MAP" $MV_FLAG $REV_FLAG
+    if [ $? -ne 0 ] ; then
+	echo "Error converting <$MAP>" 1>&2
+    fi
+done


Property changes on: grass-addons/raster/r.convert/r.convert.all
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/x-sh
Name: svn:eol-style
   + native



More information about the grass-commit mailing list