Software: Apache, PHP4, GRASS 6
What happens here?
The server is fetching the current list of earthquakes from
http://neic.usgs.gov/neis/gis/bulletin.asc
and generates a vector map with attributes from that. The result is overlayed to the
Blue Marble Next Generation map from May.
//
// Home: http://grass.itc.it/spearfish/php_grassmap.php
//
// Inspired by:
// http://grass.itc.it/pipermail/grass5/2004-August/015106.html
//
// Possible improvements:
// - use PHP session to avoid race conditions
// (use session name as mapset etc)
// - replace system calls by GRASS-SWIG-PHP interface
// Approach:
// GRASS is simply a set of commands which need to be run in
// a pre-defined environment. A map is generated as PNG file
// and then visualized.
// To keep it simple, we use system commands. Note the trailing
// semicolon for each command, otherwise it won't work.
// Prerequisites:
// Add 'MONITOR: PNG' to the .grassrc6 file (see GISRC below).
// Update also the path to the location. This and GRASS location need
// owner/group of Web server (e.g. 'apache' user/group) as the
// Web server software launches GRASS.
// Also this directory where the files/map is generated, needs to
// be owned by the Web server user.
//
// ---------------------
// 1. define the environment settings:
putenv("GISBASE=/usr/local/grass-6.1.cvs");
putenv("PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/grass-6.1.cvs/bin:/usr/local/grass-6.1.cvs/scripts");
putenv("LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/grass-6.1.cvs/lib");
// note that the GRASS location needs owner/group of Web server (e.g. 'apache' user/group)
putenv("GISRCRC=/grass0/neteler/www/spearfish/.grassrc6_ll");
putenv("GISRC=/tmp/gisrc");
// also the output files need owner/group of Web server:
putenv("GRASS_PNGFILE=earthquakes.png");
putenv("GRASS_TRUECOLOR=TRUE");
putenv("GRASS_WIDTH=900");
putenv("GRASS_PNG_COMPRESSION=1");
putenv("HOME=/tmp");
putenv("GIS_LOCK=$$");
// Debug only:
system("env > environment_vars2.txt");
// fetch & polish earthquake data:
system("
lynx -dump http://neic.usgs.gov/neis/gis/bulletin.asc > /tmp/bulletin.tmp;
cat /tmp/bulletin.tmp | sed 's+ ++g' | grep -v ',,' | grep -v '^$' > bulletin.asc;
");
// 2. Now we start to process things and create a map:
// cleanup stuff from previous session
system("rm -f grasserrors2.txt grassmsgs2.txt;");
// watch out for quotes-in-quotes in SQL commands:
//
// Next comment just left for me:
// #optimal class table
// # http://earthquake.usgs.gov/eqcenter/recenteqsww/glossary.php#class
// #d.vect.thematic recent_earthquakes column=class type=point themetype=graduated_points maxsize=20 nint=6 >> grassmsgs2.txt;
// #
// # http://neic.usgs.gov/neis/gis/recent.asc seems to be buggy recently (4/2006)
//
// 3. GRASS session....
// Debug only: simple GRASS command:
// system("g.version > version_info2.txt 2> grasserrors2.txt");
system("
g.gisenv;
g.region -d ;
d.mon PNG 2>> grasserrors2.txt;
cat bulletin.asc | v.in.ascii out=recent_earthquakes skip=1 fs=',' y=3 x=4 col='e_date date, e_time varchar(10), lat double precision, long double precision, magnitude double precision, depth double precision' --o >> grassmsgs2.txt ;
v.db.addcol recent_earthquakes col='class integer' ;
v.db.update recent_earthquakes col=class value=1 where='magnitude < 3' ;
v.db.update recent_earthquakes col=class value=2 where='magnitude >=3 AND magnitude < 4' ;
v.db.update recent_earthquakes col=class value=3 where='magnitude >=4 AND magnitude < 5' ;
v.db.update recent_earthquakes col=class value=4 where='magnitude >=5 AND magnitude < 6' ;
v.db.update recent_earthquakes col=class value=5 where='magnitude >=6 AND magnitude < 7' ;
v.db.update recent_earthquakes col=class value=6 where='magnitude >=8' ;
d.rast BMNG_May.rgb ;
echo '' ;
d.vect.thematic recent_earthquakes column=class type=point themetype=graduated_points maxsize=20 nint=6 >> grassmsgs2.txt;
echo '
' ;
d.mon stop=PNG ;
g.remove vect=recent_earthquakes ;
rm -f earthquakes_small.jpg ;
convert -geometry 75% earthquakes.png earthquakes_small.jpg;
convert -geometry 40% earthquakes.png earthquakes_tiny.jpg; ");
?>
Earthquake classification (circles in map are sized by these classes)
Magnitude | Classification | Class for map |
0 - 3 | Micro | 1 |
3 - 3.9 | Minor | 2 |
4 - 4.9 | Light | 3 |
5 - 5.9 | Moderate | 4 |
6 - 6.9 | Strong | 5 |
7 - 7.9 | Major | 6 |
8 and higher | Great | 7 |
Here a map should appear:
Oldest event from:
UTC ; Latest event from:
UTC
Latest events drawn last.
For earthquake details, visit Latest Earthquakes in the World - Last 7 days from USGS.