[GRASS-SVN] r31873 - in grass-addons: display display/d.edit.rast raster raster/r.out.gmt2 vector vector/v.in.ncdc vector/v.out.gmt

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 28 08:06:07 EDT 2008


Author: hcho
Date: 2008-06-28 08:06:07 -0400 (Sat, 28 Jun 2008)
New Revision: 31873

Added:
   grass-addons/display/d.edit.rast/
   grass-addons/display/d.edit.rast/d.edit.rast
   grass-addons/raster/r.out.gmt2/
   grass-addons/raster/r.out.gmt2/r.out.gmt2
   grass-addons/vector/v.in.ncdc/
   grass-addons/vector/v.in.ncdc/v.in.ncdc
   grass-addons/vector/v.out.gmt/
   grass-addons/vector/v.out.gmt/v.out.gmt
Log:
Added r.out.gmt2, v.in.ncdc, v.out.gmt, and d.edit.rast.


Added: grass-addons/display/d.edit.rast/d.edit.rast
===================================================================
--- grass-addons/display/d.edit.rast/d.edit.rast	                        (rev 0)
+++ grass-addons/display/d.edit.rast/d.edit.rast	2008-06-28 12:06:07 UTC (rev 31873)
@@ -0,0 +1,78 @@
+#!/bin/sh
+################################################################################
+#
+# MODULE:       d.edit.rast
+#
+# AUTHOR(S):    Huidae Cho 2007-05-14
+#
+# PURPOSE:      Edits cells in an existing raster map displayed on the monitor
+#
+# COPYRIGHT:    (c) 2007 by Huidae Cho
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+# REQUIRES:     awk
+#
+################################################################################
+
+#%module
+#% description: Edits cells in an existing raster map displayed on the monitor
+#%end
+#%option
+#% key: map
+#% type: string
+#% gisprompt: old,raster,raster
+#% description: Name of a raster map
+#% required: yes
+#%end
+#%option
+#% key: value
+#% type: string
+#% description: Value for new cells
+#% required: yes
+#% answer: 1
+#%end
+#%flag
+#% key: g
+#% description: Draw grid for editing
+#%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 ! echo test | awk '{print $0}' > /dev/null 2>&1; then
+	echo "`basename $0`: awk required, please install awk/gawk first" 1>&2
+	exit 1
+fi
+
+eval `g.region -g`
+if [ $GIS_FLAG_G -eq 1 ]; then
+	d.grid -t $ewres
+fi
+g.region rast=$GIS_OPT_MAP
+d.where | awk -v map="$GIS_OPT_MAP" -v value="$GIS_OPT_VALUE" '
+BEGIN{
+	printf "%s=", map
+}
+{
+	printf "if(%s>x()-ewres()/2 && %s<x()+ewres()/2 && %s>y()-nsres()/2 && %s<y()+nsres()/2, %s, ", $1, $1, $2, $2, value
+}
+END{
+	printf "%s", map
+	for(i = 0; i < NR; i++)
+		printf ")"
+}' | r.mapcalc
+g.region n=$n s=$s e=$e w=$w rows=$rows cols=$cols nsres=$nsres ewres=$ewres
+if [ $GIS_FLAG_G -eq 1 ]; then
+	d.save remove=1 > /dev/null
+else
+	d.redraw
+fi


