[GRASS-user] Re: script to generate georeferenced jpeg colored
images from FCELL/CELL rasters
G. Allegri
giohappy at gmail.com
Fri Jan 4 19:52:17 EST 2008
Sorry, I forgot to control region settings.
This is the correct script:
#!/bin/sh
############################################################################
#
# MODULE: r.out.jpeg
#
# AUTHOR(S): Giovanni Allegri <giohappy AT gmail.com
#
# PURPOSE: exports a jpeg image from an FCELL raster mantaing the color table
#
# COPYRIGHT: (c) 2008 Giovanni Allegri
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
# updates:
#
#4 January 2008: first version
#
#############################################################################
#
#%Module
#% description: exports a georeferenced jpeg from an FCELL raster
#%End
#%option
#% key: rastmap
#% type: string
#% gisprompt: old,cell,raster
#% description: Input FCELL Raster
#% required : yes
#%end
#%option
#% key: output
#% type: string
#% description: Output image (path_to_output_folder/filename_without_extension)
#% required : yes
#%end
if [ -z "$GISBASE" ]
then
echo ""
echo "You must be in GRASS GIS to run this program"
echo ""
exit 1
fi
if [ "$1" != "@ARGS_PARSED@" ]
then
exec g.parser "$0" "$@"
fi
RAST=$GIS_OPT_RASTMAP
OUTPATH=${GIS_OPT_OUTPUT%/*}
tmp=${GIS_OPT_OUTPUT##*/}
OUTPUT=$OUTPATH'/'${tmp%.*}
# check if we have awk
if [ ! -x "`which awk`" ] ; then
echo "$PROG: awk required, please install awk first" 2>&1
exit 1
fi
# check if we have ImageMagick
if [ ! -x "`which convert`" ] ; then
echo "$PROG: ImageMagick is required, please install it first" 2>&1
exit 1
fi
#check if the specified map exists
g.findfile element=cell file="$RAST" > /dev/null
if [ "$?" -ne 0 ] ; then
echo "Raster map '$RAST' not found in mapset search path"
exit 1
fi
# setting environment, so that awk works properly in all languages
unset LC_ALL
export LC_NUMERIC=C
exec `g.region rast="$RAST"`
RRES=`r.info -s map=$RAST | head -1 | awk 'BEGIN { FS="=" } { print $2 }' `
RNORTH=`r.info -g map=$RAST | awk 'BEGIN {FS="="} { if(NR==1) print $2 }' `
RWEST=`r.info -g map=$RAST | awk 'BEGIN {FS="="} { if(NR==4) print $2 }' `
exec `r.out.ppm -q in="$RAST" out="$OUTPUT.ppm"`
if [ "$?" -ne 0 ] ; then
echo "Jpeg Image '$OUTPUT' could not be created"
exit 1
fi
exec `convert $OUTPUT'.ppm' $OUTPUT'.jpg'`
if [ "$?" -ne 0 ] ; then
echo "Jpeg Image '$OUTPUT' could not be created"
exit 1
fi
echo $RRES'\n0\n0\n-'$RRES'\n'$RWEST'\n'$RNORTH > $OUTPUT'.jgw'
exec `rm $OUTPUT'.ppm'`
echo "$OUTPUT.jpg has been created"
More information about the grass-user
mailing list