cvs: pear /Services_Weather buildMetarDB.php

From: Date: Mon, 06 Oct 2003 10:53:03 +0000
Subject: cvs: pear /Services_Weather buildMetarDB.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-13415@lists.php.net to get a copy of this message
eru Mon Oct 6 06:53:03 2003 EDT Modified files: /pear/Services_Weather buildMetarDB.php Log: *Improved searchtime in searchAirport(), cartesian coordinates are now calculated at DB-build-time Index: pear/Services_Weather/buildMetarDB.php diff -u pear/Services_Weather/buildMetarDB.php:1.4 pear/Services_Weather/buildMetarDB.php:1.5 --- pear/Services_Weather/buildMetarDB.php:1.4 Fri Oct 3 05:50:56 2003 +++ pear/Services_Weather/buildMetarDB.php Mon Oct 6 06:53:03 2003 @@ -17,11 +17,17 @@ // | Authors: Alexander Wirtz <alex@pc4p.net> | // +----------------------------------------------------------------------+ // -// $Id: buildMetarDB.php,v 1.4 2003/10/03 09:50:56 eru Exp $ +// $Id: buildMetarDB.php,v 1.5 2003/10/06 10:53:03 eru Exp $ require_once "PEAR.php"; require_once "DB.php"; +// {{{ constants +// {{{ natural constants and measures +define("SERVICES_WEATHER_RADIUS_EARTH", 6378.15); +// }}} +// }}} + /** * This script downloads, saves and processes the textfiles needed for * the building the databases to enable searching for METAR stations. @@ -310,7 +316,7 @@ if (DB::isError($result)) { // Create new table - $create = "CREATE TABLE ".$tableName."(id int(5),block int(2),station int(3),icao varchar(4),name varchar(50),state varchar(2),country varchar(50),wmo int(1),latitude float,longitude float)"; + $create = "CREATE TABLE ".$tableName."(id int(5),block int(2),station int(3),icao varchar(4),name varchar(50),state varchar(2),country varchar(50),wmo int(1),latitude float,longitude float,x float,y float,z float)"; if ($verbose > 0) { echo "Services_Weather: Creating table '".$tableName."'.\n"; } @@ -356,6 +362,13 @@ } } } + // Calculate the cartesian coordinates for latitude and longitude + $theta = deg2rad($latitude); + $phi = deg2rad($longitude); + + $x = SERVICES_WEATHER_RADIUS_EARTH * cos($phi) * cos($theta); + $y = SERVICES_WEATHER_RADIUS_EARTH * sin($phi) * cos($theta); + $z = SERVICES_WEATHER_RADIUS_EARTH * sin($theta); // escape data strings for ( $i = 0; $i <= 6; $i++ ) { $data[$i] = $db->quote($data[$i]); @@ -365,8 +378,9 @@ $insert = "INSERT INTO ".$tableName." VALUES(".($line - $error).","; $insert .= $data[$dataOrder["b"]].",".$data[$dataOrder["s"]].","; $insert .= $data[$dataOrder["i"]].",".$data[3].",".$data[4].","; - $insert .= $data[5].",".$data[6].",".round( $latitude, 4 ).","; - $insert .= round( $longitude, 4 ).")"; + $insert .= $data[5].",".$data[6].",".round($latitude, 4).","; + $insert .= round($longitude, 4).",".round($x, 4).",".round($y, 4).","; + $insert .= round($z, 4).")"; $result = $db->query($insert); if (DB::isError($result)) { @@ -381,7 +395,7 @@ } // commit and close $db->disconnect(); - if ($verbose > 0 || $errors > 0) { + if ($verbose > 0 || $error > 0) { echo "Services_Weather: ".($line - $error)." ".$tableName." added "; echo "to database '".$dbName."' (".$error." error(s)).\n"; }

« previous php.pear.cvs (#13415) next »