Property changes on: grass-addons/display/d.edit.rast/d.edit.rast
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/raster/r.out.gmt2/r.out.gmt2
===================================================================
--- grass-addons/raster/r.out.gmt2/r.out.gmt2	                        (rev 0)
+++ grass-addons/raster/r.out.gmt2/r.out.gmt2	2008-06-28 12:06:07 UTC (rev 31873)
@@ -0,0 +1,278 @@
+#!/bin/sh
+################################################################################
+#
+# MODULE:       r.out.gmt2
+#
+# AUTHOR(S):    Huidae Cho 2006-09-21
+#               Modified from r.out.gmt by M. Hamish Bowman
+#
+# PURPOSE:      Output a GRASS raster to a GMT grd file and color table
+#
+# COPYRIGHT:    (c) 2006 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.
+#
+# REQUIRES:     GMT: The Generic Mapping Tools
+#                 http://gmt.soest.hawaii.edu
+#               awk
+#
+################################################################################
+#
+# TODO: use GMT's xyz2grd to make grd files? see raster/r.out.bin/README
+#       then you can do DCELL output.
+#
+#   xyz2grd -ZTLi  for CELL
+#   xyz2grd -ZTLf  for FCELL
+#   xyz2grd -ZTLd  for DCELL
+#
+#  and the -F may be quite important: it forces pixel registration
+#  (the default is grd registration). I am always confused by this,
+#  maybe grd registration is correct?
+#
+# Dylan's tutorial: http://169.237.35.250/~dylan/grass_user_group/map1.html
+#
+
+#%module
+#% description: Exports a GRASS raster map into a GMT grd file and color table
+#%end
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,cell,raster
+#% description: Name of input raster map
+#% required: yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% description: Base name of output files (taken from input map if not given)
+#% required: no
+#%end
+#%option
+#% key: width
+#% type: string
+#% description: Map width (e.g., 7in, 18cm)
+#% answer: 7in
+#%end
+#%option
+#% key: title
+#% type: string
+#% description: Map title (taken from output if not given)
+#%end
+#%option
+#% key: xlabel
+#% type: string
+#% description: X tic label
+#% answer: Easting (m)
+#%end
+#%option
+#% key: ylabel
+#% type: string
+#% description: Y tic label
+#% answer: Northing (m)
+#%end
+#%option
+#% key: comment
+#% type: string
+#% description: Map comment ($scale for map scale in meters)
+#% answer: Scale 1:$scale
+#%end
+#%flag
+#% key: p
+#% description: Display suggested GMT PostScript creation commands
+#%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
+
+# check if we have awk
+if ! echo test | awk '{print $0}' > /dev/null 2>&1; then
+    echo "`basename $0`: awk required, please install awk/gawk first" 1>&2
+    exit 1
+fi
+
+# setting environment, so that awk works properly in all languages
+unset LC_ALL
+export LC_NUMERIC=C
+
+map_name="$GIS_OPT_INPUT"
+
+if [ -z "$GIS_OPT_OUTPUT" ]; then
+    output_base="$GIS_OPT_INPUT"
+else
+    output_base="$GIS_OPT_OUTPUT"
+fi
+
+if [ -z "$GIS_OPT_TITLE" ]; then
+    title="$output_base"
+else
+    title="$GIS_OPT_TITLE"
+fi
+
+xlabel="$GIS_OPT_XLABEL"
+ylabel="$GIS_OPT_YLABEL"
+comment="$GIS_OPT_COMMENT"
+
+output_grd="$output_base.grd"
+output_cpt="$output_base.cpt"
+output_ps="$output_base.ps"
+
+# what to do in case of user break:
+exit_procedure()
+{
+    echo "User break!" 1>&2
+    cleanup
+    exit 1
+}
+# shell check for user break (signal list: trap -l)
+trap "exit_procedure" 2 3 15
+
+cleanup()
+{
+    if [ "$map_type" = "DCELL" ]; then
+	g.remove tmp_gmt_$$ > /dev/null
+    fi
+}
+
+map_type=`r.info -t "$map_name" | cut -f2 -d'='`
+
+case "$map_type" in
+CELL)
+    map_tag="=2"
+    ;;
+FCELL)
+    map_tag="=1"
+    ;;
+DCELL)
+    map_tag="=1"
+    echo "WARNING: Converting from double precision to floating point map" 1>&2
+    r.mapcalc "tmp_gmt_$$=float($map_name)"
+    map_name=tmp_gmt_$$
+    ;;
+esac
+
+r.out.bin -h input="$map_name" output="$output_grd"
+if [ $? -ne 0 ]; then
+    echo "ERROR: creating binary grd file" 1>&2
+    cleanup
+    exit 1
+fi
+
+# get our geographic extents
+eval `g.region -g`
+ns_extent=`g.region -e | grep south | cut -f2 -d: | sed -e 's=^ =='`
+ew_extent=`g.region -e | grep west | cut -f2 -d: | sed -e 's=^ =='`
+
+# preserve aspect ratio from UTM E,N coordinates:
+aspect_ratio=`echo $ns_extent $ew_extent | awk '{printf("%f", $1 / $2)}'`
+
+# setup the map width in inches
+# this is going to affect how much information can be placed in the margins of
+# the paper. commonly a printer will enforce a .25" margin...
+map_width=`echo $GIS_OPT_WIDTH | sed -e 's/[a-zA-Z]//g'`
+map_width_unit=`echo $GIS_OPT_WIDTH | sed -e 's/[0-9]//g' | cut -c1`
+
+# calculate the map length based on the original aspect ratio
+map_height=`echo $map_width $aspect_ratio | awk '{printf("%f", $1 * $2)}'`
+
+# compute the scale in meters
+# 39.37 inch/meter
+# (round to a whole number of some sort?)
+if [ "$map_width_unit" = "i" ]; then
+    scale=`echo $ew_extent $map_width | awk '{printf("%d", ($1 * 39.37) / $2)}'`
+else
+    scale=`echo $ew_extent $map_width | awk '{printf("%d", $1 / $2)}'`
+fi
+
+# compute default grd ticks
+# default units are meters
+if [ `echo $aspect_ratio | cut -f1 -d'.'` -ge 1 ]; then
+    max_extent=$ns_extent
+else
+    max_extent=$ew_extent
+fi
+# try to figure out something useful  (how to get awk to do log10()??)
+# what is this for?
+#tic_interval=`echo $max_extent | awk '{printf("%d", log($1)/log(10))}'`
+tic_interval=`echo $max_extent | awk '{printf("%d", int(($1/60)/100)*100)}'`
+annotated_tic_interval=`expr $tic_interval '*' 10`
+
+# setup the comment at the bottom of the map
+eval "comment=\"$comment\""
+
+# create cpt color table from raster's colr file
+eval `g.findfile elem=colr file="$map_name" | grep "^file="`
+colr_file="$file"
+
+cat<<EOT > "$output_cpt"
+#
+# GMT colormap created by the `g.version` r.out.gmt script
+# from base map [$map_name]
+# created by $USER@$HOSTNAME at `date`
+#
+# COLOR_MODEL = RGB
+EOT
+
+for line in `cat "$colr_file" | tail -n+2 | grep -v "^nv" | tr ' ' '|'`; do
+    c_begin="`echo "$line" | cut -f1 -d'|'`"
+    c_end="`echo "$line" | cut -f2 -d'|'`"
+
+    c_begin="`echo "$line" | cut -f1 -d'|'`"
+    c_end="`echo "$line" | cut -f2 -d'|'`"
+
+    # translate 1 color value into 3
+    if [ "`echo "$c_begin" | tr ':' '\n' | wc -l`" -eq 2 ]; then
+	rule_cat="`echo "$c_begin" | cut -f1 -d:`"
+	rule_color="`echo "$c_begin" | cut -f2 -d:`"
+	c_begin="$rule_cat:$rule_color:$rule_color:$rule_color"
+    fi
+    if [ "`echo "$c_end" | tr ':' '\n' | wc -l`" -eq 2 ]; then
+	rule_cat="`echo "$c_end" | cut -f1 -d:`"
+	rule_color="`echo "$c_end" | cut -f2 -d:`"
+	c_end="$rule_cat:$rule_color:$rule_color:$rule_color"
+    fi
+
+    c_string="$c_begin:$c_end"
+    echo "$c_string" | tr ':' '\t' >> "$output_cpt"
+done
+
+# copy color of null value, if any
+c_null="`grep "^nv" "$colr_file" | cut -f2 -d':'`"
+if [ -n "$c_null" ]; then
+    if [ "`echo "$c_null" | tr ':' '\n' | wc -l`" -eq 1 ]; then
+	c_string="N:$c_null:$c_null:$c_null"
+    else
+	c_string="N:$c_null"
+    fi
+
+    echo "$c_string" | tr ':' '\t' >> "$output_cpt"
+fi
+
+# show suggested PostScript creation commands
+if [ $GIS_FLAG_P -eq 1 ]; then
+    echo 1>&2
+    cat<<EOT
+psbasemap \\
+    -JX$map_width$map_width_unit/$map_height$map_width_unit \\
+    -R$w/$e/$s/$n \\
+    -B:."$title":f${tic_interval}a$annotated_tic_interval:"$xlabel":/f${tic_interval}a$annotated_tic_interval:"$ylabel": \\
+    -U"$comment" \\
+    -V -K > $output_ps
+grdimage $output_grd$map_tag -C$output_cpt -JX -R -O -V -K >> $output_ps
+EOT
+    echo 1>&2
+fi
+
+cleanup
+
+echo "`basename $0` complete." 1>&2
+
+exit 0


