[GRASS-SVN] r52104 - grass-promo/tutorials/batch_processing/earthquakes/php_demo

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 17 00:08:43 PDT 2012


Author: hamish
Date: 2012-06-17 00:08:42 -0700 (Sun, 17 Jun 2012)
New Revision: 52104

Added:
   grass-promo/tutorials/batch_processing/earthquakes/php_demo/earthquakes.png
   grass-promo/tutorials/batch_processing/earthquakes/php_demo/grass_earthquakes.sh
   grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.php
   grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.txt
   grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes_PHP4.txt
Log:
+ Markus N's Earthquake PHP demo

Added: grass-promo/tutorials/batch_processing/earthquakes/php_demo/earthquakes.png
===================================================================
(Binary files differ)


Property changes on: grass-promo/tutorials/batch_processing/earthquakes/php_demo/earthquakes.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Added: grass-promo/tutorials/batch_processing/earthquakes/php_demo/grass_earthquakes.sh
===================================================================
--- grass-promo/tutorials/batch_processing/earthquakes/php_demo/grass_earthquakes.sh	                        (rev 0)
+++ grass-promo/tutorials/batch_processing/earthquakes/php_demo/grass_earthquakes.sh	2012-06-17 07:08:42 UTC (rev 52104)
@@ -0,0 +1,110 @@
+#!/bin/sh
+
+# 2006 Markus Neteler
+#
+#      This program is free software under the GNU General Public
+#      License (>=v2). Read the file COPYING that comes with GRASS
+#      for details.
+#######
+# Script to launch GRASS, fetch the USGS list of recent
+# earthquakes, generate map, leave GRASS.
+#
+# Inspired by
+#   http://grass.itc.it/spearfish/php_grass_earthquakes.php
+#
+# Requirements:
+# - grass6 installation
+# - latitude-longitude GRASS location (= GRASS project)
+#######################################################
+
+# some settings:
+TMPDIR=/tmp
+
+# directory of our software and grassdata:
+MAINDIR=/asd0/ssi/neteler_grid/software
+# our private /usr/ directory:
+MYUSER=$MAINDIR/myusr
+
+# path to GRASS binaries and libraries:
+export GISBASE=$MYUSER/grass-6.1.cvs
+
+# generate GRASS settings file:
+# the file contains the GRASS variables which define the LOCATION etc.
+echo "GISDBASE: $MAINDIR/grassdata
+LOCATION_NAME: latlong
+MAPSET: PERMANENT
+" > $TMPDIR/.grassrc6_earthquakes
+
+# path to GRASS settings file:
+export GISRC=$TMPDIR/.grassrc6_earthquakes
+
+# first our GRASS, then the rest
+export PATH=$GISBASE/bin:$GISBASE/scripts:$PATH
+#first have our private libraries:
+export LD_LIBRARY_PATH=$MYUSER/lib:$GISBASE/lib:$LD_LIBRARY_PATH
+
+# settings for graphical output
+PNGOUTPUTDIR=$TMPDIR
+# current date
+DATE=`LC_ALL=C date -R | tr -s ' ' ' ' | cut -d' ' -f2,3,4 | tr -s ' ' '_'`
+export GRASS_PNGFILE=$PNGOUTPUTDIR/grass6_recent_earthquakes_${DATE}.png
+export GRASS_TRUECOLOR=TRUE
+export GRASS_WIDTH=900
+export GRASS_PNG_COMPRESSION=1
+
+# use process ID (PID) as lock file number:
+export GIS_LOCK=$$
+
+
+##### the algorithms goes here
+
+error_routine () {
+ echo "ERROR: $1"
+ exit 1
+}
+
+# fetch last earthquake bulletin:
+lynx -dump http://neic.usgs.gov/neis/gis/bulletin.asc > $TMPDIR/bulletin.tmp || error_routine "lynx"
+cat $TMPDIR/bulletin.tmp | sed 's+ ++g' | grep -v ',,' | grep -v '^$' > $TMPDIR/bulletin.asc
+
+# set region to default settings (here: world)
+g.region -d || error_routine "g.region"
+
+#open PNG output
+d.mon start=PNG || error_routine "d.mon start=PNG"
+
+# import earthquake bulletin:
+cat $TMPDIR/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 || error_routine "v.in.ascii"
+
+# add new columns for magnitude classification:
+v.db.addcol recent_earthquakes col='class integer' || error_routine "v.db.addcol"
+v.db.update recent_earthquakes col=class value=1 where='magnitude < 3'  || error_routine "v.db.addcol"
+v.db.update recent_earthquakes col=class value=2 where='magnitude >=3 AND magnitude < 4'  || error_routine "v.db.addcol"
+v.db.update recent_earthquakes col=class value=3 where='magnitude >=4 AND magnitude < 5'  || error_routine "v.db.addcol"
+v.db.update recent_earthquakes col=class value=4 where='magnitude >=5 AND magnitude < 6'  || error_routine "v.db.addcol"
+v.db.update recent_earthquakes col=class value=5 where='magnitude >=6 AND magnitude < 7'  || error_routine "v.db.addcol"
+v.db.update recent_earthquakes col=class value=6 where='magnitude >=8'  || error_routine "v.db.addcol"
+
+# display nice world satellite background image (already saved in LOCAITON):
+d.rast BMNG_May.rgb || error_routine "d.rast"
+
+# show classified earthquakes:
+d.vect.thematic recent_earthquakes column=class type=point \
+  themetype=graduated_points maxsize=20 nint=6  || error_routine "d.vect.thematic"
+
+# close PNG output
+d.mon stop=PNG  || error_routine "d.mon stop"
+
+# remove imported map, no longer needed:
+g.remove vect=recent_earthquakes  || error_routine "g.remove"
+rm -f $TMPDIR/bulletin.asc $TMPDIR/bulletin.tmp
+
+# remove internal tmp stuff:
+$GISBASE/etc/clean_temp  || error_routine "clean_temp"
+rm -rf $TMPDIR/grass6-$USER-$GIS_LOCK
+
+# done.
+echo "Generated $GRASS_PNGFILE"
+


