3
############################################################################
5
# MODULE: d.vect.thematic
6
# AUTHOR(S): Michael Barton, Arizona State University with contributions
7
# by Martin Landa, Jachym Cepicky, Daniel Calvelo Aros and Moritz Lennert
8
# PURPOSE: Displays thematic vector map with graduated colors
9
# or graduated points and line thickneses
10
# COPYRIGHT: (C) 2006 by the GRASS Development Team
12
# This program is free software under the GNU General Public
13
# License (>=v2). Read the file COPYING that comes with GRASS
16
#############################################################################
20
#% description: Displays thematic vector map
21
#% keywords: display, vector, thematic, legend
27
#% gisprompt: old,vector,vector
28
#% description: Name of vector map
35
#% description: Feature type
36
#% options: area,point,centroid,line,boundary
43
#% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
45
#% description: Name of attribute column to use for thematic display (must be numeric)
52
#% options: graduated_colors,graduated_points,graduated_lines
53
#% answer: graduated_colors
54
#% description: Type of thematic display
61
#% options: interval,std_deviation,quartiles,custom_breaks
63
#% description: Thematic divisions of data for display
70
#% label: Break points for custom breaks option
71
#% description: Separate values by spaces (0 10 20 30 ...)
78
#% gisprompt: old_layer,layer,layer
79
#% description: Layer number
87
#% description: Vector point icon for point data
88
#% options: basic/box,basic/circle,basic/cross2,basic/diamond,basic/star,basic/cross1,basic/x
89
#% answer: basic/circle
96
#% label: Icon size for point data
97
#% description: Minimum icon size/line width for graduated points/lines)
102
#% guisection: Points
105
#% description: Maximum icon size/line width for graduated points and lines
113
#% description: Number of classes for interval theme (integer)
121
#% label: Color scheme for graduated color mapping
122
#% description: Select 'single_color' for graduated point/line display
123
#% options: blue-red,red-blue,green-red,red-green,blue-green,green-blue,cyan-yellow,yellow-cyan,custom_gradient,single_color
131
#% label: Color for graduated points map
132
#% description: GRASS named color or R:G:B triplet. Set color scheme to single color
140
#% label: Color for graduated lines or point/area outlines
141
#% description: GRASS named color or R:G:B triplet. Set color scheme to single color.
149
#% label: Beginning color for custom color gradient
150
#% description: Must be expressed as R:G:B triplet
158
#% label: Ending color for custom color gradient
159
#% description: Must be expressed as R:G:B triplet
167
#% description: Select x11 display monitor for legend
168
#% options: x0,x1,x2,x3,x4,x5,x6,none
175
#%description: Save thematic map commands to group file for GIS Manager
181
#% description: WHERE conditions of SQL statement without 'where' keyword
188
#% label: Root for the name of psmap instruction files to be in current directory
189
#% description: If not set, no psmap instruction files will be created)
196
#% gisprompt: new_file,file,group
197
#% description: Name of group file where thematic map commands will be saved
203
#%description: Create graphic legend in x11 display monitor
208
#% description: Only draw fills (no outlines) for areas and points
213
#% description: Update color values to GRASSRGB column in attribute table
218
#%description: Output legend for GIS Manager (for scripting use only)
223
#%description: Use math notation brackets in legend
226
if [ -z "$GISBASE" ] ; then
227
echo "You must be in GRASS GIS to run this program." >&2
231
if [ "$1" != "@ARGS_PARSED@" ] ; then
232
exec g.parser "$0" "$@"
237
#### check if we have awk
238
if [ ! -x "`which awk`" ] ; then
239
g.message -e "awk required, please install awk or gawk first"
243
# setting environment, so that awk works properly in all languages
248
# hard-coded parameter: the maximum number of legend items before
249
# we strip them using a middle ellipsis
253
COLTYPE=`v.info -c "$GIS_OPT_MAP" layer="$GIS_OPT_LAYER" 2> /dev/null | grep -w "$GIS_OPT_COLUMN" | cut -d'|' -f1 | tr -s '[:upper:]' '[:lower:]'`
256
if [ -z "$COLTYPE" ] ; then
257
g.message -e message="No such column [$GIS_OPT_COLUMN]"
261
if [ "$COLTYPE" != "integer" ] && [ "$COLTYPE" != "double precision" ] ; then
262
g.message -e message="Column <$GIS_OPT_COLUMN> is of type <$COLTYPE> which is not numeric."
266
# create temporary file to hold output from v.univar
267
TMP1="`g.tempfile pid=$$`"
268
if [ $? -ne 0 ] || [ -z "$TMP1" ] ; then
269
g.message -e "Unable to create temporary file for statistics"
273
# create temporary file to hold d.graph commands for legend
274
TMP2="`g.tempfile pid=$$`"
275
if [ $? -ne 0 ] || [ -z "$TMP2" ] ; then
276
g.message -e "Unable to create temporary file for legend"
280
# Create temporary file to commands for GIS Manager group
281
TMP3="`g.tempfile pid=$$`"
282
if [ $? -ne 0 ] || [ -z "$TMP3" ] ; then
283
g.message -e "Unable to create temporary file for group"
287
# Create temporary file for commands for ps.map map file
288
TMP4="`g.tempfile pid=$$`"
289
if [ $? -ne 0 ] || [ -z "$TMP4" ] ; then
290
g.message -e "Unable to create temporary file for ps.map legend"
294
# Create temporary file for commands for ps.map legend file
295
TMP5="`g.tempfile pid=$$`"
296
if [ $? -ne 0 ] || [ -z "$TMP5" ] ; then
297
g.message -e "Unable to create temporary file for ps.map legend"
301
# create file to hold elements for GIS Manager legend
302
TMP6="`g.tempfile pid=$$`"
303
if [ $? -ne 0 ] || [ -z "$TMP6" ] ; then
304
g.message -e "Unable to create temporary file for GIS Manager legend"
309
# Set display variables for group
316
case "$GIS_OPT_TYPE" in
319
"centroid" ) ctype=1 ;;
321
"boundary" ) btype=1 ;;
326
\rm -f "$TMP1" "$TMP1.sort" "$TMP2" "$TMP2.sort" "$TMP3" "$TMP3.sort" \
327
"$TMP4" "$TMP4.sort" "$TMP5" "$TMP5.sort" "$TMP6" "$TMP6.sort"
330
# what to do in case of user break:
333
g.message -e message='User break!'
337
# shell check for user break (signal list: trap -l)
338
trap "exitprocedure" 2 3 15
340
# identify current monitor or start monitor
341
if [ "$GIS_FLAG_S" -ne 1 ] ; then
342
currmon=`eval d.mon -L | grep "(selected)" | awk '{print $1}'`
345
if [ -z "$currmon" -a "$GIS_FLAG_S" -ne 1 ] ; then
346
g.message -e message='*** You must open a display monitor ***'
351
# if running in the GUI, do not create a graphic legend in an xmon
352
if [ "$GIS_FLAG_S" -eq 1 ] ; then
354
# if running in GUI, turn off immediate mode rendering so that the
355
# iterated d.vect commands will composite using the display driver
356
autowrite=$GRASS_PNG_AUTO_WRITE
357
pngread=$GRASS_PNG_READ
359
export GRASS_PNG_READ
360
GRASS_PNG_AUTO_WRITE=FALSE
361
export GRASS_PNG_AUTO_WRITE
364
table=`v.db.connect "$GIS_OPT_MAP" -gl layer="$GIS_OPT_LAYER" fs="|" | cut -f2 -d'|'`
365
database=`v.db.connect "$GIS_OPT_MAP" -gl layer="$GIS_OPT_LAYER" fs="|" | cut -f4 -d'|'`
366
driver=`v.db.connect "$GIS_OPT_MAP" -gl layer="$GIS_OPT_LAYER" fs="|" | cut -f5 -d'|'`
368
if [ -z "$table" ] ; then
369
g.message -e message="No table connected or layer <$GIS_OPT_LAYER> does not exist."
373
# update color values to the table?
374
if [ "$GIS_FLAG_U" -eq 1 ] ; then
375
# test, if the column GRASSRGB is in the table
376
if [ -z "`db.columns table=$table database=$database driver=$driver| grep -i grassrgb`" ] ; then
377
g.message message="Creating column 'grassrgb' in table '$table'"
378
echo "ALTER TABLE $table ADD COLUMN grassrgb varchar(11)" | db.execute database="${database}" driver=${driver}
383
if [ -z "$GIS_OPT_GROUP" ] ; then
389
echo "Group $group" > "$TMP3"
391
# Calculate statistics for thematic intervals
392
if [ -z "$GIS_OPT_WHERE" ] ; then
393
if [ "$GIS_OPT_TYPE" = "line" ] ; then
394
v.univar -e -g map=$GIS_OPT_MAP type=line column=$GIS_OPT_COLUMN layer="$GIS_OPT_LAYER" > "$TMP1"
396
v.univar -e -g map=$GIS_OPT_MAP type=point,centroid column=$GIS_OPT_COLUMN layer="$GIS_OPT_LAYER" > "$TMP1"
399
if [ "$GIS_OPT_TYPE" = "line" ] ; then
400
v.univar -e -g map=$GIS_OPT_MAP type=line column=$GIS_OPT_COLUMN where="$GIS_OPT_WHERE" layer="$GIS_OPT_LAYER" > "$TMP1"
402
v.univar -e -g map=$GIS_OPT_MAP type=point,centroid column=$GIS_OPT_COLUMN where="$GIS_OPT_WHERE" layer="$GIS_OPT_LAYER" > "$TMP1"
406
min=`grep 'min=' "$TMP1" | sed s/min=//`
407
max=`grep 'max=' "$TMP1" | sed s/max=//`
408
mean=`grep 'mean=' "$TMP1" | sed s/mean=//`
409
sd=`grep 'population_stddev=' "$TMP1" | sed s/'population_stddev='//`
410
q1=`grep 'first_quartile=' "$TMP1" | sed s/'first_quartile='//`
411
q2=`grep 'median=' "$TMP1" | sed s/'median='//`
412
q3=`grep 'third_quartile=' "$TMP1" | sed s/'third_quartile='//`
414
ptsize="$GIS_OPT_SIZE"
416
if [ -n "$GIS_OPT_BREAKPOINTS" ] && [ "$GIS_OPT_THEMECALC" != "custom_breaks" ] ; then
417
g.message -w "Custom breakpoints ignored due to themecalc setting."
420
# set interval for each thematic map calculation type
421
case "$GIS_OPT_THEMECALC" in
424
step=`echo $min $max $numint | awk '{print (($2 - $1) / $3)}'`
425
breakpoints=`echo $min $max $numint | awk '{for(i=0;i<$3;i++){printf $1+($2-$1)/$3*i " "}printf $2}'`
430
# 2 standard deviation units on either side of mean,
431
# plus min to -2 sd units and +2 sd units to max, if applicable
432
breakpoints=`echo $min $max $mean $sd | awk '{printf $1;for(i=-2;i<=2;i++){ith=$3+i*$4;if($1<ith && $2>ith){printf " " ith}}print " " $2}'`
433
annotations=`echo $min $max $mean $sd | awk '{printf "";for(i=-2;i<=2;i++){ith=$3+i*$4;if($1<ith && $2>ith){if(i!=0){printf ";"((i<0)?"":"+") i "sd"} }}print ";"}'`
434
numint=`echo $breakpoints | awk '{print NF-1}'`
439
# one for each quartile
440
breakpoints="$min $q1 $q2 $q3 $max"
441
annotations=" q1; q2; q3; q4"
445
if [ -z "$GIS_OPT_BREAKPOINTS" ] ; then
446
breakpoints=`cat | awk '{gsub("[^0-9., ]","",$0);print}'`
448
breakpoints="$GIS_OPT_BREAKPOINTS"
450
numint=`echo $breakpoints|awk '{print NF-1}'`
455
g.message -e "Unknown themecalc type"
460
pointstep=`echo $GIS_OPT_MAXSIZE $ptsize $numint | awk '{print (($1 - $2) / ($3-1))}'`
462
# Prepare legend cuts for too large numint
463
if [ $numint -gt $MAX_LEG_ITEMS ]; then
464
xupper=`echo $numint $MAX_LEG_ITEMS | awk '{print int($1 - $2/2)+1}'`
465
xlower=`echo $MAX_LEG_ITEMS | awk '{print int($1/2)+1}'`
472
echo "color 0:0:0" > "$TMP2"
473
echo "size 2 2" >> "$TMP2"
474
echo "move 1 95" >> "$TMP2"
475
echo "text Thematic map legend for column $GIS_OPT_COLUMN of map $GIS_OPT_MAP" >> "$TMP2"
476
echo "size 1.5 1.8" >> "$TMP2"
477
echo "move 4 90" >> "$TMP2"
478
echo "text Value range: $min - $max" >> "$TMP2"
480
echo "title - - - {Thematic map legend for column $GIS_OPT_COLUMN of map $GIS_OPT_MAP}" > "$TMP6"
482
echo "text 1% 95% Thematic map legend for column $GIS_OPT_COLUMN of map $GIS_OPT_MAP" >> "$TMP5"
483
echo " ref bottom left" >> "$TMP5"
484
echo "end" >> "$TMP5"
485
echo "text 4% 90% Value range: $min - $max" >> "$TMP5"
486
echo " ref bottom left" >> "$TMP5"
487
echo "end" >> "$TMP5"
489
g.message message="Thematic map legend for column $GIS_OPT_COLUMN of map $GIS_OPT_MAP"
490
g.message message="Value range: $min - $max"
492
# graduated color thematic mapping
493
if [ "$GIS_OPT_THEMETYPE" = "graduated_colors" ] ; then
494
# set color schemes for graduated color maps
495
case "$GIS_OPT_COLORSCHEME" in
529
startc="$GIS_OPT_STARTCOLOR"
530
endc="$GIS_OPT_ENDCOLOR"
533
if [ "$GIS_OPT_THEMETYPE" = "graduated_points" ]; then
534
startc="$GIS_OPT_LINECOLOR"
535
endc="$GIS_OPT_LINECOLOR"
537
startc="$GIS_OPT_POINTCOLOR"
538
endc="$GIS_OPT_POINTCOLOR"
542
g.message -e message="This should not happen: gparser error. Unknown color scheme $GIS_OPT_COLORSCHEME"
549
eval color$i=`echo $startc | cut -d':' -f$i`
550
eval endcolor$i=`echo $endc | cut -d':' -f$i`
553
#The number of color steps is one less then the number of classes
554
nclrstep=`expr $numint - 1`
556
clrstep1=`expr \( $color1 - $endcolor1 \) / $nclrstep`
557
clrstep2=`expr \( $color2 - $endcolor2 \) / $nclrstep`
558
clrstep3=`expr \( $color3 - $endcolor3 \) / $nclrstep`
562
# display graduated color themes
563
if [ "$GIS_OPT_THEMECALC" = "interval" ] ; then
564
echo "move 4 87" >> "$TMP2"
565
echo "text Mapped by $numint intervals of $step" >> "$TMP2"
567
echo "subtitle - - - {Mapped by $numint intervals of $step}" >> "$TMP6"
569
echo "text 4% 87% Mapped by $numint intervals of $step" >> "$TMP5"
570
echo " ref bottom left" >> "$TMP5"
571
echo "end" >> "$TMP5"
573
g.message message="Mapped by $numint intervals of $step"
576
# display graduated color themes for standard deviation units
577
if [ "$GIS_OPT_THEMECALC" = "std_deviation" ] ; then
579
echo "move 4 87" >> "$TMP2"
580
echo "text Mapped by standard deviation units of $sd (mean =$mean)" >> "$TMP2"
582
echo "subtitle - - - {Mapped by standard deviation units of $sd (mean =$mean)}" >> "$TMP6"
584
echo "text 4% 87% Mapped by standard deviation units of $sd (mean =$mean)" >> "$TMP5"
585
echo " ref bottom left" >> "$TMP5"
586
echo "end" >> "$TMP5"
588
g.message message="Mapped by standard deviation units of $sd (mean =$mean)"
591
# display graduated color themes for quartiles
592
if [ "$GIS_OPT_THEMECALC" = "quartiles" ] ; then
594
echo "move 4 87" >> "$TMP2"
595
echo "text Mapped by quartiles (median =$q2)" >> "$TMP2"
597
echo "subtitle - - - {Mapped by quartiles (median =$q2)}" >> "$TMP6"
599
echo "text 4% 87% Mapped by quartiles (median =$q2)" >> "$TMP5"
600
echo " ref bottom left" >> "$TMP5"
601
echo "end" >> "$TMP5"
605
g.message message="Mapped by quartiles (median = $q2)"
608
echo "move 4 83" >> "$TMP2"
609
echo "text Color" >> "$TMP2"
610
echo "move 14 83" >> "$TMP2"
611
echo "text Value" >> "$TMP2"
612
echo "move 4 80" >> "$TMP2"
613
echo "text =====" >> "$TMP2"
614
echo "move 14 80" >> "$TMP2"
615
echo "text ============" >> "$TMP2"
618
echo "text 4% 83% Color" >> "$TMP5"
619
echo " ref bottom left" >> "$TMP5"
620
echo "end" >> "$TMP5"
621
echo "text 14% 83% Value" >> "$TMP5"
622
echo " ref bottom left" >> "$TMP5"
623
echo "end" >> "$TMP5"
624
echo "text 4% 80% =====" >> "$TMP5"
625
echo " ref bottom left" >> "$TMP5"
626
echo "end" >> "$TMP5"
627
echo "text 14% 80% ============" >> "$TMP5"
628
echo " ref bottom left" >> "$TMP5"
629
echo "end" >> "$TMP5"
632
echo "Color(R:G:B)" "Value" | awk '{print $1 "\t" $2}'
633
echo "============" "==========" | awk '{print $1 "\t" $2}'
642
while [ $i -le $numint ]
644
if [ "$GIS_FLAG_M" -eq 1 ] ; then
646
if [ "$first" = "true" ] ; then
659
if [ "$first" = "true" ] ; then
667
themecolor="$color1:$color2:$color3"
668
if [ "$GIS_FLAG_F" -eq 1 ] ; then
671
if [ "$GIS_OPT_TYPE" = "line" -o "$GIS_OPT_TYPE" = "boundary" ] ; then
672
linecolor=$themecolor
674
linecolor="$GIS_OPT_LINECOLOR"
678
rangemin=`echo $i $breakpoints | awk '{t=$1+1;print $t}'`
679
rangemax=`echo $i $breakpoints | awk '{t=$1+2;print $t}'`
681
if [ -z "$annotations" ]; then
684
extranote=`echo $annotations| cut -d';' -f$i`
687
if [ $i -lt $xlower -o $i -ge $xupper ]; then
688
xline1=`expr $line2 + 2`
689
xline3=`expr $line2 - 1`
690
echo "color $themecolor" >> "$TMP2"
691
echo "polygon" >> "$TMP2"
692
echo "5 $xline1" >> "$TMP2"
693
echo "8 $xline1" >> "$TMP2"
694
echo "8 $xline3" >> "$TMP2"
695
echo "5 $xline3" >> "$TMP2"
696
echo "color $linecolor" >> "$TMP2"
697
echo "move 5 $xline1" >> "$TMP2"
698
echo "draw 8 $xline1" >> "$TMP2"
699
echo "draw 8 $xline3" >> "$TMP2"
700
echo "draw 5 $xline3" >> "$TMP2"
701
echo "draw 5 $xline1" >> "$TMP2"
702
echo "move 14 $line2" >> "$TMP2"
703
echo "color 0:0:0" >> "$TMP2"
704
echo "text $openbracket$rangemin - $rangemax$closebracket $extranote" >> "$TMP2"
706
if [ $i -eq $xlower ]; then
707
echo "color 0:0:0" >> "$TMP2"
708
echo "move 10 $line2" >> "$TMP2"
709
echo "text ..." >> "$TMP2"
712
line2=`expr $line2 + 4`
716
if [ $i -lt $xlower -o $i -ge $xupper ]; then
717
echo "area $themecolor $linecolor - {$openbracket$rangemin - $rangemax$closebracket $extranote}" >> "$TMP6"
719
if [ "$GIS_OPT_TYPE" = "line" -o "$GIS_OPT_TYPE" = "boundary" ] ; then
720
echo "line 5% $xline1% 8% $xline1%" >> "$TMP5"
721
echo " color $linecolor" >> "$TMP5"
722
echo "end" >> "$TMP5"
723
echo "text 14% $xline1% $openbracket$rangemin - $rangemax$closebracket $extranote" >> "$TMP5"
724
echo " ref center left" >> "$TMP5"
725
echo "end" >> "$TMP5"
726
elif [ "$GIS_OPT_TYPE" = "point" -o "$GIS_OPT_TYPE" = "centroid" ] ; then
727
echo "point 8% $xline1%" >> "$TMP5"
728
echo " color $linecolor" >> "$TMP5"
729
echo " fcolor $themecolor" >> "$TMP5"
730
echo " size $GIS_OPT_SIZE" >> "$TMP5"
731
echo " symbol $GIS_OPT_ICON" >> "$TMP5"
732
echo "end" >> "$TMP5"
733
echo "text 14% $xline1% $openbracket$rangemin - $rangemax$closebracket $extranote" >> "$TMP5"
734
echo " ref center left" >> "$TMP5"
735
echo "end" >> "$TMP5"
737
echo "rectangle 5% $xline1% 8% $xline3%" >> "$TMP5"
738
echo " color 0:0:0" >> "$TMP5"
739
echo " fcolor $themecolor" >> "$TMP5"
740
echo "end" >> "$TMP5"
741
echo "text 14% $xline3% $openbracket$rangemin - $rangemax$closebracket DCADCA $extranote" >> "$TMP5"
742
echo " ref bottom left" >> "$TMP5"
743
echo "end" >> "$TMP5"
746
if [ $i -eq $xlower ]; then
747
echo "color 0:0:0" >>"$TMP5"
748
echo "text 14% $xline3% ..." >> "$TMP5"
749
echo " ref bottom left" >> "$TMP5"
750
echo "end" >> "$TMP5"
752
echo "text - - - {...}" >> "$TMP6"
758
echo $themecolor@$rangemin@$rangemax@$extranote@$openbracket@$closebracket | awk -F@ '{print $1 "\t\t" $5$2" - "$3$6" "$4}'
759
if [ -z "$GIS_OPT_WHERE" ] ; then
760
sqlwhere="$GIS_OPT_COLUMN $mincomparison $rangemin and $GIS_OPT_COLUMN<=$rangemax"
762
sqlwhere="$GIS_OPT_COLUMN $mincomparison $rangemin and $GIS_OPT_COLUMN<=$rangemax AND $GIS_OPT_WHERE"
765
# update color to database?
766
if [ $GIS_FLAG_U -eq 1 ] ; then
767
echo "UPDATE $table SET GRASSRGB = '$themecolor' WHERE\
768
$sqlwhere" | db.execute database="${database}" driver=${driver}
771
# Create group for GIS Manager
772
if [ "$GIS_FLAG_G" -eq 1 ] ; then
774
# change rgb colors to hex
775
xthemecolor=`echo $themecolor | awk -F: '{printf("#%02X%02X%02X\n",$1,$2,$3)}'`
776
# xlinecolor=`echo $linecolor | awk -F: '{printf("#%02X%02X%02X\n",$1,$2,$3)}'`
778
if [ "$linecolor" = "black" ] ; then
781
xlinecolor=$xthemecolor
785
echo " _check 1" >> "$TMP3"
786
echo " Vector $GIS_OPT_COLUMN = $rangemin - $rangemax" >> "$TMP3"
787
echo " _check 1" >> "$TMP3"
788
echo " map $GIS_OPT_MAP" >> "$TMP3"
789
echo " display_shape 1" >> "$TMP3"
790
echo " display_cat 0" >> "$TMP3"
791
echo " display_topo 0" >> "$TMP3"
792
echo " display_dir 0" >> "$TMP3"
793
echo " display_attr 0" >> "$TMP3"
794
echo " type_point $ptype" >> "$TMP3"
795
echo " type_line $ltype" >> "$TMP3"
796
echo " type_boundary $btype" >> "$TMP3"
797
echo " type_centroid $ctype" >> "$TMP3"
798
echo " type_area $atype" >> "$TMP3"
799
echo " type_face 0" >> "$TMP3"
800
echo " color $xlinecolor" >> "$TMP3"
801
echo " fcolor $xthemecolor" >> "$TMP3"
802
echo " width $ptsize" >> "$TMP3"
803
echo " _use_fcolor 1" >> "$TMP3"
804
echo " lcolor #000000" >> "$TMP3"
805
echo " sqlcolor 0" >> "$TMP3"
806
echo " icon $GIS_OPT_ICON" >> "$TMP3"
807
echo " size $ptsize" >> "$TMP3"
808
echo " field $GIS_OPT_LAYER" >> "$TMP3"
809
echo " lfield $GIS_OPT_LAYER" >> "$TMP3"
810
echo " attribute" >> "$TMP3"
811
echo " xref left" >> "$TMP3"
812
echo " yref center" >> "$TMP3"
813
echo " lsize 8" >> "$TMP3"
814
echo " cat" >> "$TMP3"
815
echo " where "$sqlwhere >> "$TMP3"
816
echo " _query_text 0" >> "$TMP3"
817
echo " _query_edit 1" >> "$TMP3"
818
echo " _use_where 1" >> "$TMP3"
819
echo " minreg" >> "$TMP3"
820
echo " maxreg" >> "$TMP3"
821
echo " _width 0.1" >> "$TMP3"
822
echo " End" >> "$TMP3"
826
# display theme vector map
828
d.vect map=$GIS_OPT_MAP type=$GIS_OPT_TYPE layer=$GIS_OPT_LAYER \
830
color=$linecolor fcolor=$themecolor icon=$GIS_OPT_ICON size=$ptsize
832
if [ "$GIS_OPT_TYPE" = "line" -o "$GIS_OPT_TYPE" = "boundary" ] ; then
833
echo "vlines $GIS_OPT_MAP" >> "$TMP4"
834
echo " type $GIS_OPT_TYPE" >> "$TMP4"
835
echo " layer $GIS_OPT_LAYER" >> "$TMP4"
836
echo " where $sqlwhere" >> "$TMP4"
837
echo " color $linecolor" >> "$TMP4"
838
echo " label $rangemin - $rangemax" >> "$TMP4"
839
echo "end" >> "$TMP4"
840
elif [ "$GIS_OPT_TYPE" = "point" -o "$GIS_OPT_TYPE" = "centroid" ] ; then
841
echo "vpoints $GIS_OPT_MAP" >> "$TMP4"
842
echo " type $GIS_OPT_TYPE" >> "$TMP4"
843
echo " layer $GIS_OPT_LAYER" >> "$TMP4"
844
echo " where $sqlwhere" >> "$TMP4"
845
echo " color $linecolor" >> "$TMP4"
846
echo " fcolor $themecolor" >> "$TMP4"
847
echo " symbol $GIS_OPT_ICON" >> "$TMP4"
848
echo " label $rangemin - $rangemax" >> "$TMP4"
849
echo "end" >> "$TMP4"
851
echo "vareas $GIS_OPT_MAP" >> "$TMP4"
852
echo " layer $GIS_OPT_LAYER" >> "$TMP4"
853
echo " where $sqlwhere" >> "$TMP4"
854
echo " color $linecolor" >> "$TMP4"
855
echo " fcolor $themecolor" >> "$TMP4"
856
echo " label $rangemin - $rangemax" >> "$TMP4"
857
echo "end" >> "$TMP4"
861
# increment for next theme
863
if [ $i = $numint ] ; then
868
color1=`expr $color1 - $clrstep1`
869
color2=`expr $color2 - $clrstep2`
870
color3=`expr $color3 - $clrstep3`
872
line1=`expr $line1 - 4`
873
line2=`expr $line2 - 4`
874
line3=`expr $line3 - 4`
879
#graduated points and line widths thematic mapping
881
if [ "$GIS_OPT_THEMETYPE" = "graduated_points" -o "$GIS_OPT_THEMETYPE" = "graduated_lines" ] ; then
883
#display graduated points/lines by intervals
884
if [ "$GIS_OPT_THEMECALC" = "interval" ] ; then
885
echo "move 4 87" >> "$TMP2"
886
echo "text Mapped by $numint intervals of $step" >> "$TMP2"
888
echo "subtitle - - - {Mapped by $numint intervals of $step}" >> "$TMP6"
890
echo "text 4% 87% Mapped by $numint intervals of $step" >> "$TMP5"
891
echo " ref bottom left" >> "$TMP5"
892
echo "end" >> "$TMP5"
894
g.message message="Mapped by $numint intervals of $step"
897
# display graduated points/lines for standard deviation units
898
if [ "$GIS_OPT_THEMECALC" = "std_deviation" ] ; then
900
echo "move 4 87" >> "$TMP2"
901
echo "text Mapped by standard deviation units of $sd (mean =$mean)" >> "$TMP2"
903
echo "subtitle - - - {Mapped by standard deviation units of $sd (mean =$mean)}" >> "$TMP6"
905
echo "text 4% 87% Mapped by standard deviation units of $sd (mean =$mean)" >> "$TMP5"
906
echo " ref bottom left" >> "$TMP5"
907
echo "end" >> "$TMP5"
909
g.message message="Mapped by standard deviation units of $sd (mean =$mean)"
912
# display graduated points/lines for quartiles
913
if [ "$GIS_OPT_THEMECALC" = "quartiles" ] ; then
915
echo "move 4 87" >> "$TMP2"
916
echo "text Mapped by quartiles (median =$q2)" >> "$TMP2"
918
echo "subtitle - - - {Mapped by quartiles (median =$q2)}" >> "$TMP6"
920
echo "text 4% 87% Mapped by quartiles (median =$q2)" >> "$TMP5"
921
echo " ref bottom left" >> "$TMP5"
922
echo "end" >> "$TMP5"
924
g.message message="Mapped by quartiles (median = $q2)"
929
echo "move 4 83" >> "$TMP2"
930
echo "text Size/width" >> "$TMP2"
931
echo "move 25 83" >> "$TMP2"
932
echo "text Value" >> "$TMP2"
933
echo "move 4 80" >> "$TMP2"
934
echo "text ==============" >> "$TMP2"
935
echo "move 25 80" >> "$TMP2"
936
echo "text ==============" >> "$TMP2"
939
echo "text 4% 83% Icon size" >> "$TMP5"
940
echo " ref bottom left" >> "$TMP5"
941
echo "end" >> "$TMP5"
942
echo "text 25% 83% Value" >> "$TMP5"
943
echo " ref bottom left" >> "$TMP5"
944
echo "end" >> "$TMP5"
945
echo "text 4% 80% ============" >> "$TMP5"
946
echo " ref bottom left" >> "$TMP5"
947
echo "end" >> "$TMP5"
948
echo "text 25% 80% ============" >> "$TMP5"
949
echo " ref bottom left" >> "$TMP5"
950
echo "end" >> "$TMP5"
953
echo "Size/width" "Value" | awk '{print $1 " " $2"\t"$3}'
954
echo "==========" "=====" | awk '{print $1 "\t" $2}'
956
themecolor=$GIS_OPT_POINTCOLOR
958
if [ "$GIS_FLAG_F" -eq 1 ] ; then
961
linecolor="$GIS_OPT_LINECOLOR"
965
ptsize=$GIS_OPT_MAXSIZE
969
if [ "$GIS_FLAG_M" -eq 1 ] ; then
971
if [ "$i" = "1" ] ; then
983
if [ "$i" = "1" ] ; then
990
themecolor=$GIS_OPT_POINTCOLOR
992
if [ "$GIS_FLAG_F" -eq 1 ] ; then
995
linecolor="$GIS_OPT_LINECOLOR"
998
rangemin=`echo $i $breakpoints | awk '{t=$1+1;print $t}'`
999
rangemax=`echo $i $breakpoints | awk '{t=$1+2;print $t}'`
1001
if [ -z "$annotations" ]; then
1004
extranote=`echo $annotations| cut -d';' -f$i`
1007
iconsize=`echo $ptsize | awk '{print int($1 / 2)}'`
1008
lineht=`echo $ptsize | awk '{print int($1 / 4)}'`
1009
if [ "$lineht" -lt "4" ] ; then
1013
if [ $i -lt $xlower -o $i -ge $xupper ]; then
1014
if [ "$GIS_OPT_THEMETYPE" = "graduated_lines" ]; then
1015
echo "color $linecolor" >> "$TMP2"
1016
echo "line $themecolor $linecolor $ptsize {$openbracket$rangemin - $rangemax$closebracket $extranote}" >> "$TMP6"
1018
echo "color $themecolor" >> "$TMP2"
1019
echo "point $themecolor $linecolor $ptsize {$openbracket$rangemin - $rangemax$closebracket $extranote}" >> "$TMP6"
1022
echo "icon + $iconsize 5 $line1" >> "$TMP2"
1023
echo "color 0:0:0" >> "$TMP2"
1024
echo "move 10 $line2" >> "$TMP2"
1025
echo "text $ptsize pts" >> "$TMP2"
1026
echo "move 25 $line2" >> "$TMP2"
1027
echo "text $openbracket$rangemin - $rangemax$closebracket $extranote" >> "$TMP2"
1029
if [ $i -eq $xlower ]; then
1030
echo "color 0:0:0" >>"$TMP2"
1031
echo "move 10 $line2" >> "$TMP2"
1032
echo "text ..." >> "$TMP2"
1033
echo "text - - - ..." >> "$TMP6"
1035
# undo future line increment
1036
line2=`expr $line2 + $lineht`
1040
if [ $i -lt $xlower -o $i -ge $xupper ]; then
1041
echo "point 8% $line1%" >> "$TMP5"
1042
echo " color $linecolor" >> "$TMP5"
1043
echo " fcolor $themecolor" >> "$TMP5"
1044
echo " size $iconsize" >> "$TMP5"
1045
echo " symbol $GIS_OPT_ICON" >> "$TMP5"
1046
echo "end" >> "$TMP5"
1047
echo "text 25% $line1% $openbracket$rangemin - $rangemax$closebracket $extranote" >> "$TMP5"
1048
echo " ref center left" >> "$TMP5"
1049
echo "end" >> "$TMP5"
1051
if [ $i -eq $xlower ]; then
1052
echo "text 25% $xline1% ..." >> "$TMP5"
1053
echo " ref center left" >> "$TMP5"
1054
echo "end" >> "$TMP5"
1058
echo $ptsize@$rangemin@$rangemax@$extranote@$openbracket@$closebracket | awk -F@ '{print $1 "\t\t" $5$2" - "$3$6" "$4}'
1060
if [ -z "$GIS_OPT_WHERE" ] ; then
1061
sqlwhere="$GIS_OPT_COLUMN $mincomparison $rangemin and $GIS_OPT_COLUMN<=$rangemax"
1063
sqlwhere="$GIS_OPT_COLUMN $mincomparison $rangemin and $GIS_OPT_COLUMN<=$rangemax AND $GIS_OPT_WHERE"
1066
# update color to database?
1067
if [ $GIS_FLAG_U -eq 1 ] ; then
1068
echo "UPDATE $table SET GRASSRGB = '$themecolor' WHERE\
1069
$sqlwhere" | db.execute database="${database}" driver=${driver}
1072
# Create group for GIS Manager
1073
if [ "$GIS_FLAG_G" -eq 1 ] ; then
1075
# change rgb colors to hex
1076
xthemecolor=`echo $themecolor | awk -F: '{printf("#%02X%02X%02X\n",$1,$2,$3)}'`
1077
xlinecolor="#000000"
1079
# create group entry
1080
echo " _check 1" >> "$TMP3"
1081
echo " Vector $GIS_OPT_COLUMN = $rangemin - $rangemax" >> "$TMP3"
1082
echo " _check 1" >> "$TMP3"
1083
echo " map $GIS_OPT_MAP" >> "$TMP3"
1084
echo " display_shape 1" >> "$TMP3"
1085
echo " display_cat 0" >> "$TMP3"
1086
echo " display_topo 0" >> "$TMP3"
1087
echo " display_dir 0" >> "$TMP3"
1088
echo " display_attr 0" >> "$TMP3"
1089
echo " type_point $ptype" >> "$TMP3"
1090
echo " type_line $ltype" >> "$TMP3"
1091
echo " type_boundary $btype" >> "$TMP3"
1092
echo " type_centroid $ctype" >> "$TMP3"
1093
echo " type_area $atype" >> "$TMP3"
1094
echo " type_face 0" >> "$TMP3"
1095
echo " color $xlinecolor" >> "$TMP3"
1096
echo " width $ptsize" >> "$TMP3"
1097
echo " fcolor $xthemecolor" >> "$TMP3"
1098
echo " _use_fcolor 1" >> "$TMP3"
1099
echo " lcolor #000000" >> "$TMP3"
1100
echo " sqlcolor 0" >> "$TMP3"
1101
echo " icon $GIS_OPT_ICON" >> "$TMP3"
1102
echo " size $ptsize" >> "$TMP3"
1103
echo " field $GIS_OPT_LAYER" >> "$TMP3"
1104
echo " lfield $GIS_OPT_LAYER" >> "$TMP3"
1105
echo " attribute" >> "$TMP3"
1106
echo " xref left" >> "$TMP3"
1107
echo " yref center" >> "$TMP3"
1108
echo " lsize 8" >> "$TMP3"
1109
echo " cat" >> "$TMP3"
1110
echo " where "$sqlwhere >> "$TMP3"
1111
echo " _query_text 0" >> "$TMP3"
1112
echo " _query_edit 1" >> "$TMP3"
1113
echo " _use_where 1" >> "$TMP3"
1114
echo " minreg" >> "$TMP3"
1115
echo " maxreg" >> "$TMP3"
1116
echo " _width 0.1" >> "$TMP3"
1117
echo " End" >> "$TMP3"
1120
#graduates line widths or point sizes
1122
if [ "$GIS_OPT_THEMETYPE" = "graduated_lines" ] ; then
1123
d.vect map=$GIS_OPT_MAP type=$GIS_OPT_TYPE layer=$GIS_OPT_LAYER \
1125
color=$linecolor fcolor=$themecolor icon=$GIS_OPT_ICON size=$ptsize \
1128
d.vect map=$GIS_OPT_MAP type=$GIS_OPT_TYPE layer=$GIS_OPT_LAYER \
1130
color=$linecolor fcolor=$themecolor icon=$GIS_OPT_ICON size=$ptsize
1133
echo "vpoints $GIS_OPT_MAP" >> "$TMP4"
1134
echo " type $GIS_OPT_TYPE" >> "$TMP4"
1135
echo " layer $GIS_OPT_LAYER" >> "$TMP4"
1136
echo " where $sqlwhere" >> "$TMP4"
1137
echo " color $linecolor" >> "$TMP4"
1138
echo " fcolor $themecolor" >> "$TMP4"
1139
echo " symbol $GIS_OPT_ICON" >> "$TMP4"
1140
echo " size $ptsize" >> "$TMP4"
1141
echo " label $rangemin - $rangemax" >> "$TMP4"
1142
echo "end" >> "$TMP4"
1145
ptsize=`echo $ptsize $pointstep | awk '{print $1 - $2}'`
1147
line1=`expr $line1 - $lineht`
1148
line2=`expr $line2 - $lineht`
1154
if [ "$GIS_FLAG_S" -eq 1 ] ; then
1155
# reset display parameters
1156
GRASS_PNG_READ=$pngread
1157
export GRASS_PNG_READ
1158
GRASS_PNG_AUTO_WRITE=$autowrite
1159
export GRASS_PNG_AUTO_WRITE
1162
# Create graphic legend
1163
if [ "$GIS_FLAG_L" -eq 1 -a "$GIS_OPT_MONITOR" != "none" ] ; then
1164
if [ `eval d.mon -L | grep $GIS_OPT_MONITOR | awk '{print $5}'` = "not" ] ; then
1165
d.mon start=$GIS_OPT_MONITOR > /dev/null
1167
d.mon select=$GIS_OPT_MONITOR > /dev/null
1170
d.graph input="$TMP2"
1171
if [ -n "$currmon" ] ; then
1172
d.mon select=$currmon
1176
# Create group file for GIS Manager
1177
echo "End" >> "$TMP3"
1178
if [ "$GIS_FLAG_G" -eq 1 ] ; then
1179
cat "$TMP3" > "${group}.dm"
1182
# Create ps.map map file
1183
echo "end" >> "$TMP4"
1184
if [ "$GIS_OPT_PSMAP" ] ; then
1185
cat "$TMP4" > "$GIS_OPT_PSMAP.psmap"
1188
# Create ps.map legend file
1189
echo "end" >> "$TMP5"
1190
if [ "$GIS_OPT_PSMAP" ] ; then
1191
cat "$TMP5" > "$GIS_OPT_PSMAP\_legend.psmap"
1194
# Create text file to use with d.graph in GIS Manager
1195
if [ "$GIS_FLAG_S" -eq 1 ] ; then
1196
tmpdir=`eval dirname "$TMP6"`
1197
tlegfile="$tmpdir/gismlegend.txt"
1198
# echo $tlegfile > outtxt.txt
1199
cp "$TMP6" "$tlegfile"