Property changes on: grass-addons/raster/r.out.gmt2/r.out.gmt2
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/vector/v.in.ncdc/v.in.ncdc
===================================================================
--- grass-addons/vector/v.in.ncdc/v.in.ncdc	                        (rev 0)
+++ grass-addons/vector/v.in.ncdc/v.in.ncdc	2008-06-28 12:06:07 UTC (rev 31873)
@@ -0,0 +1,72 @@
+#!/bin/sh
+################################################################################
+#
+# MODULE:       v.in.ncdc
+#
+# AUTHOR(S):    Huidae Cho 2006-10-26
+#
+# PURPOSE:      Import NCDC station data into a GRASS vector file
+#
+# COPYRIGHT:    (c) 2006 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.
+#
+# REQUIRES:     awk
+#
+################################################################################
+
+#%module
+#% description: Imports an NCDC stn file (station data) into a GRASS vector map
+#%end
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old_file,file,stn
+#% description: Name of input NCDC stn file
+#% required: yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new,vector,vector
+#% description: Name for output vector map
+#% required: yes
+#%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 ! echo test | awk '{print $0}' > /dev/null 2>&1; then
+	echo "`basename $0`: awk required, please install awk/gawk first" 1>&2
+	exit 1
+fi
+
+awk '{
+	if(NR < 3)
+		next
+	x = substr($0, 148, 9)
+	gsub(" ", "", x)
+	if(sub("-", "", x))
+		x = x"W"
+	else
+		x = x"E"
+	y = substr($0, 138, 8)
+	gsub(" ", "", y)
+	if(sub("-", "", y))
+		y = y"S"
+	else
+		y = y"N"
+	z = substr($0, 156)
+	id = substr($0, 1, 6)
+	name = substr($0, 17, 29)
+	printf "%s|%s|%s|%s|%s\n", x, y, z, id, name
+}' "$GIS_OPT_INPUT" | sed 's/ *$//g' | v.in.ascii output="$GIS_OPT_OUTPUT" \
+	columns="x varchar(7), y varchar(6), z double precision, id int, name varchar(29)"