Property changes on: grass-promo/tutorials/batch_processing/earthquakes/php_demo/grass_earthquakes.sh
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native

Added: grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.php
===================================================================
--- grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.php	                        (rev 0)
+++ grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.php	2012-06-17 07:08:42 UTC (rev 52104)
@@ -0,0 +1,92 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<head>
+  <title>GRASS/PHP Server Sample page: Current Earthquakes</title>
+  <meta name="Author" content="Markus Neteler, 2006">
+  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+</head>
+<body bgcolor="#FFFFFF">
+
+<h2>Recent Earthquakes: map generated by GRASS on the fly with PHP</h2>
+<P>
+Software: Apache, PHP5, GRASS 6 (see <a href="php_grass_earthquakes_PHP4.txt">here</a> for PHP4 example; 
+ <a href="http://mpa.itc.it/markus/grass63/earthquakes/">here</a> for GRASS location with world map)
+<P>
+What happens here?<br>
+The server is fetching the current list of earthquakes from
+<i>http://neic.usgs.gov/neis/gis/bulletin.asc</i>
+and generates a vector map with attributes from that. The result is overlayed to the
+Blue Marble Next Generation map from May.
+
+
+<SMALL><PRE>
+</PRE></SMALL>
+
+<br>
+<b>Earthquake classification (circles in map are sized by these classes)</b>
+<table border="1" cellpadding="2" cellspacing="0">
+<tbody><tr>
+<td align="center"><b>Magnitude</b></td>
+<td align="center"><b>Classification</b></td>
+<td align="center"><b>Class for map</b></td>
+</tr>
+<tr>
+<td align="center">0 - 3</td>
+<td align="center">Micro</td>
+<td align="center">1</td>
+</tr>
+<tr>
+<td align="center">3 - 3.9</td>
+<td align="center">Minor</td>
+<td align="center">2</td>
+</tr>
+<tr>
+<td align="center">4 - 4.9</td>
+<td align="center">Light</td>
+<td align="center">3</td>
+</tr>
+<tr>
+<td align="center">5 - 5.9</td>
+<td align="center">Moderate</td>
+<td align="center">4</td>
+</tr>
+<tr>
+<td align="center">6 - 6.9</td>
+<td align="center">Strong</td>
+<td align="center">5</td>
+</tr>
+<tr>
+<td align="center">7 - 7.9</td>
+<td align="center">Major</td>
+<td align="center">6</td>
+</tr>
+<tr>
+<td align="center">8 and higher</td>
+<td align="center">Great</td>
+<td align="center">7</td>
+</tr>
+</tbody></table>
+<p>
+Here a map should appear:<p>
+
+Oldest event from: 
+10/11/30 10:45:09
+UTC ; Latest event from: 
+10/12/07 09:38:31
+ UTC <br>
+82 earthquakes on this map
+<br>
+Latest events drawn last.
+<p>
+<a href="earthquakes.png" border="0"><img src="earthquakes_small.jpg" alt="Auto-generated earthquake map (GRASS GIS/PHP based)"></a><br>
+<i>Click for high-res map</i>
+
+<p>
+For earthquake details, visit <a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/">Latest Earthquakes in the World - Last 7 days</a> from USGS.
+<hr>
+2006 Markus Neteler (based on comments from Sharyn Namnath and Glynn Clements)
+<br>
+<a href="php_grass_earthquakes.txt">Download PHP page source code</a> <br>
+<a href="grass_earthquakes.sh">Download the script implemented as SHELL script code</a>
+</body>
+</html>

