cvs: pear /Image_GIS GIS.php package.xml /Image_GIS/GIS LineSet.php Parser.php Renderer.php /Image_GIS/GIS/Parser E00.php
| From: | Sebastian Bergmann | Date: | Sun, 19 Jan 2003 11:24:18 +0000 |
| Subject: | cvs: pear /Image_GIS GIS.php package.xml /Image_GIS/GIS LineSet.php Parser.php Renderer.php /Image_GIS/GIS/Parser E00.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8408@lists.php.net to get a copy of this message | ||
sebastian Sun Jan 19 06:24:18 2003 EDT
Added files:
/pear/Image_GIS/GIS LineSet.php
Modified files:
/pear/Image_GIS GIS.php package.xml
/pear/Image_GIS/GIS Parser.php Renderer.php
/pear/Image_GIS/GIS/Parser E00.php
Log:
Cache parsed data files using Cache_Lite. Factor the handling of Line Sets out into a separate
class.
Index: pear/Image_GIS/GIS.php diff -u pear/Image_GIS/GIS.php:1.8 pear/Image_GIS/GIS.php:1.9 --- pear/Image_GIS/GIS.php:1.8 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS.php Sun Jan 19 06:24:18 2003 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GIS.php,v 1.8 2003/01/18 18:01:30 sebastian Exp $ +// $Id: GIS.php,v 1.9 2003/01/19 11:24:18 sebastian Exp $ // require_once 'Image/Color.php'; @@ -50,7 +50,7 @@ * $map->saveImage('kiel.png'); * ?> * -* @version $Revision: 1.8 $ +* @version $Revision: 1.9 $ * @since Image_GIS 1.0.0 */ class Image_GIS { @@ -121,15 +121,7 @@ * @access public */ function render() { - list($lines, $min, $max) = $this->parser->parse(); - - if ($this->renderer->min == false || - $this->renderer->max == false) { - $this->renderer->min = $min; - $this->renderer->max = $max; - } - - $this->renderer->render($lines); + $this->renderer->render($this->parser->parse()); } /** Index: pear/Image_GIS/package.xml diff -u pear/Image_GIS/package.xml:1.6 pear/Image_GIS/package.xml:1.7 --- pear/Image_GIS/package.xml:1.6 Sat Jan 18 05:17:12 2003 +++ pear/Image_GIS/package.xml Sun Jan 19 06:24:18 2003 @@ -33,9 +33,13 @@ <date>YYYY-MM-DD</date> <notes> <![CDATA[ -* Added getRange() method to the Image_GIS and Image_GIS_Renderer ++ Added caching of parsed data files. + ++ Added getRange() method to the Image_GIS and Image_GIS_Renderer classes. +* Factored the handling of Line Sets out into a separate class. + * Fixed a bug that kept a debugging message from beeing printed. ]]> </notes> @@ -51,6 +55,7 @@ <file role="php" name="SVG.php"/> </dir> + <file role="php" name="LineSet.php"/> <file role="php" name="Parser.php"/> <file role="php" name="Renderer.php"/> </dir> Index: pear/Image_GIS/GIS/Parser.php diff -u pear/Image_GIS/GIS/Parser.php:1.4 pear/Image_GIS/GIS/Parser.php:1.5 --- pear/Image_GIS/GIS/Parser.php:1.4 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS/Parser.php Sun Jan 19 06:24:18 2003 @@ -13,17 +13,27 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.4 2003/01/18 18:01:30 sebastian Exp $ +// $Id: Parser.php,v 1.5 2003/01/19 11:24:18 sebastian Exp $ // +require_once 'Cache/Lite.php'; +require_once 'Image/GIS/LineSet.php'; + /** * Parser Base Class. * -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser { /** + * Cache. + * + * @var Cache_Lite $cache + */ + var $cache; + + /** * Data Files. * * @var array $dataFiles @@ -38,27 +48,11 @@ var $debug; /** - * Lines. + * Line Set. * - * @var array $lines - */ - var $lines = array(); - - /** - * @var array $min - */ - var $min = array( - 'x' => 0, - 'y' => 0 - ); - - /** - * @var array $max + * @var array $lineSets */ - var $max = array( - 'x' => 0, - 'y' => 0 - ); + var $lineSets = array(); /** * Constructor. @@ -67,6 +61,7 @@ * @access public */ function Image_GIS_Parser($debug) { + $this->cache = new Cache_Lite; $this->debug = $debug; } @@ -86,25 +81,6 @@ } /** - * Adds a line to the map. - * - * @param float $x1 - * @param float $y1 - * @param float $x2 - * @param float $y2 - * @param mixed $color - * @access public - */ - function addLine($x1, $y1, $x2, $y2, $color) { - $this->lines[] = array($x1, $y1, $x2, $y2, $color); - - $this->min['x'] = min($this->min['x'], $x1, $x2); - $this->min['y'] = min($this->min['y'], $y1, $y2); - $this->max['x'] = max($this->max['x'], $x1, $x2); - $this->max['y'] = max($this->max['y'], $y1, $y2); - } - - /** * Adds a datafile to the map. * * @param string $dataFile @@ -123,10 +99,20 @@ */ function parse() { foreach ($this->dataFiles as $dataFile => $color) { - $this->parseFile($dataFile, $color); + $cacheID = md5($dataFile . '_' . $color); + + if ($lineSet = $this->cache->get($cacheID, 'Image_GIS')) { + $lineSet = unserialize($lineSet); + } else { + $lineSet = $this->parseFile($dataFile, $color); + + $this->cache->save(serialize($lineSet), $cacheID, 'Image_GIS'); + } + + $this->lineSets[] = $lineSet; } - return array($this->lines, $this->min, $this->max); + return $this->lineSets; } /** @@ -134,6 +120,7 @@ * * @param string $dataFile * @param mixed $color + * @return mixed * @access public * @abstract */ Index: pear/Image_GIS/GIS/Renderer.php diff -u pear/Image_GIS/GIS/Renderer.php:1.6 pear/Image_GIS/GIS/Renderer.php:1.7 --- pear/Image_GIS/GIS/Renderer.php:1.6 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS/Renderer.php Sun Jan 19 06:24:18 2003 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Renderer.php,v 1.6 2003/01/18 18:01:30 sebastian Exp $ +// $Id: Renderer.php,v 1.7 2003/01/19 11:24:18 sebastian Exp $ // require_once 'Image/Color.php'; @@ -21,7 +21,7 @@ /** * Renderer Base Class. * -* @version $Revision: 1.6 $ +* @version $Revision: 1.7 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer { @@ -184,12 +184,33 @@ /** * Renders the image. * - * @param array $lines + * @param array $lineSets * @access public */ - function render($lines) { - foreach ($lines as $line) { - $this->drawClippedLine($line[0], $line[1], $line[2], $line[3], $line[4]); + function render($lineSets) { + if ($this->min == false || $this->max == false) { + $this->min = array( + 'x' => 0, + 'y' => 0 + ); + + $this->max = array( + 'x' => 0, + 'y' => 0 + ); + + foreach ($lineSets as $lineSet) { + $this->min['x'] = min($this->min['x'], $lineSet->min['x']); + $this->min['y'] = min($this->min['y'], $lineSet->min['y']); + $this->max['x'] = max($this->max['x'], $lineSet->max['x']); + $this->max['y'] = max($this->max['y'], $lineSet->max['y']); + } + } + + foreach ($lineSets as $lineSet) { + foreach ($lineSet->lines as $line) { + $this->drawClippedLine($line[0], $line[1], $line[2], $line[3], $lineSet->color); + } } } Index: pear/Image_GIS/GIS/Parser/E00.php diff -u pear/Image_GIS/GIS/Parser/E00.php:1.5 pear/Image_GIS/GIS/Parser/E00.php:1.6 --- pear/Image_GIS/GIS/Parser/E00.php:1.5 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS/Parser/E00.php Sun Jan 19 06:24:18 2003 @@ -13,15 +13,16 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: E00.php,v 1.5 2003/01/18 18:01:30 sebastian Exp $ +// $Id: E00.php,v 1.6 2003/01/19 11:24:18 sebastian Exp $ // +require_once 'Image/GIS/LineSet.php'; require_once 'Image/GIS/Parser.php'; /** * E00 Parser. * -* @version $Revision: 1.5 $ +* @version $Revision: 1.6 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser_E00 extends Image_GIS_Parser { @@ -40,10 +41,12 @@ * * @param string $dataFile * @param mixed $color - * @return boolean + * @return mixed * @access public */ function parseFile($dataFile, $color) { + $lineSet = new Image_GIS_LineSet($color); + if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $ln = 0; @@ -67,12 +70,12 @@ if ($pl['x'] != -1 && $pl['y'] != -1) { - $this->addLine($pl['x'], $pl['y'], $a[1], $a[2], $color); + $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); } $numRecords--; - $this->addLine($a[1], $a[2], $a[3], $a[4], $color); + $lineSet->addLine($a[1], $a[2], $a[3], $a[4]); $pl['x'] = $a[3]; $pl['y'] = $a[4]; @@ -84,7 +87,7 @@ preg_match("#^ ([0-9]\.[0-9]{7}E[-+][0-9]{2}) ([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) { if ($pl['x'] != -1 && $pl['y'] != -1) { - $this->addLine($pl['x'], $pl['y'], $a[1], $a[2], $color); + $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); $pl['x'] = $a[1]; $pl['y'] = $a[2]; @@ -109,7 +112,7 @@ @fclose($fp); - return true; + return $lineSet; } return false; Index: pear/Image_GIS/GIS/LineSet.php +++ pear/Image_GIS/GIS/LineSet.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Line Set | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: LineSet.php,v 1.1 2003/01/19 11:24:18 sebastian Exp $ // /** * A Set of Lines. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.1 */ class Image_GIS_LineSet { /** * @var array $color */ var $color = 'black'; /** * @var array $lines */ var $lines = array(); /** * @var array $min */ var $min = array( 'x' => 0, 'y' => 0 ); /** * @var array $max */ var $max = array( 'x' => 0, 'y' => 0 ); /** * Constructor. * * @param string $color * @access public */ function Image_GIS_LineSet($color = 'black') { $this->color = $color; } /** * Adds a line to the line set. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @access public */ function addLine($x1, $y1, $x2, $y2) { $this->lines[] = array($x1, $y1, $x2, $y2); $this->min['x'] = min($this->min['x'], $x1, $x2); $this->min['y'] = min($this->min['y'], $y1, $y2); $this->max['x'] = max($this->max['x'], $x1, $x2); $this->max['y'] = max($this->max['y'], $y1, $y2); } } ?>
Index: pear/Image_GIS/GIS.php diff -u pear/Image_GIS/GIS.php:1.8 pear/Image_GIS/GIS.php:1.9 --- pear/Image_GIS/GIS.php:1.8 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS.php Sun Jan 19 06:24:18 2003 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GIS.php,v 1.8 2003/01/18 18:01:30 sebastian Exp $ +// $Id: GIS.php,v 1.9 2003/01/19 11:24:18 sebastian Exp $ // require_once 'Image/Color.php'; @@ -50,7 +50,7 @@ * $map->saveImage('kiel.png'); * ?> * -* @version $Revision: 1.8 $ +* @version $Revision: 1.9 $ * @since Image_GIS 1.0.0 */ class Image_GIS { @@ -121,15 +121,7 @@ * @access public */ function render() { - list($lines, $min, $max) = $this->parser->parse(); - - if ($this->renderer->min == false || - $this->renderer->max == false) { - $this->renderer->min = $min; - $this->renderer->max = $max; - } - - $this->renderer->render($lines); + $this->renderer->render($this->parser->parse()); } /** Index: pear/Image_GIS/package.xml diff -u pear/Image_GIS/package.xml:1.6 pear/Image_GIS/package.xml:1.7 --- pear/Image_GIS/package.xml:1.6 Sat Jan 18 05:17:12 2003 +++ pear/Image_GIS/package.xml Sun Jan 19 06:24:18 2003 @@ -33,9 +33,13 @@ <date>YYYY-MM-DD</date> <notes> <![CDATA[ -* Added getRange() method to the Image_GIS and Image_GIS_Renderer ++ Added caching of parsed data files. + ++ Added getRange() method to the Image_GIS and Image_GIS_Renderer classes. +* Factored the handling of Line Sets out into a separate class. + * Fixed a bug that kept a debugging message from beeing printed. ]]> </notes> @@ -51,6 +55,7 @@ <file role="php" name="SVG.php"/> </dir> + <file role="php" name="LineSet.php"/> <file role="php" name="Parser.php"/> <file role="php" name="Renderer.php"/> </dir> Index: pear/Image_GIS/GIS/Parser.php diff -u pear/Image_GIS/GIS/Parser.php:1.4 pear/Image_GIS/GIS/Parser.php:1.5 --- pear/Image_GIS/GIS/Parser.php:1.4 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS/Parser.php Sun Jan 19 06:24:18 2003 @@ -13,17 +13,27 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.4 2003/01/18 18:01:30 sebastian Exp $ +// $Id: Parser.php,v 1.5 2003/01/19 11:24:18 sebastian Exp $ // +require_once 'Cache/Lite.php'; +require_once 'Image/GIS/LineSet.php'; + /** * Parser Base Class. * -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser { /** + * Cache. + * + * @var Cache_Lite $cache + */ + var $cache; + + /** * Data Files. * * @var array $dataFiles @@ -38,27 +48,11 @@ var $debug; /** - * Lines. + * Line Set. * - * @var array $lines - */ - var $lines = array(); - - /** - * @var array $min - */ - var $min = array( - 'x' => 0, - 'y' => 0 - ); - - /** - * @var array $max + * @var array $lineSets */ - var $max = array( - 'x' => 0, - 'y' => 0 - ); + var $lineSets = array(); /** * Constructor. @@ -67,6 +61,7 @@ * @access public */ function Image_GIS_Parser($debug) { + $this->cache = new Cache_Lite; $this->debug = $debug; } @@ -86,25 +81,6 @@ } /** - * Adds a line to the map. - * - * @param float $x1 - * @param float $y1 - * @param float $x2 - * @param float $y2 - * @param mixed $color - * @access public - */ - function addLine($x1, $y1, $x2, $y2, $color) { - $this->lines[] = array($x1, $y1, $x2, $y2, $color); - - $this->min['x'] = min($this->min['x'], $x1, $x2); - $this->min['y'] = min($this->min['y'], $y1, $y2); - $this->max['x'] = max($this->max['x'], $x1, $x2); - $this->max['y'] = max($this->max['y'], $y1, $y2); - } - - /** * Adds a datafile to the map. * * @param string $dataFile @@ -123,10 +99,20 @@ */ function parse() { foreach ($this->dataFiles as $dataFile => $color) { - $this->parseFile($dataFile, $color); + $cacheID = md5($dataFile . '_' . $color); + + if ($lineSet = $this->cache->get($cacheID, 'Image_GIS')) { + $lineSet = unserialize($lineSet); + } else { + $lineSet = $this->parseFile($dataFile, $color); + + $this->cache->save(serialize($lineSet), $cacheID, 'Image_GIS'); + } + + $this->lineSets[] = $lineSet; } - return array($this->lines, $this->min, $this->max); + return $this->lineSets; } /** @@ -134,6 +120,7 @@ * * @param string $dataFile * @param mixed $color + * @return mixed * @access public * @abstract */ Index: pear/Image_GIS/GIS/Renderer.php diff -u pear/Image_GIS/GIS/Renderer.php:1.6 pear/Image_GIS/GIS/Renderer.php:1.7 --- pear/Image_GIS/GIS/Renderer.php:1.6 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS/Renderer.php Sun Jan 19 06:24:18 2003 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Renderer.php,v 1.6 2003/01/18 18:01:30 sebastian Exp $ +// $Id: Renderer.php,v 1.7 2003/01/19 11:24:18 sebastian Exp $ // require_once 'Image/Color.php'; @@ -21,7 +21,7 @@ /** * Renderer Base Class. * -* @version $Revision: 1.6 $ +* @version $Revision: 1.7 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer { @@ -184,12 +184,33 @@ /** * Renders the image. * - * @param array $lines + * @param array $lineSets * @access public */ - function render($lines) { - foreach ($lines as $line) { - $this->drawClippedLine($line[0], $line[1], $line[2], $line[3], $line[4]); + function render($lineSets) { + if ($this->min == false || $this->max == false) { + $this->min = array( + 'x' => 0, + 'y' => 0 + ); + + $this->max = array( + 'x' => 0, + 'y' => 0 + ); + + foreach ($lineSets as $lineSet) { + $this->min['x'] = min($this->min['x'], $lineSet->min['x']); + $this->min['y'] = min($this->min['y'], $lineSet->min['y']); + $this->max['x'] = max($this->max['x'], $lineSet->max['x']); + $this->max['y'] = max($this->max['y'], $lineSet->max['y']); + } + } + + foreach ($lineSets as $lineSet) { + foreach ($lineSet->lines as $line) { + $this->drawClippedLine($line[0], $line[1], $line[2], $line[3], $lineSet->color); + } } } Index: pear/Image_GIS/GIS/Parser/E00.php diff -u pear/Image_GIS/GIS/Parser/E00.php:1.5 pear/Image_GIS/GIS/Parser/E00.php:1.6 --- pear/Image_GIS/GIS/Parser/E00.php:1.5 Sat Jan 18 13:01:30 2003 +++ pear/Image_GIS/GIS/Parser/E00.php Sun Jan 19 06:24:18 2003 @@ -13,15 +13,16 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: E00.php,v 1.5 2003/01/18 18:01:30 sebastian Exp $ +// $Id: E00.php,v 1.6 2003/01/19 11:24:18 sebastian Exp $ // +require_once 'Image/GIS/LineSet.php'; require_once 'Image/GIS/Parser.php'; /** * E00 Parser. * -* @version $Revision: 1.5 $ +* @version $Revision: 1.6 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser_E00 extends Image_GIS_Parser { @@ -40,10 +41,12 @@ * * @param string $dataFile * @param mixed $color - * @return boolean + * @return mixed * @access public */ function parseFile($dataFile, $color) { + $lineSet = new Image_GIS_LineSet($color); + if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $ln = 0; @@ -67,12 +70,12 @@ if ($pl['x'] != -1 && $pl['y'] != -1) { - $this->addLine($pl['x'], $pl['y'], $a[1], $a[2], $color); + $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); } $numRecords--; - $this->addLine($a[1], $a[2], $a[3], $a[4], $color); + $lineSet->addLine($a[1], $a[2], $a[3], $a[4]); $pl['x'] = $a[3]; $pl['y'] = $a[4]; @@ -84,7 +87,7 @@ preg_match("#^ ([0-9]\.[0-9]{7}E[-+][0-9]{2}) ([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) { if ($pl['x'] != -1 && $pl['y'] != -1) { - $this->addLine($pl['x'], $pl['y'], $a[1], $a[2], $color); + $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); $pl['x'] = $a[1]; $pl['y'] = $a[2]; @@ -109,7 +112,7 @@ @fclose($fp); - return true; + return $lineSet; } return false; Index: pear/Image_GIS/GIS/LineSet.php +++ pear/Image_GIS/GIS/LineSet.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Line Set | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: LineSet.php,v 1.1 2003/01/19 11:24:18 sebastian Exp $ // /** * A Set of Lines. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.1 */ class Image_GIS_LineSet { /** * @var array $color */ var $color = 'black'; /** * @var array $lines */ var $lines = array(); /** * @var array $min */ var $min = array( 'x' => 0, 'y' => 0 ); /** * @var array $max */ var $max = array( 'x' => 0, 'y' => 0 ); /** * Constructor. * * @param string $color * @access public */ function Image_GIS_LineSet($color = 'black') { $this->color = $color; } /** * Adds a line to the line set. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @access public */ function addLine($x1, $y1, $x2, $y2) { $this->lines[] = array($x1, $y1, $x2, $y2); $this->min['x'] = min($this->min['x'], $x1, $x2); $this->min['y'] = min($this->min['y'], $y1, $y2); $this->max['x'] = max($this->max['x'], $x1, $x2); $this->max['y'] = max($this->max['y'], $y1, $y2); } } ?>