Property changes on: grass-addons/vector/v.in.ncdc/v.in.ncdc
___________________________________________________________________
Name: svn:executable
   + *

Added: grass-addons/vector/v.out.gmt/v.out.gmt
===================================================================
--- grass-addons/vector/v.out.gmt/v.out.gmt	                        (rev 0)
+++ grass-addons/vector/v.out.gmt/v.out.gmt	2008-06-28 12:06:07 UTC (rev 31873)
@@ -0,0 +1,185 @@
+#!/bin/sh
+################################################################################
+#
+# MODULE:       v.out.gmt
+#
+# AUTHOR(S):    Huidae Cho 2006-09-21
+#               psbasemap code copied from r.out.gmt
+#
+# PURPOSE:      Output a GRASS vector to a GMT xy file
+#
+# COPYRIGHT:    (c) 2006 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.
+#
+# REQUIRES:     GMT: The Generic Mapping Tools
+#                 http://gmt.soest.hawaii.edu
+#               awk
+#
+################################################################################
+#
+# TODO: xyz, points, color, label
+#
+
+#%module
+#% description: Exports a GRASS vector map into a GMT xy file
+#%end
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,vector,vector
+#% description: Name of input vector map
+#% required: yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% description: Base name of output file (taken from input map if not given)
+#% required: no
+#%end
+#%option
+#% key: width
+#% type: string
+#% description: Map width (e.g., 7in, 18cm)
+#% answer: 7in
+#%end
+#%option
+#% key: title
+#% type: string
+#% description: Map title (taken from output if not given)
+#%end
+#%option
+#% key: xlabel
+#% type: string
+#% description: X tic label
+#% answer: Easting (m)
+#%end
+#%option
+#% key: ylabel
+#% type: string
+#% description: Y tic label
+#% answer: Northing (m)
+#%end
+#%option
+#% key: comment
+#% type: string
+#% description: Map comment ($scale for map scale in meters)
+#% answer: Scale 1:$scale
+#%end
+#%flag
+#% key: p
+#% description: Display suggested GMT PostScript creation commands
+#%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
+
+# check if we have awk
+if ! echo test | awk '{print $0}' > /dev/null 2>&1; then
+    echo "`basename $0`: awk required, please install awk/gawk first" 1>&2
+    exit 1
+fi
+
+# setting environment, so that awk works properly in all languages
+unset LC_ALL
+export LC_NUMERIC=C
+
+map_name="$GIS_OPT_INPUT"
+
+if [ -z "$GIS_OPT_OUTPUT" ]; then
+    output_base="$GIS_OPT_INPUT"
+else
+    output_base="$GIS_OPT_OUTPUT"
+fi
+
+if [ -z "$GIS_OPT_TITLE" ]; then
+    title="$output_base"
+else
+    title="$GIS_OPT_TITLE"
+fi
+
+xlabel="$GIS_OPT_XLABEL"
+ylabel="$GIS_OPT_YLABEL"
+comment="$GIS_OPT_COMMENT"
+
+output_xy="$output_base.xy"
+output_ps="$output_base.ps"
+
+# get our geographic extents
+eval `g.region -g`
+ns_extent=`g.region -e | grep south | cut -f2 -d: | sed -e 's=^ =='`
+ew_extent=`g.region -e | grep west | cut -f2 -d: | sed -e 's=^ =='`
+
+# preserve aspect ratio from UTM E,N coordinates:
+aspect_ratio=`echo $ns_extent $ew_extent | awk '{printf("%f", $1 / $2)}'`
+
+# setup the map width in inches
+# this is going to affect how much information can be placed in the margins of
+# the paper. commonly a printer will enforce a .25" margin...
+map_width=`echo $GIS_OPT_WIDTH | sed -e 's/[a-zA-Z]//g'`
+map_width_unit=`echo $GIS_OPT_WIDTH | sed -e 's/[0-9]//g' | cut -c1`
+
+# calculate the map length based on the original aspect ratio
+map_height=`echo $map_width $aspect_ratio | awk '{printf("%f", $1 * $2)}'`
+
+# compute the scale in meters
+# 39.37 inch/meter
+# (round to a whole number of some sort?)
+if [ "$map_width_unit" = "i" ]; then
+    scale=`echo $ew_extent $map_width | awk '{printf("%d", ($1 * 39.37) / $2)}'`
+else
+    scale=`echo $ew_extent $map_width | awk '{printf("%d", $1 / $2)}'`
+fi
+
+# compute default grid ticks
+# default units are meters
+if [ `echo $aspect_ratio | cut -f1 -d'.'` -ge 1 ]; then
+    max_extent=$ns_extent
+else
+    max_extent=$ew_extent
+fi
+# try to figure out something useful  (how to get awk to do log10()??)
+# what is this for?
+#tic_interval=`echo $max_extent | awk '{printf("%d", log($1)/log(10))}'`
+tic_interval=`echo $max_extent | awk '{printf("%d", int(($1/60)/100)*100)}'`
+annotated_tic_interval=`expr $tic_interval '*' 10`
+
+# setup the comment at the bottom of the map
+eval "comment=\"$comment\""
+
+v.out.ascii "$map_name" format=standard | awk '{
+	if($1 == "B"){
+		npnts = $2
+		draw = 1
+		print ">"
+		next
+	}
+	if(!draw)
+		next
+	print $0
+	if(!(--npnts))
+		draw = 0
+}' > "$output_xy"
+
+# show suggested PostScript creation commands
+if [ $GIS_FLAG_P -eq 1 ]; then
+    cat<<EOT
+psbasemap \\
+    -JX$map_width$map_width_unit/$map_height$map_width_unit \\
+    -R$w/$e/$s/$n \\
+    -B:."$title":f${tic_interval}a$annotated_tic_interval:"$xlabel":/f${tic_interval}a$annotated_tic_interval:"$ylabel": \\
+    -U"$comment" \\
+    -V -K > $output_ps
+psxy $output_xy -JX -R -M -O -V -K >> $output_ps
+EOT
+fi
+
+exit 0


Property changes on: grass-addons/vector/v.out.gmt/v.out.gmt
___________________________________________________________________
Name: svn:executable
   + *



More information about the grass-commit mailing list