Added: grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.txt
===================================================================
--- grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.txt	                        (rev 0)
+++ grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.txt	2012-06-17 07:08:42 UTC (rev 52104)
@@ -0,0 +1,242 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<head>
+  <title>GRASS/PHP Server Sample page: Current Earthquakes</title>
+  <meta name="Author" content="Markus Neteler, 2006">
+  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+</head>
+<body bgcolor="#FFFFFF">
+
+<h2>Recent Earthquakes: map generated by GRASS on the fly with PHP</h2>
+<P>
+Software: Apache, PHP5, GRASS 6 (see <a href="php_grass_earthquakes_PHP4.txt">here</a> for PHP4 example; 
+ <a href="http://mpa.itc.it/markus/grass63/earthquakes/">here</a> for GRASS location with world map)
+<P>
+What happens here?<br>
+The server is fetching the current list of earthquakes from
+<i>http://neic.usgs.gov/neis/gis/bulletin.asc</i>
+and generates a vector map with attributes from that. The result is overlayed to the
+Blue Marble Next Generation map from May.
+
+<?php
+  // FOR DEBUG ONLY: Show all information, defaults to INFO_ALL
+  // uncomment next line to check if and which version of PHP is running:
+  // phpinfo();
+?>
+
+<?php
+  /////////////// PHP 5 - work in progress ///////////////////
+  // for PHP4 solution, see http://grass.itc.it/spearfish/php_grass_earthquakes_PHP4.php
+  //
+  //
+  // Quick-and-dirty implementation. Complaints to /dev/null, 
+  // suggestions to <neteler itc it>
+  //
+  // Home: http://grass.itc.it/spearfish/php_grass_earthquakes.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 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. The GRASS location needs to be
+  //    recursively set to the owner/group of Web server (e.g. 'apache' user/group) 
+  //    as the Web server software launches GRASS. Check for access permissions
+  //    also in the parent directories.
+  //    Also this directory where the files/map is generated, needs to
+  //    be owned by the Web server user.
+  //
+  // ---------------------
+  // Here we go:
+  // 1. define the environment settings (full path everywhere):
+  
+  
+$descriptorspec = array(
+    0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
+    1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
+    2 => array("pipe", "w") // stderr is a file to write to
+);
+
+$cwd = '.';
+
+// define environment variables
+$env = array(
+  'GISBASE' => '/usr/local/grass-6.1.cvs',
+  'PATH'    => '/bin:/usr/bin:/usr/local/bin:/usr/local/grass-6.1.cvs/bin:/usr/local/grass-6.1.cvs/scripts',
+
+  // WARNING: probably protected in /etc/php.ini (see 'safe_mode_protected_env_vars')
+  '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)
+  'GISRC' => '/krokus0/www/grass/html/spearfish/.grassrc6_ll',
+
+  // also the output files need owner/group of Web server:
+  'GRASS_PNGFILE' => 'earthquakes.png',
+  'GRASS_TRUECOLOR' => 'TRUE',
+  'GRASS_WIDTH' => '900',
+  'GRASS_PNG_COMPRESSION' => '1',
+
+  'HOME' => '/tmp',
+  // better use posix_getpid();
+  'GIS_LOCK' => '$$'
+);
+
+// 3. fetch & polish earthquake data
+//    GRASS session....
+//      watch out for quotes-in-quotes in SQL commands and $:
+
+$command = "
+  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;
+  env > environment_vars2.txt;
+
+  rm -f grasserrors2.txt grassmsgs2.txt;
+
+  echo \$LD_LIBRARY_PATH >> grasserrors2.txt;
+  echo \$PATH >> grasserrors2.txt;
+  echo \$GISBASE >> grasserrors2.txt;
+  echo \$GISRC >> grasserrors2.txt;
+  echo \$GIS_LOCK >> grasserrors2.txt;
+
+  g.region -d >> grasserrors2.txt;
+  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 2>> grasserrors2.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' ;
+
+  # center at Pacific
+  g.region w=-18 e=-18
+  d.rast BMNG_May.rgb >> grassmsgs2.txt 2>> grasserrors2.txt;
+  echo '<SMALL><PRE>' ;
+  d.vect.thematic recent_earthquakes column=class type=point themetype=graduated_points maxsize=20 nint=6 >> grassmsgs2.txt >> grassmsgs2.txt 2>> grasserrors2.txt;
+  echo '</PRE></SMALL>' ;
+  d.mon stop=PNG >> grassmsgs2.txt 2>> grasserrors2.txt;
+  g.remove vect=recent_earthquakes >> grassmsgs2.txt 2>> grasserrors2.txt;
+
+  \$GISBASE/etc/clean_temp
+  rm -rf /tmp/grass6-\$USER-\$GIS_LOCK
+ 
+  rm -f earthquakes_small.jpg ;
+  convert -geometry 75% earthquakes.png earthquakes_small.jpg;
+  convert -geometry 40% earthquakes.png earthquakes_tiny.jpg;
+    
+"; // command
+
+$process = proc_open($command, $descriptorspec, $pipes, $cwd, $env);
+
+if (is_resource($process)) {
+// $pipes now looks like this:
+// 0 => writeable handle connected to child stdin
+// 1 => readable handle connected to child stdout
+// 2 => readable handle connected to child stderr
+		  
+fwrite($pipes[0], '<?php print_r($_ENV); ?>');
+fclose($pipes[0]);
+			      
+
+echo stream_get_contents($pipes[1]);
+fclose($pipes[1]);
+				  
+echo stream_get_contents($pipes[2]);
+fclose($pipes[2]);
+			      
+$return_value = proc_close($process);
+			        
+//echo $return_value;
+}
+
+
+?>
+
+<br>
+<b>Earthquake classification (circles in map are sized by these classes)</b>
+<table border="1" cellpadding="2" cellspacing="0">
+<tbody><tr>
+<td align="center"><b>Magnitude</b></td>
+<td align="center"><b>Classification</b></td>
+<td align="center"><b>Class for map</b></td>
+</tr>
+<tr>
+<td align="center">0 - 3</td>
+<td align="center">Micro</td>
+<td align="center">1</td>
+</tr>
+<tr>
+<td align="center">3 - 3.9</td>
+<td align="center">Minor</td>
+<td align="center">2</td>
+</tr>
+<tr>
+<td align="center">4 - 4.9</td>
+<td align="center">Light</td>
+<td align="center">3</td>
+</tr>
+<tr>
+<td align="center">5 - 5.9</td>
+<td align="center">Moderate</td>
+<td align="center">4</td>
+</tr>
+<tr>
+<td align="center">6 - 6.9</td>
+<td align="center">Strong</td>
+<td align="center">5</td>
+</tr>
+<tr>
+<td align="center">7 - 7.9</td>
+<td align="center">Major</td>
+<td align="center">6</td>
+</tr>
+<tr>
+<td align="center">8 and higher</td>
+<td align="center">Great</td>
+<td align="center">7</td>
+</tr>
+</tbody></table>
+<p>
+Here a map should appear:<p>
+
+Oldest event from: 
+<?php
+ system("head -2 bulletin.asc  | tail -1 | cut -d',' -f1-2 | tr ',' ' '");
+?>
+UTC ; Latest event from: 
+<?php
+ system("tail -1 bulletin.asc | cut -d',' -f1-2 | tr ',' ' '");
+?>
+ UTC <br>
+<?php
+ system("echo \"`cat bulletin.asc  | grep -vi Date | wc -l | awk '{print $1}'` earthquakes on this map\"");
+?>
+<br>
+Latest events drawn last.
+<p>
+<a href="earthquakes.png" border="0"><img src="earthquakes_small.jpg" alt="Auto-generated earthquake map (GRASS GIS/PHP based)"></a><br>
+<i>Click for high-res map</i>
+
+<p>
+For earthquake details, visit <a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/">Latest Earthquakes in the World - Last 7 days</a> from USGS.
+<hr>
+2006 Markus Neteler (based on comments from Sharyn Namnath and Glynn Clements)
+<br>
+<a href="php_grass_earthquakes.txt">Download PHP page source code</a> <br>
+<a href="grass_earthquakes.sh">Download the script implemented as SHELL script code</a>
+</body>
+</html>


