Psmap flooding example: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
m (htmlmap driver link)
 
(9 intermediate revisions by the same user not shown)
Line 4: Line 4:
== About ==
== About ==


This is simple ps.map script demonstrating variable text & queries. It is based on [http://article.gmane.org/gmane.comp.gis.grass.user/20983/ this mailing list post].
This is a simple ps.map script demonstrating variable text & queries.  


It builds on the Spearfish catchments generated in the [http://grass.ibiblio.org/grass63/manuals/html63_user/r.watershed.html r.watershed help page example]. All you need to specify is catchments at risk, it does the rest.
It is based on [http://article.gmane.org/gmane.comp.gis.grass.user/20983/ this mailing list post] and considers a hypothetical dynamic flood risk warning map generator.
 
It builds on the Spearfish catchments generated by the [http://grass.ibiblio.org/grass63/manuals/html63_user/r.watershed.html r.watershed help page example]. All you need to specify is catchments at risk, the script generates the rest.


== Screenshots ==
== Screenshots ==
Line 12: Line 14:


screenshot of whole catchment warning:
screenshot of whole catchment warning:
http://bambi.otago.ac.nz/hamish/grass/screenshots/flood_warning_basins.png
 
: [[Image:Flood_warning_basins.png|320px]]


-----
-----
Line 18: Line 21:


screenshot of low-lying areas warning:
screenshot of low-lying areas warning:
http://bambi.otago.ac.nz/hamish/grass/screenshots/flood_warning_lowlying.png
 
: [http://grass.ibiblio.org/grass63/screenshots/images/flood_warning_lowlying.png  http://grass.ibiblio.org/grass63/screenshots/images/flood_warning_lowlying_small.jpg]
 


-----
-----
Line 24: Line 29:


screenshot of Spearfish catchments:
screenshot of Spearfish catchments:
: http://grass.itc.it/screenshots/raster.php
 
: [http://grass.ibiblio.org/grass63/screenshots/images/spearfish_catchements.png  http://grass.ibiblio.org/grass63/screenshots/images/spearfish_catchements_small.png]


== The script ==
== The script ==


First we need to generate polygons for low lying ares from each catchment created with the [http://grass.ibiblio.org/grass63/manuals/html63_user/r.watershed.html r.watershed help page example]:
First we need to generate polygons for low lying ares from each catchment created with the [http://grass.ibiblio.org/grass63/manuals/html63_user/r.watershed.html r.watershed help page example].
 
Next we designate the low lying areas. Ideally this would come from a real-time hydrologic model, but as this is an example we just make something up:


<pre>
<pre>
# create danger polygons for each catchment
# create danger polygons for each catchment
#  (homebrew example of predictor for at-risk lowlying areas)
#  (homebrew example of predictor for at-risk low-lying areas)
r.cost -k in=slope out=slope_cost_from_rivers start_rast=rwater.course
r.cost -k in=slope out=slope_cost_from_rivers start_rast=rwater.course
r.colors slope_cost_from_rivers col=bcyr -e
r.colors slope_cost_from_rivers col=bcyr -e
Line 48: Line 56:
</pre>
</pre>


Next we set the dynamic data, either automatically from model output or though interactive selection & highlight of areas (e.g. a script using the HTMLMAP driver, 'd.what.vect -xft', or d.ask)
 
Next we set the dynamic data, either automatically from model output or though interactive selection & highlight of areas (e.g. a script using the [[HTMLMAP driver]], 'd.what.vect -xft', or d.ask)


<pre>
<pre>
Line 100: Line 109:
</pre>
</pre>


Finally we conver the output PostScript image to PDF and PNG formats.
Finally we convert the output PostScript image to PDF and PNG formats.
<pre>
<pre>
# convert to PDF
# convert to PDF
Line 110: Line 119:


The PDF output looks the best.
The PDF output looks the best.


== Rendering issues ==
== Rendering issues ==
Line 117: Line 125:
:These do not appear in PDF + acrobat reader.
:These do not appear in PDF + acrobat reader.
* EPS hatch patterns are tiled so fill lines have slightly noticeable breaks.
* EPS hatch patterns are tiled so fill lines have slightly noticeable breaks.
* We need to add something to allow skipping vectors in ps.map's vlegends
 
: ideas: labelskip [y|N],  test for label='' or 'none' or 'skip'?
 
[[Category:ps.map]]

Latest revision as of 08:03, 8 October 2010


About

This is a simple ps.map script demonstrating variable text & queries.

It is based on this mailing list post and considers a hypothetical dynamic flood risk warning map generator.

It builds on the Spearfish catchments generated by the r.watershed help page example. All you need to specify is catchments at risk, the script generates the rest.

Screenshots

screenshot of whole catchment warning:



screenshot of low-lying areas warning:

http://grass.ibiblio.org/grass63/screenshots/images/flood_warning_lowlying_small.jpg




screenshot of Spearfish catchments:

http://grass.ibiblio.org/grass63/screenshots/images/spearfish_catchements_small.png

The script

First we need to generate polygons for low lying ares from each catchment created with the r.watershed help page example.

Next we designate the low lying areas. Ideally this would come from a real-time hydrologic model, but as this is an example we just make something up:

# create danger polygons for each catchment
#  (homebrew example of predictor for at-risk low-lying areas)
r.cost -k in=slope out=slope_cost_from_rivers start_rast=rwater.course
r.colors slope_cost_from_rivers col=bcyr -e

# choose some threshold. this could be based on hydrologic model output.
#  for now just set for lower half of slope-costs in the map
eval `r.univar -g slope_cost_from_rivers`
r.mapcalc "flood.zones = if(slope_cost_from_rivers < $mean, \
     rwater.basin, null() )"

# convert to vector areas
r.to.vect -s in=flood.zones out=flood_zones feature=area
v.db.dropcol map=flood_zones column=label
v.db.renamecol map=flood_zones column=value,catchment


Next we set the dynamic data, either automatically from model output or though interactive selection & highlight of areas (e.g. a script using the HTMLMAP driver, 'd.what.vect -xft', or d.ask)

# Here we say catchment #6 and #12 are at risk.

FLOOD_BASINS=6,12
TIMESTAMP=`date`


The rest is a static template. Here we pass the command through the shell but the input file could be written to a file (taking care to process environment variables) and then passed to ps.map's input option.

# convert catchment list to SQL query
FLOOD_BASIN_SQL=`echo $FLOOD_BASINS | \
  sed -e 's/^/catchment = /' -e 's/,/ OR catchment = /g'`

# generate PostScript image
ps.map out=flood_warning.ps << EOF
raster elevation.dem
# example of dashed lines
vlines roads
  style 000011
  where label ~ 'highway'
  width 0.25
  label Highways
  end
vlines rwater_course
  color grey
  label Water courses
  end
vareas rwater_basins
#change to "flood_zones" vector map for lowlying areas instead of
#  entire catchment
  where $FLOOD_BASIN_SQL
  color red
  fcolor red
  width 2
  pat $GISBASE/etc/paint/patterns/diag_up.eps
  label Catchements subject to flood risk
  end
vlegend
  end
text 100% -3% Warning issued $TIMESTAMP
  font Helvetica-BoldOblique
  fontsize 12
  ref right
  end
end
EOF

Finally we convert the output PostScript image to PDF and PNG formats.

# convert to PDF
ps2pdf flood_warning.ps
# convert to PNG
pstoimg -antialias -aaliastext -out flood_warning.png -scale 1.3 \
  -crop tb flood_warning.ps

The PDF output looks the best.

Rendering issues

  • EPS hatch pattern renders in gv and PNG with black boxes behind lines??
These do not appear in PDF + acrobat reader.
  • EPS hatch patterns are tiled so fill lines have slightly noticeable breaks.