Property changes on: grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes.txt
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes_PHP4.txt
===================================================================
--- grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes_PHP4.txt	                        (rev 0)
+++ grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes_PHP4.txt	2012-06-17 07:08:42 UTC (rev 52104)
@@ -0,0 +1,200 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<HTML>
+<head>
+  <title>GRASS/PHP Server Sample page: Current Earthquakes</title>
+  <meta name="Author" content="Markus Neteler, 2006">
+  <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
+</head>
+<body bgcolor="#FFFFFF">
+
+<h2>Recent Earthquakes: map generated by GRASS on the fly with PHP</h2>
+<P>
+Software: Apache, PHP4, GRASS 6
+<P>
+What happens here?<br>
+The server is fetching the current list of earthquakes from
+<i>http://neic.usgs.gov/neis/gis/bulletin.asc</i>
+and generates a vector map with attributes from that. The result is overlayed to the
+Blue Marble Next Generation map from May.
+
+<?php
+  // FOR DEBUG ONLY: Show all information, defaults to INFO_ALL
+  // uncomment next line to check if and which version of PHP is running:
+//phpinfo();
+?>
+
+<?php
+  // PHP 4, doesn't work with PHP5 (see instead:
+  //       http://grass.itc.it/spearfish/php_grass_earthquakes.php )
+  //
+  // Quick-and-dirty implementation. Complaints to /dev/null, 
+  // suggestions to <neteler itc it>
+  //
+  // 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 '<SMALL><PRE>' ;
+    d.vect.thematic recent_earthquakes column=class type=point themetype=graduated_points maxsize=20 nint=6 >> grassmsgs2.txt;
+    echo '</PRE></SMALL>' ;
+    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; ");
+?>
+
+<b>Earthquake classification (circles in map are sized by these classes)</b>
+<table border="1" cellpadding="2" cellspacing="0">
+<tbody><tr>
+<td align="center"><b>Magnitude</b></td>
+<td align="center"><b>Classification</b></td>
+<td align="center"><b>Class for map</b></td>
+</tr>
+<tr>
+<td align="center">0 - 3</td>
+<td align="center">Micro</td>
+<td align="center">1</td>
+</tr>
+<tr>
+<td align="center">3 - 3.9</td>
+<td align="center">Minor</td>
+<td align="center">2</td>
+</tr>
+<tr>
+<td align="center">4 - 4.9</td>
+<td align="center">Light</td>
+<td align="center">3</td>
+</tr>
+<tr>
+<td align="center">5 - 5.9</td>
+<td align="center">Moderate</td>
+<td align="center">4</td>
+</tr>
+<tr>
+<td align="center">6 - 6.9</td>
+<td align="center">Strong</td>
+<td align="center">5</td>
+</tr>
+<tr>
+<td align="center">7 - 7.9</td>
+<td align="center">Major</td>
+<td align="center">6</td>
+</tr>
+<tr>
+<td align="center">8 and higher</td>
+<td align="center">Great</td>
+<td align="center">7</td>
+</tr>
+</tbody></table>
+<p>
+Here a map should appear:<p>
+
+Oldest event from: 
+<?php
+ system("head -2 bulletin.asc  | tail -1 | cut -d',' -f1-2 | tr ',' ' '");
+?>
+UTC ; Latest event from: 
+<?php
+ system("tail -1 bulletin.asc | cut -d',' -f1-2 | tr ',' ' '");
+?>
+ UTC <br>
+<?php
+ system("echo \"`cat bulletin.asc  | grep -vi Date | wc -l | awk '{print $1}'` earthquakes on this map\"");
+?>
+<br>
+Latest events drawn last.
+<p>
+<a href="earthquakes.png" border="0"><img src="earthquakes_small.jpg" alt="Auto-generated earthquake map (GRASS GIS/PHP based)"></a><br>
+<i>Click for high-res map</i>
+
+<p>
+For earthquake details, visit <a href="http://earthquake.usgs.gov/eqcenter/recenteqsww/">Latest Earthquakes in the World - Last 7 days</a> from USGS.
+<hr>
+2006 Markus Neteler (based on comments from Sharyn Namnath and Glynn Clements)
+<br>
+<a href=php_grass_earthquakes.txt>Download page source code</a>
+</body>
+</html>


Property changes on: grass-promo/tutorials/batch_processing/earthquakes/php_demo/php_grass_earthquakes_PHP4.txt
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native



More information about the grass-commit mailing list