cvs: pear /Image_GIS GIS.php package.xml /Image_GIS/GIS LineSet.php Parser.php Renderer.php /Image_GIS/GIS/Parser E00.php /Image_GIS/GIS/Renderer
GD.php SVG.php /Image_GIS2 GIS.php package.xml /Image_GIS2/GIS LineSet.php Parser.php Renderer.php /Image_GIS2/GIS/Parser E00.php
/Image_GIS2/GIS/Renderer GD.php SVG.php
| From: | Sebastian Bergmann | Date: | Sat, 17 Apr 2004 10:21:29 +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 /Image_GIS/GIS/Renderer GD.php SVG.php /Image_GIS2 GIS.php package.xml /Image_GIS2/GIS LineSet.php Parser.php Renderer.php /Image_GIS2/GIS/Parser E00.php /Image_GIS2/GIS/Renderer GD.php SVG.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-18341@lists.php.net to get a copy of this message | ||
sebastian Sat Apr 17 06:21:29 2004 EDT
Added files:
/pear/Image_GIS2 GIS.php package.xml
/pear/Image_GIS2/GIS LineSet.php Parser.php Renderer.php
/pear/Image_GIS2/GIS/Parser E00.php
/pear/Image_GIS2/GIS/Renderer GD.php SVG.php
Modified files:
/pear/Image_GIS GIS.php package.xml
/pear/Image_GIS/GIS LineSet.php Parser.php Renderer.php
/pear/Image_GIS/GIS/Parser E00.php
/pear/Image_GIS/GIS/Renderer GD.php SVG.php
Log:
Move Image_GIS/HEAD to Image_GIS2/HEAD. Move Image_GIS/ZEND_ENGINE_1 to Image_GIS/HEAD.
http://cvs.php.net/diff.php/pear/Image_GIS/GIS.php?r1=1.17&r2=1.18&ty=u Index: pear/Image_GIS/GIS.php diff -u pear/Image_GIS/GIS.php:1.17 pear/Image_GIS/GIS.php:1.18 --- pear/Image_GIS/GIS.php:1.17 Sat Apr 17 06:13:15 2004 +++ pear/Image_GIS/GIS.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GIS.php,v 1.17 2004/04/17 10:13:15 sebastian Exp $ +// $Id: GIS.php,v 1.18 2004/04/17 10:21:24 sebastian Exp $ // require_once 'Image/Color.php'; @@ -70,21 +70,21 @@ * * @var boolean $debug */ - private $debug; + var $debug; /** * Image_GIS_Parser sub-class object. * * @var Image_GIS_Parser $parser */ - private $parser; + var $parser; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ - private $renderer; + var $renderer; /** * Constructor. @@ -92,7 +92,7 @@ * @param array $parameters * @access public */ - public function Image_GIS($parameters = array()) { + function Image_GIS($parameters = array()) { $this->debug = isset($parameters['debug']) ? $parameters['debug'] : false; $this->setParser( @@ -128,7 +128,7 @@ * @return boolean * @access public */ - public function addDataFile($dataFile, $color) { + function addDataFile($dataFile, $color) { return $this->parser->addDataFile($dataFile, $color); } @@ -139,7 +139,7 @@ * @access public * @since Image_GIS 1.0.1 */ - public function getRange() { + function getRange() { return $this->renderer->getRange(); } @@ -148,7 +148,7 @@ * * @access public */ - public function render() { + function render() { $this->renderer->render($this->parser->parse()); } @@ -159,7 +159,7 @@ * @return boolean * @access public */ - public function saveImage($filename) { + function saveImage($filename) { $this->render(); return $this->renderer->saveImage($filename); @@ -173,8 +173,8 @@ * @param boolean $cache * @access public */ - public function setParser($parser, $cache) { - $this->parser = Image_GIS_Parser::factory($parser, $cache, $this->debug); + function setParser($parser, $cache) { + $this->parser = &Image_GIS_Parser::factory($parser, $cache, $this->debug); } /** @@ -186,7 +186,7 @@ * @param float $y2 * @access public */ - public function setRange($x1, $x2, $y1, $y2) { + function setRange($x1, $x2, $y1, $y2) { $this->renderer->setRange($x1, $x2, $y1, $y2); } @@ -197,8 +197,8 @@ * @param string $renderer * @access public */ - public function setRenderer($renderer, $width, $height) { - $this->renderer = Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); + function setRenderer($renderer, $width, $height) { + $this->renderer = &Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); } /** @@ -206,8 +206,9 @@ * * @access public */ - public function showImage() { + function showImage() { $this->render(); + $this->renderer->showImage(); } } http://cvs.php.net/diff.php/pear/Image_GIS/package.xml?r1=1.14&r2=1.15&ty=u Index: pear/Image_GIS/package.xml diff -u pear/Image_GIS/package.xml:1.14 pear/Image_GIS/package.xml:1.15 --- pear/Image_GIS/package.xml:1.14 Tue Mar 16 03:05:53 2004 +++ pear/Image_GIS/package.xml Sat Apr 17 06:21:24 2004 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> - <name>Image_GIS2</name> + <name>Image_GIS</name> <summary>Visualization of GIS data.</summary> <description> Generating maps on demand can be a hard job as most often you don't @@ -28,14 +28,31 @@ </maintainers> <license>PHP License</license> <release> - <version>2.0.0</version> + <version>1.1.0</version> <state>stable</state> - <date>2004-MM-DD</date> + <date>2004-01-06</date> <notes> <![CDATA[ -* Refactored using PHP 5 syntax. ++ Added caching of parsed data files. + ++ Added getRange() method to the Image_GIS and Image_GIS_Renderer + classes. + +* Changed the Image_GIS constructor to accept an associative + parameter array as its only argument. + + Note: This breaks backwards compatibility. + +* The SVG renderer now uses the XML_SVG package instead of the + XML_Tree package. -! PHP 5.0.0 (or higher) is now required. +* Factored the handling of Line Sets out into a separate class. + +* Fixed handling of negative coordinates. + +* Fixed a bug that kept a debugging message from beeing printed. + +* Fixed incompatibilities with PHP 5. ]]> </notes> <filelist> @@ -67,35 +84,6 @@ </release> <changelog> <release> - <version>1.1.0</version> - <state>stable</state> - <date>2004-01-06</date> - <notes> -<![CDATA[ -+ Added caching of parsed data files. - -+ Added getRange() method to the Image_GIS and Image_GIS_Renderer - classes. - -* Changed the Image_GIS constructor to accept an associative - parameter array as its only argument. - - Note: This breaks backwards compatibility. - -* The SVG renderer now uses the XML_SVG package instead of the - XML_Tree package. - -* Factored the handling of Line Sets out into a separate class. - -* Fixed handling of negative coordinates. - -* Fixed a bug that kept a debugging message from beeing printed. - -* Fixed incompatibilities with PHP 5. -]]> - </notes> - </release> - <release> <version>1.0.0</version> <state>stable</state> <date>2002-12-30</date> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/LineSet.php?r1=1.4&r2=1.5&ty=u Index: pear/Image_GIS/GIS/LineSet.php diff -u pear/Image_GIS/GIS/LineSet.php:1.4 pear/Image_GIS/GIS/LineSet.php:1.5 --- pear/Image_GIS/GIS/LineSet.php:1.4 Sat Apr 17 06:13:16 2004 +++ pear/Image_GIS/GIS/LineSet.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: LineSet.php,v 1.4 2004/04/17 10:13:16 sebastian Exp $ +// $Id: LineSet.php,v 1.5 2004/04/17 10:21:24 sebastian Exp $ // /** @@ -29,17 +29,17 @@ /** * @var array $color */ - public $color = 'black'; + var $color = 'black'; /** * @var array $lines */ - public $lines = array(); + var $lines = array(); /** * @var array $min */ - public $min = array( + var $min = array( 'x' => 0, 'y' => 0 ); @@ -47,7 +47,7 @@ /** * @var array $max */ - public $max = array( + var $max = array( 'x' => 0, 'y' => 0 ); @@ -58,7 +58,7 @@ * @param string $color * @access public */ - public function Image_GIS_LineSet($color = 'black') { + function Image_GIS_LineSet($color = 'black') { $this->color = $color; } @@ -71,7 +71,7 @@ * @param float $y2 * @access public */ - public function addLine($x1, $y1, $x2, $y2) { + function addLine($x1, $y1, $x2, $y2) { $this->lines[] = array($x1, $y1, $x2, $y2); $this->min['x'] = min($this->min['x'], $x1, $x2); http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Parser.php?r1=1.12&r2=1.13&ty=u Index: pear/Image_GIS/GIS/Parser.php diff -u pear/Image_GIS/GIS/Parser.php:1.12 pear/Image_GIS/GIS/Parser.php:1.13 --- pear/Image_GIS/GIS/Parser.php:1.12 Sat Apr 17 06:13:17 2004 +++ pear/Image_GIS/GIS/Parser.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.12 2004/04/17 10:13:17 sebastian Exp $ +// $Id: Parser.php,v 1.13 2004/04/17 10:21:24 sebastian Exp $ // require_once 'Cache/Lite.php'; @@ -28,34 +28,34 @@ * @category Image * @package Image_GIS */ -abstract class Image_GIS_Parser { +class Image_GIS_Parser { /** * Cache. * * @var Cache_Lite $cache */ - protected $cache = NULL; + var $cache = NULL; /** * Data Files. * * @var array $dataFiles */ - protected $dataFiles = array(); + var $dataFiles = array(); /** * Set to TRUE to enable debugging. * * @var boolean $debug */ - protected $debug; + var $debug; /** * Line Set. * * @var array $lineSets */ - protected $lineSets = array(); + var $lineSets = array(); /** * Constructor. @@ -64,7 +64,7 @@ * @param boolean $debug * @access public */ - public function Image_GIS_Parser($cache, $debug) { + function Image_GIS_Parser($cache, $debug) { if ($cache) { $this->cache = new Cache_Lite; } @@ -81,7 +81,7 @@ * @return object * @access public */ - public static function factory($parser, $cache, $debug) { + function &factory($parser, $cache, $debug) { include_once 'Image/GIS/Parser/' . $parser . '.php'; $class = 'Image_GIS_Parser_' . $parser; @@ -97,7 +97,7 @@ * @param mixed $color * @access public */ - public function addDataFile($dataFile, $color) { + function addDataFile($dataFile, $color) { $this->dataFiles[$dataFile] = $color; } @@ -107,7 +107,7 @@ * @access public * @return array */ - public function parse() { + function parse() { foreach ($this->dataFiles as $dataFile => $color) { $cacheID = md5($dataFile . '_' . $color); $lineSet = false; @@ -140,6 +140,6 @@ * @access public * @abstract */ - public abstract function parseFile($dataFile, $color); + function parseFile($dataFile, $color) { /* abstract */ } } ?> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Renderer.php?r1=1.11&r2=1.12&ty=u Index: pear/Image_GIS/GIS/Renderer.php diff -u pear/Image_GIS/GIS/Renderer.php:1.11 pear/Image_GIS/GIS/Renderer.php:1.12 --- pear/Image_GIS/GIS/Renderer.php:1.11 Sat Apr 17 06:13:17 2004 +++ pear/Image_GIS/GIS/Renderer.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Renderer.php,v 1.11 2004/04/17 10:13:17 sebastian Exp $ +// $Id: Renderer.php,v 1.12 2004/04/17 10:21:24 sebastian Exp $ // require_once 'Image/Color.php'; @@ -29,37 +29,37 @@ * @package Image_GIS * @abstract */ -abstract class Image_GIS_Renderer { +class Image_GIS_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ - protected $debug; + var $debug; /** * @var array $min */ - protected $min = false; + var $min = false; /** * @var array $max */ - protected $max = false; + var $max = false; /** * Width of the image. * * @var integer $width */ - protected $width; + var $width; /** * Height of the image. * * @var integer $height */ - protected $height; + var $height; /** * Constructor. @@ -69,7 +69,7 @@ * @param boolean $debug * @access public */ - public function Image_GIS_Renderer($width, $height, $debug) { + function Image_GIS_Renderer($width, $height, $debug) { $this->debug = $debug; if ($width < 0 || @@ -96,7 +96,7 @@ * @return object * @access public */ - public static function factory($renderer, $width, $height, $debug) { + function &factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS_Renderer_' . $renderer; $object = new $class($width, $height, $debug); @@ -116,7 +116,7 @@ * @param mixed $color * @access public */ - public function drawClippedLine($x1, $y1, $x2, $y2, $color) { + function drawClippedLine($x1, $y1, $x2, $y2, $color) { if (($x1 > $this->max['x'] || $x1 < $this->min['x'] || $y1 > $this->max['y'] || @@ -156,7 +156,7 @@ * @access public * @since Image_GIS 1.0.1 */ - public function getRange() { + function getRange() { return array( $this->min['x'], $this->max['x'], @@ -172,7 +172,7 @@ * @param string $direction * @access public */ - public function polar2image($polarCoordinate, $direction) { + function polar2image($polarCoordinate, $direction) { switch ($direction) { case 'x': { return ($polarCoordinate - $this->min[$direction]) * @@ -194,7 +194,7 @@ * @param array $lineSets * @access public */ - public function render($lineSets) { + function render($lineSets) { if ($this->min == false || $this->max == false) { $this->min = array( 'x' => 0, @@ -230,7 +230,7 @@ * @param float $y2 * @access public */ - public function setRange($x1, $x2, $y1, $y2) { + function setRange($x1, $x2, $y1, $y2) { $this->min = array('x' => $x1, 'y' => $y1); $this->max = array('x' => $x2, 'y' => $y2); } @@ -249,7 +249,7 @@ * @access public * @abstract */ - public abstract function drawLine($x1, $y1, $x2, $y2, $r, $g, $b); + function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { /* abstract */ } /** * Saves the rendered image to a given file. @@ -259,7 +259,7 @@ * @access public * @abstract */ - public abstract function saveImage($filename); + function saveImage($filename) { /* abstract */ } /** * Shows the rendered image. @@ -267,6 +267,6 @@ * @access public * @abstract */ - public abstract function showImage(); + function showImage() { /* abstract */ } } ?> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Parser/E00.php?r1=1.11&r2=1.12&ty=u Index: pear/Image_GIS/GIS/Parser/E00.php diff -u pear/Image_GIS/GIS/Parser/E00.php:1.11 pear/Image_GIS/GIS/Parser/E00.php:1.12 --- pear/Image_GIS/GIS/Parser/E00.php:1.11 Sat Apr 17 06:13:17 2004 +++ pear/Image_GIS/GIS/Parser/E00.php Sat Apr 17 06:21:25 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: E00.php,v 1.11 2004/04/17 10:13:17 sebastian Exp $ +// $Id: E00.php,v 1.12 2004/04/17 10:21:25 sebastian Exp $ // require_once 'Image/GIS/LineSet.php'; @@ -37,7 +37,7 @@ * @param boolean $debug * @access public */ - public function Image_GIS_Parser_E00($cache, $debug) { + function Image_GIS_Parser_E00($cache, $debug) { $this->Image_GIS_Parser($cache, $debug); } @@ -49,15 +49,15 @@ * @return mixed * @access public */ - public function parseFile($dataFile, $color) { + function parseFile($dataFile, $color) { $lineSet = new Image_GIS_LineSet($color); if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; - $lineNum = 0; + $ln = 0; while(0 || $line = fgets($fp, 1024)) { - $lineNum++; + $ln ++; if ($numRecords == 0 && preg_match("#^\s+([0-9]+)\s+([-0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)#", $line, $a)) { @@ -101,13 +101,13 @@ $numRecords--; } - else if ($lineNum > 2) { - if ($this->debug) { - printf( - 'Died at: %s<br />', - $lineNum - ); - } + else if ($ln > 2) { + if ($this->debug) { + printf( + 'Died at: %s<br />', + $ln + ); + } break; } http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Renderer/GD.php?r1=1.6&r2=1.7&ty=u Index: pear/Image_GIS/GIS/Renderer/GD.php diff -u pear/Image_GIS/GIS/Renderer/GD.php:1.6 pear/Image_GIS/GIS/Renderer/GD.php:1.7 --- pear/Image_GIS/GIS/Renderer/GD.php:1.6 Sat Apr 17 06:13:18 2004 +++ pear/Image_GIS/GIS/Renderer/GD.php Sat Apr 17 06:21:26 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GD.php,v 1.6 2004/04/17 10:13:18 sebastian Exp $ +// $Id: GD.php,v 1.7 2004/04/17 10:21:26 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; @@ -30,18 +30,18 @@ */ class Image_GIS_Renderer_GD extends Image_GIS_Renderer { /** - * GD Image Ressource. + * GD Image Palette. * - * @var ressource $image + * @var array $palette */ - private $image; + var $palette = array(); /** - * GD Image Palette. + * GD Image Ressource. * - * @var array $palette + * @var ressource $img */ - private $palette = array(); + var $img; /** * Constructor. @@ -51,19 +51,19 @@ * @param boolean $debug * @access public */ - public function __construct($width, $height, $debug) { + function Image_GIS_Renderer_GD($width, $height, $debug) { if (is_file($width)) { - $this->image = imagecreatefrompng($width); + $this->img = imagecreatefrompng($width); + $width = imagesx($this->img); + $height = imagesy($this->img); - $width = imagesx($this->image); - $height = imagesy($this->image); + $this->Image_GIS_Renderer($width, $height, $debug); } else { - $this->image = imagecreate($this->width, $this->height); + $this->Image_GIS_Renderer($width, $height, $debug); - imagecolorallocate($this->image, 255, 255, 255); + $this->img = imagecreate($this->width, $this->height); + imagecolorallocate($this->img, 255, 255, 255); } - - $this->Image_GIS_Renderer($width, $height, $debug); } /** @@ -79,13 +79,13 @@ * @param float $b * @access public */ - public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { + function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { - $this->palette[$r][$g][$b] = imagecolorallocate($this->image, $r, $g, $b); + $this->palette[$r][$g][$b] = imagecolorallocate($this->img, $r, $g, $b); } imageline( - $this->image, + $this->img, $x1, $y1, $x2, @@ -101,8 +101,8 @@ * @return boolean * @access public */ - public function saveImage($filename) { - return imagepng($this->image, $filename); + function saveImage($filename) { + return imagepng($this->img, $filename); } /** @@ -110,9 +110,9 @@ * * @access public */ - public function showImage() { + function showImage() { header('Content-Type: image/png'); - imagepng($this->image); + imagepng($this->img); } } ?> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Renderer/SVG.php?r1=1.7&r2=1.8&ty=u Index: pear/Image_GIS/GIS/Renderer/SVG.php diff -u pear/Image_GIS/GIS/Renderer/SVG.php:1.7 pear/Image_GIS/GIS/Renderer/SVG.php:1.8 --- pear/Image_GIS/GIS/Renderer/SVG.php:1.7 Sat Apr 17 06:13:18 2004 +++ pear/Image_GIS/GIS/Renderer/SVG.php Sat Apr 17 06:21:26 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: SVG.php,v 1.7 2004/04/17 10:13:18 sebastian Exp $ +// $Id: SVG.php,v 1.8 2004/04/17 10:21:26 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; @@ -34,14 +34,14 @@ * * @var XML_SVG $svg */ - private $svg; + var $svg; /** * SVG Groups. * * @var XML_SVG_Group[] */ - private $svgGroups = array(); + var $svgGroups = array(); /** * Constructor. @@ -51,7 +51,7 @@ * @param boolean $debug * @access public */ - public function __construct($width, $height, $debug) { + function Image_GIS_Renderer_SVG($width, $height, $debug) { $this->Image_GIS_Renderer($width, $height, $debug); $this->svg = new XML_SVG_Document( @@ -75,7 +75,7 @@ * @param float $b * @access public */ - public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { + function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $group = md5($r . $g . $b); if (!isset($this->svgGroups[$group])) { @@ -113,7 +113,7 @@ * @return boolean * @access public */ - public function saveImage($filename) { + function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->svg->bufferObject()); @fclose($fp); @@ -129,7 +129,7 @@ * * @access public */ - public function showImage() { + function showImage() { $this->svg->printElement(); } } http://cvs.php.net/co.php/pear/Image_GIS2/GIS.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS.php +++ pear/Image_GIS2/GIS.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: GIS.php,v 1.1 2004/04/17 10:21:26 sebastian Exp $ // require_once 'Image/Color.php'; require_once 'Image/GIS/Parser.php'; require_once 'Image/GIS/Renderer.php'; /** * The following example draws the region around the * German city of Kiel which is Jan's home town: * * <code> * <?php * require_once 'Image/GIS.php'; * * // Create new map. * $map = new Image_GIS( * array( * 'width' => 960, * 'height' => 1280, * 'range' => array( * 'x1' => 9.7, * 'x2' => 10.5, * 'y1' => 54.2, * 'y2' => 54.7 * ) * ) * ); * * // Political * $map->addDataFile('germany_ponet.e00', 'black'); * * // Roads * $map->addDataFile('germany_rdline.e00', 'gray'); * * // Populated Places * $map->addDataFile('germany_pppoly.e00', 'green'); * * // Drainage * $map->addDataFile('germany_dnnet.e00', 'blue'); * * $map->saveImage('kiel.png'); * ?> * </code> * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ private $debug; /** * Image_GIS_Parser sub-class object. * * @var Image_GIS_Parser $parser */ private $parser; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ private $renderer; /** * Constructor. * * @param array $parameters * @access public */ public function Image_GIS($parameters = array()) { $this->debug = isset($parameters['debug']) ? $parameters['debug'] : false; $this->setParser( isset($parameters['parser']) ? $parameters['parser'] : 'E00', isset($parameters['cache']) ? $parameters['cache'] : false, isset($parameters['cacheDir']) ? $parameters['cacheDir'] : '/tmp' ); $this->setRenderer( isset($parameters['renderer']) ? $parameters['renderer'] : 'GD', isset($parameters['width']) ? $parameters['width'] : 640, isset($parameters['height']) ? $parameters['height'] : 480 ); if (isset($parameters['range']['x1']) && isset($parameters['range']['x2']) && isset($parameters['range']['y1']) && isset($parameters['range']['y2'])) { $this->setRange( $parameters['range']['x1'], $parameters['range']['x2'], $parameters['range']['y1'], $parameters['range']['y2'] ); } } /** * Adds a datafile to the map. * * @param string $dataFile * @param mixed $color * @return boolean * @access public */ public function addDataFile($dataFile, $color) { return $this->parser->addDataFile($dataFile, $color); } /** * Returns the range of the data to be rendered. * * @return array * @access public * @since Image_GIS 1.0.1 */ public function getRange() { return $this->renderer->getRange(); } /** * Renders the image. * * @access public */ public function render() { $this->renderer->render($this->parser->parse()); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { $this->render(); return $this->renderer->saveImage($filename); } /** * Sets the Image_GIS_Parser sub-class to be used * to parse a data file. * * @param string $parser * @param boolean $cache * @access public */ public function setParser($parser, $cache) { $this->parser = Image_GIS_Parser::factory($parser, $cache, $this->debug); } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access public */ public function setRange($x1, $x2, $y1, $y2) { $this->renderer->setRange($x1, $x2, $y1, $y2); } /** * Sets the Image_GIS_Renderer sub-class to be used * to render an image. * * @param string $renderer * @access public */ public function setRenderer($renderer, $width, $height) { $this->renderer = Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); } /** * Shows the rendered image. * * @access public */ public function showImage() { $this->render(); $this->renderer->showImage(); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/package.xml?r=1.1&p=1 Index: pear/Image_GIS2/package.xml +++ pear/Image_GIS2/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>Image_GIS2</name> <summary>Visualization of GIS data.</summary> <description> Generating maps on demand can be a hard job as most often you don't have the maps you need in digital form. But you can generate your own maps based on raw, digital data files which are available for free on the net. This package provides a parser for the most common format for geographical data, the Arcinfo/E00 format as well as renderers to produce images using GD or Scalable Vector Graphics (SVG). </description> <maintainers> <maintainer> <user>sebastian</user> <role>lead</role> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <maintainer> <user>ostborn</user> <role>lead</role> <name>Jan Kneschke</name> <email>jan@kneschke.de</email> </maintainer> </maintainers> <license>PHP License</license> <release> <version>2.0.0</version> <state>stable</state> <date>2004-MM-DD</date> <notes> <![CDATA[ * Refactored using PHP 5 syntax. ! PHP 5.0.0 (or higher) is now required. ]]> </notes> <filelist> <dir name="/" baseinstalldir="Image"> <dir name="GIS"> <dir name="Parser"> <file role="php" name="E00.php"/> </dir> <dir name="Renderer"> <file role="php" name="GD.php"/> <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> <file role="php" name="GIS.php"/> </dir> </filelist> <deps> <dep type="ext" rel="has">gd</dep> <dep type="pkg" rel="has">Cache_Lite</dep> <dep type="pkg" rel="has">Image_Color</dep> <dep type="pkg" rel="has">XML_SVG</dep> </deps> </release> <changelog> <release> <version>1.1.0</version> <state>stable</state> <date>2004-01-06</date> <notes> <![CDATA[ + Added caching of parsed data files. + Added getRange() method to the Image_GIS and Image_GIS_Renderer classes. * Changed the Image_GIS constructor to accept an associative parameter array as its only argument. Note: This breaks backwards compatibility. * The SVG renderer now uses the XML_SVG package instead of the XML_Tree package. * Factored the handling of Line Sets out into a separate class. * Fixed handling of negative coordinates. * Fixed a bug that kept a debugging message from beeing printed. * Fixed incompatibilities with PHP 5. ]]> </notes> </release> <release> <version>1.0.0</version> <state>stable</state> <date>2002-12-30</date> <notes> <![CDATA[ * Initial release. ]]> </notes> </release> </changelog> </package> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/LineSet.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/LineSet.php +++ pear/Image_GIS2/GIS/LineSet.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Line Set | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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 2004/04/17 10:21:27 sebastian Exp $ // /** * A Set of Lines. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_LineSet { /** * @var array $color */ public $color = 'black'; /** * @var array $lines */ public $lines = array(); /** * @var array $min */ public $min = array( 'x' => 0, 'y' => 0 ); /** * @var array $max */ public $max = array( 'x' => 0, 'y' => 0 ); /** * Constructor. * * @param string $color * @access public */ 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 */ 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); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Parser.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Parser.php +++ pear/Image_GIS2/GIS/Parser.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Parser Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: Parser.php,v 1.1 2004/04/17 10:21:27 sebastian Exp $ // require_once 'Cache/Lite.php'; require_once 'Image/GIS/LineSet.php'; /** * Parser Base Class. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ abstract class Image_GIS_Parser { /** * Cache. * * @var Cache_Lite $cache */ protected $cache = NULL; /** * Data Files. * * @var array $dataFiles */ protected $dataFiles = array(); /** * Set to TRUE to enable debugging. * * @var boolean $debug */ protected $debug; /** * Line Set. * * @var array $lineSets */ protected $lineSets = array(); /** * Constructor. * * @param boolean $cache * @param boolean $debug * @access public */ public function Image_GIS_Parser($cache, $debug) { if ($cache) { $this->cache = new Cache_Lite; } $this->debug = $debug; } /** * Factory. * * @param string $parser * @param boolean $cache * @param boolean $debug * @return object * @access public */ public static function factory($parser, $cache, $debug) { include_once 'Image/GIS/Parser/' . $parser . '.php'; $class = 'Image_GIS_Parser_' . $parser; $object = new $class($cache, $debug); return $object; } /** * Adds a datafile to the map. * * @param string $dataFile * @param mixed $color * @access public */ public function addDataFile($dataFile, $color) { $this->dataFiles[$dataFile] = $color; } /** * Parses the data files of the map. * * @access public * @return array */ public function parse() { foreach ($this->dataFiles as $dataFile => $color) { $cacheID = md5($dataFile . '_' . $color); $lineSet = false; if (is_object($this->cache) && $lineSet = $this->cache->get($cacheID, 'Image_GIS')) { $lineSet = unserialize($lineSet); } if ($lineSet === false) { $lineSet = $this->parseFile($dataFile, $color); if (is_object($this->cache)) { $this->cache->save(serialize($lineSet), $cacheID, 'Image_GIS'); } } $this->lineSets[] = $lineSet; } return $this->lineSets; } /** * Parses a data file. * * @param string $dataFile * @param mixed $color * @return mixed * @access public * @abstract */ public abstract function parseFile($dataFile, $color); } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Renderer.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Renderer.php +++ pear/Image_GIS2/GIS/Renderer.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Renderer Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: Renderer.php,v 1.1 2004/04/17 10:21:27 sebastian Exp $ // require_once 'Image/Color.php'; /** * Renderer Base Class. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS * @abstract */ abstract class Image_GIS_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ protected $debug; /** * @var array $min */ protected $min = false; /** * @var array $max */ protected $max = false; /** * Width of the image. * * @var integer $width */ protected $width; /** * Height of the image. * * @var integer $height */ protected $height; /** * Constructor. * * @param mixed $width * @param integer $height * @param boolean $debug * @access public */ public function Image_GIS_Renderer($width, $height, $debug) { $this->debug = $debug; if ($width < 0 || $width > 2048) { $width = 640; } if ($height < 0 || $height > 2048) { $height = 480; } $this->width = $width; $this->height = $height; } /** * Factory. * * @param string $renderer * @param mixed $width * @param integer $height * @param boolean $debug * @return object * @access public */ public static function factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS_Renderer_' . $renderer; $object = new $class($width, $height, $debug); return $object; } } /** * Draws a clipped line from ($x1, $y1) to ($x2, $y2) * using $color. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param mixed $color * @access public */ public function drawClippedLine($x1, $y1, $x2, $y2, $color) { if (($x1 > $this->max['x'] || $x1 < $this->min['x'] || $y1 > $this->max['y'] || $y1 < $this->min['y']) && ($x2 > $this->max['x'] || $x2 < $this->min['x'] || $y2 > $this->max['y'] || $y2 < $this->min['y'])) { if ($this->debug) { printf('clipped x1: %d %d %d<br />', $x1, $this->min['x'], $this->max['x']); printf('clipped y1: %d %d %d<br />', $y1, $this->min['y'], $this->max['y']); printf('clipped x2: %d %d %d<br />', $x2, $this->min['x'], $this->max['x']); printf('clipped y2: %d %d %d<br />', $y2, $this->min['y'], $this->max['y']); } } else { if (!is_array($color)) { $color = Image_Color::namedColor2RGB($color); } $x1 = $this->polar2image($x1, 'x'); $y1 = $this->polar2image($y1, 'y'); $x2 = $this->polar2image($x2, 'x'); $y2 = $this->polar2image($y2, 'y'); if ($this->debug) { printf('Drawing line (%s, %s) -> (%s, %s)<br />', $x1, $y1, $x2, $y2); } $this->drawLine($x1, $y1, $x2, $y2, $color[0], $color[1], $color[2]); } } /** * Returns the range of the data to be rendered. * * @return array * @access public * @since Image_GIS 1.0.1 */ public function getRange() { return array( $this->min['x'], $this->max['x'], $this->min['y'], $this->max['y'] ); } /** * Converts a polar coordinate to an image coordinate. * * @param float $polarCoordinate * @param string $direction * @access public */ public function polar2image($polarCoordinate, $direction) { switch ($direction) { case 'x': { return ($polarCoordinate - $this->min[$direction]) * ($this->width / ($this->max[$direction] - $this->min[$direction])); } break; case 'y': { return ($polarCoordinate - $this->max[$direction]) * ($this->height / ($this->min[$direction] - $this->max[$direction])); } break; } } /** * Renders the image. * * @param array $lineSets * @access public */ public 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); } } } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access public */ public function setRange($x1, $x2, $y1, $y2) { $this->min = array('x' => $x1, 'y' => $y1); $this->max = array('x' => $x2, 'y' => $y2); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public * @abstract */ public abstract function drawLine($x1, $y1, $x2, $y2, $r, $g, $b); /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public * @abstract */ public abstract function saveImage($filename); /** * Shows the rendered image. * * @access public * @abstract */ public abstract function showImage(); } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Parser/E00.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Parser/E00.php +++ pear/Image_GIS2/GIS/Parser/E00.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: E00 Parser | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: E00.php,v 1.1 2004/04/17 10:21:28 sebastian Exp $ // require_once 'Image/GIS/LineSet.php'; require_once 'Image/GIS/Parser.php'; /** * E00 Parser. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_Parser_E00 extends Image_GIS_Parser { /** * Constructor. * * @param boolean $cache * @param boolean $debug * @access public */ public function Image_GIS_Parser_E00($cache, $debug) { $this->Image_GIS_Parser($cache, $debug); } /** * Parses a data file. * * @param string $dataFile * @param mixed $color * @return mixed * @access public */ public function parseFile($dataFile, $color) { $lineSet = new Image_GIS_LineSet($color); if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $lineNum = 0; while(0 || $line = fgets($fp, 1024)) { $lineNum++; if ($numRecords == 0 && preg_match("#^\s+([0-9]+)\s+([-0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)#", $line, $a)) { $numRecords = $a[7]; $pl['x'] = -1; $pl['y'] = -1; } else if ($numRecords && preg_match("#^[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) { if ($this->debug) { echo $a[0] . '<br />'; } if ($pl['x'] != -1 && $pl['y'] != -1) { $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); } $numRecords--; $lineSet->addLine($a[1], $a[2], $a[3], $a[4]); $pl['x'] = $a[3]; $pl['y'] = $a[4]; $numRecords--; } else if ($numRecords && 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) { $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); $pl['x'] = $a[1]; $pl['y'] = $a[2]; } $numRecords--; } else if ($lineNum > 2) { if ($this->debug) { printf( 'Died at: %s<br />', $lineNum ); } break; } else if ($this->debug) { echo $line . '<br />'; } } @fclose($fp); return $lineSet; } return false; } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Renderer/GD.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Renderer/GD.php +++ pear/Image_GIS2/GIS/Renderer/GD.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: GD Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: GD.php,v 1.1 2004/04/17 10:21:28 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; /** * GD Renderer. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_Renderer_GD extends Image_GIS_Renderer { /** * GD Image Ressource. * * @var ressource $image */ private $image; /** * GD Image Palette. * * @var array $palette */ private $palette = array(); /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ public function __construct($width, $height, $debug) { if (is_file($width)) { $this->image = imagecreatefrompng($width); $width = imagesx($this->image); $height = imagesy($this->image); } else { $this->image = imagecreate($this->width, $this->height); imagecolorallocate($this->image, 255, 255, 255); } $this->Image_GIS_Renderer($width, $height, $debug); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public */ public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { $this->palette[$r][$g][$b] = imagecolorallocate($this->image, $r, $g, $b); } imageline( $this->image, $x1, $y1, $x2, $y2, $this->palette[$r][$g][$b] ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { return imagepng($this->image, $filename); } /** * Shows the rendered image. * * @access public */ public function showImage() { header('Content-Type: image/png'); imagepng($this->image); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Renderer/SVG.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Renderer/SVG.php +++ pear/Image_GIS2/GIS/Renderer/SVG.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: SVG Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: SVG.php,v 1.1 2004/04/17 10:21:28 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; require_once 'XML/SVG.php'; /** * SVG Renderer. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_Renderer_SVG extends Image_GIS_Renderer { /** * SVG Document. * * @var XML_SVG $svg */ private $svg; /** * SVG Groups. * * @var XML_SVG_Group[] */ private $svgGroups = array(); /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ public function __construct($width, $height, $debug) { $this->Image_GIS_Renderer($width, $height, $debug); $this->svg = new XML_SVG_Document( array( 'width' => $width, 'height' => $height ) ); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public */ public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $group = md5($r . $g . $b); if (!isset($this->svgGroups[$group])) { $this->svgGroups[$group] = new XML_SVG_Group( array( 'style' => sprintf( 'stroke:rgb(%s, %s, %s)', $r, $g, $b ) ) ); $this->svgGroups[$group]->addParent($this->svg); } $line = new XML_SVG_Line( array( 'x1' => $x1, 'y1' => $y1, 'x2' => $x2, 'y2' => $y2, ) ); $this->svgGroups[$group]->addChild($line); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->svg->bufferObject()); @fclose($fp); return true; } return false; } /** * Shows the rendered image. * * @access public */ public function showImage() { $this->svg->printElement(); } } ?>
http://cvs.php.net/diff.php/pear/Image_GIS/GIS.php?r1=1.17&r2=1.18&ty=u Index: pear/Image_GIS/GIS.php diff -u pear/Image_GIS/GIS.php:1.17 pear/Image_GIS/GIS.php:1.18 --- pear/Image_GIS/GIS.php:1.17 Sat Apr 17 06:13:15 2004 +++ pear/Image_GIS/GIS.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GIS.php,v 1.17 2004/04/17 10:13:15 sebastian Exp $ +// $Id: GIS.php,v 1.18 2004/04/17 10:21:24 sebastian Exp $ // require_once 'Image/Color.php'; @@ -70,21 +70,21 @@ * * @var boolean $debug */ - private $debug; + var $debug; /** * Image_GIS_Parser sub-class object. * * @var Image_GIS_Parser $parser */ - private $parser; + var $parser; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ - private $renderer; + var $renderer; /** * Constructor. @@ -92,7 +92,7 @@ * @param array $parameters * @access public */ - public function Image_GIS($parameters = array()) { + function Image_GIS($parameters = array()) { $this->debug = isset($parameters['debug']) ? $parameters['debug'] : false; $this->setParser( @@ -128,7 +128,7 @@ * @return boolean * @access public */ - public function addDataFile($dataFile, $color) { + function addDataFile($dataFile, $color) { return $this->parser->addDataFile($dataFile, $color); } @@ -139,7 +139,7 @@ * @access public * @since Image_GIS 1.0.1 */ - public function getRange() { + function getRange() { return $this->renderer->getRange(); } @@ -148,7 +148,7 @@ * * @access public */ - public function render() { + function render() { $this->renderer->render($this->parser->parse()); } @@ -159,7 +159,7 @@ * @return boolean * @access public */ - public function saveImage($filename) { + function saveImage($filename) { $this->render(); return $this->renderer->saveImage($filename); @@ -173,8 +173,8 @@ * @param boolean $cache * @access public */ - public function setParser($parser, $cache) { - $this->parser = Image_GIS_Parser::factory($parser, $cache, $this->debug); + function setParser($parser, $cache) { + $this->parser = &Image_GIS_Parser::factory($parser, $cache, $this->debug); } /** @@ -186,7 +186,7 @@ * @param float $y2 * @access public */ - public function setRange($x1, $x2, $y1, $y2) { + function setRange($x1, $x2, $y1, $y2) { $this->renderer->setRange($x1, $x2, $y1, $y2); } @@ -197,8 +197,8 @@ * @param string $renderer * @access public */ - public function setRenderer($renderer, $width, $height) { - $this->renderer = Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); + function setRenderer($renderer, $width, $height) { + $this->renderer = &Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); } /** @@ -206,8 +206,9 @@ * * @access public */ - public function showImage() { + function showImage() { $this->render(); + $this->renderer->showImage(); } } http://cvs.php.net/diff.php/pear/Image_GIS/package.xml?r1=1.14&r2=1.15&ty=u Index: pear/Image_GIS/package.xml diff -u pear/Image_GIS/package.xml:1.14 pear/Image_GIS/package.xml:1.15 --- pear/Image_GIS/package.xml:1.14 Tue Mar 16 03:05:53 2004 +++ pear/Image_GIS/package.xml Sat Apr 17 06:21:24 2004 @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> - <name>Image_GIS2</name> + <name>Image_GIS</name> <summary>Visualization of GIS data.</summary> <description> Generating maps on demand can be a hard job as most often you don't @@ -28,14 +28,31 @@ </maintainers> <license>PHP License</license> <release> - <version>2.0.0</version> + <version>1.1.0</version> <state>stable</state> - <date>2004-MM-DD</date> + <date>2004-01-06</date> <notes> <![CDATA[ -* Refactored using PHP 5 syntax. ++ Added caching of parsed data files. + ++ Added getRange() method to the Image_GIS and Image_GIS_Renderer + classes. + +* Changed the Image_GIS constructor to accept an associative + parameter array as its only argument. + + Note: This breaks backwards compatibility. + +* The SVG renderer now uses the XML_SVG package instead of the + XML_Tree package. -! PHP 5.0.0 (or higher) is now required. +* Factored the handling of Line Sets out into a separate class. + +* Fixed handling of negative coordinates. + +* Fixed a bug that kept a debugging message from beeing printed. + +* Fixed incompatibilities with PHP 5. ]]> </notes> <filelist> @@ -67,35 +84,6 @@ </release> <changelog> <release> - <version>1.1.0</version> - <state>stable</state> - <date>2004-01-06</date> - <notes> -<![CDATA[ -+ Added caching of parsed data files. - -+ Added getRange() method to the Image_GIS and Image_GIS_Renderer - classes. - -* Changed the Image_GIS constructor to accept an associative - parameter array as its only argument. - - Note: This breaks backwards compatibility. - -* The SVG renderer now uses the XML_SVG package instead of the - XML_Tree package. - -* Factored the handling of Line Sets out into a separate class. - -* Fixed handling of negative coordinates. - -* Fixed a bug that kept a debugging message from beeing printed. - -* Fixed incompatibilities with PHP 5. -]]> - </notes> - </release> - <release> <version>1.0.0</version> <state>stable</state> <date>2002-12-30</date> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/LineSet.php?r1=1.4&r2=1.5&ty=u Index: pear/Image_GIS/GIS/LineSet.php diff -u pear/Image_GIS/GIS/LineSet.php:1.4 pear/Image_GIS/GIS/LineSet.php:1.5 --- pear/Image_GIS/GIS/LineSet.php:1.4 Sat Apr 17 06:13:16 2004 +++ pear/Image_GIS/GIS/LineSet.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: LineSet.php,v 1.4 2004/04/17 10:13:16 sebastian Exp $ +// $Id: LineSet.php,v 1.5 2004/04/17 10:21:24 sebastian Exp $ // /** @@ -29,17 +29,17 @@ /** * @var array $color */ - public $color = 'black'; + var $color = 'black'; /** * @var array $lines */ - public $lines = array(); + var $lines = array(); /** * @var array $min */ - public $min = array( + var $min = array( 'x' => 0, 'y' => 0 ); @@ -47,7 +47,7 @@ /** * @var array $max */ - public $max = array( + var $max = array( 'x' => 0, 'y' => 0 ); @@ -58,7 +58,7 @@ * @param string $color * @access public */ - public function Image_GIS_LineSet($color = 'black') { + function Image_GIS_LineSet($color = 'black') { $this->color = $color; } @@ -71,7 +71,7 @@ * @param float $y2 * @access public */ - public function addLine($x1, $y1, $x2, $y2) { + function addLine($x1, $y1, $x2, $y2) { $this->lines[] = array($x1, $y1, $x2, $y2); $this->min['x'] = min($this->min['x'], $x1, $x2); http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Parser.php?r1=1.12&r2=1.13&ty=u Index: pear/Image_GIS/GIS/Parser.php diff -u pear/Image_GIS/GIS/Parser.php:1.12 pear/Image_GIS/GIS/Parser.php:1.13 --- pear/Image_GIS/GIS/Parser.php:1.12 Sat Apr 17 06:13:17 2004 +++ pear/Image_GIS/GIS/Parser.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Parser.php,v 1.12 2004/04/17 10:13:17 sebastian Exp $ +// $Id: Parser.php,v 1.13 2004/04/17 10:21:24 sebastian Exp $ // require_once 'Cache/Lite.php'; @@ -28,34 +28,34 @@ * @category Image * @package Image_GIS */ -abstract class Image_GIS_Parser { +class Image_GIS_Parser { /** * Cache. * * @var Cache_Lite $cache */ - protected $cache = NULL; + var $cache = NULL; /** * Data Files. * * @var array $dataFiles */ - protected $dataFiles = array(); + var $dataFiles = array(); /** * Set to TRUE to enable debugging. * * @var boolean $debug */ - protected $debug; + var $debug; /** * Line Set. * * @var array $lineSets */ - protected $lineSets = array(); + var $lineSets = array(); /** * Constructor. @@ -64,7 +64,7 @@ * @param boolean $debug * @access public */ - public function Image_GIS_Parser($cache, $debug) { + function Image_GIS_Parser($cache, $debug) { if ($cache) { $this->cache = new Cache_Lite; } @@ -81,7 +81,7 @@ * @return object * @access public */ - public static function factory($parser, $cache, $debug) { + function &factory($parser, $cache, $debug) { include_once 'Image/GIS/Parser/' . $parser . '.php'; $class = 'Image_GIS_Parser_' . $parser; @@ -97,7 +97,7 @@ * @param mixed $color * @access public */ - public function addDataFile($dataFile, $color) { + function addDataFile($dataFile, $color) { $this->dataFiles[$dataFile] = $color; } @@ -107,7 +107,7 @@ * @access public * @return array */ - public function parse() { + function parse() { foreach ($this->dataFiles as $dataFile => $color) { $cacheID = md5($dataFile . '_' . $color); $lineSet = false; @@ -140,6 +140,6 @@ * @access public * @abstract */ - public abstract function parseFile($dataFile, $color); + function parseFile($dataFile, $color) { /* abstract */ } } ?> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Renderer.php?r1=1.11&r2=1.12&ty=u Index: pear/Image_GIS/GIS/Renderer.php diff -u pear/Image_GIS/GIS/Renderer.php:1.11 pear/Image_GIS/GIS/Renderer.php:1.12 --- pear/Image_GIS/GIS/Renderer.php:1.11 Sat Apr 17 06:13:17 2004 +++ pear/Image_GIS/GIS/Renderer.php Sat Apr 17 06:21:24 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: Renderer.php,v 1.11 2004/04/17 10:13:17 sebastian Exp $ +// $Id: Renderer.php,v 1.12 2004/04/17 10:21:24 sebastian Exp $ // require_once 'Image/Color.php'; @@ -29,37 +29,37 @@ * @package Image_GIS * @abstract */ -abstract class Image_GIS_Renderer { +class Image_GIS_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ - protected $debug; + var $debug; /** * @var array $min */ - protected $min = false; + var $min = false; /** * @var array $max */ - protected $max = false; + var $max = false; /** * Width of the image. * * @var integer $width */ - protected $width; + var $width; /** * Height of the image. * * @var integer $height */ - protected $height; + var $height; /** * Constructor. @@ -69,7 +69,7 @@ * @param boolean $debug * @access public */ - public function Image_GIS_Renderer($width, $height, $debug) { + function Image_GIS_Renderer($width, $height, $debug) { $this->debug = $debug; if ($width < 0 || @@ -96,7 +96,7 @@ * @return object * @access public */ - public static function factory($renderer, $width, $height, $debug) { + function &factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS_Renderer_' . $renderer; $object = new $class($width, $height, $debug); @@ -116,7 +116,7 @@ * @param mixed $color * @access public */ - public function drawClippedLine($x1, $y1, $x2, $y2, $color) { + function drawClippedLine($x1, $y1, $x2, $y2, $color) { if (($x1 > $this->max['x'] || $x1 < $this->min['x'] || $y1 > $this->max['y'] || @@ -156,7 +156,7 @@ * @access public * @since Image_GIS 1.0.1 */ - public function getRange() { + function getRange() { return array( $this->min['x'], $this->max['x'], @@ -172,7 +172,7 @@ * @param string $direction * @access public */ - public function polar2image($polarCoordinate, $direction) { + function polar2image($polarCoordinate, $direction) { switch ($direction) { case 'x': { return ($polarCoordinate - $this->min[$direction]) * @@ -194,7 +194,7 @@ * @param array $lineSets * @access public */ - public function render($lineSets) { + function render($lineSets) { if ($this->min == false || $this->max == false) { $this->min = array( 'x' => 0, @@ -230,7 +230,7 @@ * @param float $y2 * @access public */ - public function setRange($x1, $x2, $y1, $y2) { + function setRange($x1, $x2, $y1, $y2) { $this->min = array('x' => $x1, 'y' => $y1); $this->max = array('x' => $x2, 'y' => $y2); } @@ -249,7 +249,7 @@ * @access public * @abstract */ - public abstract function drawLine($x1, $y1, $x2, $y2, $r, $g, $b); + function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { /* abstract */ } /** * Saves the rendered image to a given file. @@ -259,7 +259,7 @@ * @access public * @abstract */ - public abstract function saveImage($filename); + function saveImage($filename) { /* abstract */ } /** * Shows the rendered image. @@ -267,6 +267,6 @@ * @access public * @abstract */ - public abstract function showImage(); + function showImage() { /* abstract */ } } ?> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Parser/E00.php?r1=1.11&r2=1.12&ty=u Index: pear/Image_GIS/GIS/Parser/E00.php diff -u pear/Image_GIS/GIS/Parser/E00.php:1.11 pear/Image_GIS/GIS/Parser/E00.php:1.12 --- pear/Image_GIS/GIS/Parser/E00.php:1.11 Sat Apr 17 06:13:17 2004 +++ pear/Image_GIS/GIS/Parser/E00.php Sat Apr 17 06:21:25 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: E00.php,v 1.11 2004/04/17 10:13:17 sebastian Exp $ +// $Id: E00.php,v 1.12 2004/04/17 10:21:25 sebastian Exp $ // require_once 'Image/GIS/LineSet.php'; @@ -37,7 +37,7 @@ * @param boolean $debug * @access public */ - public function Image_GIS_Parser_E00($cache, $debug) { + function Image_GIS_Parser_E00($cache, $debug) { $this->Image_GIS_Parser($cache, $debug); } @@ -49,15 +49,15 @@ * @return mixed * @access public */ - public function parseFile($dataFile, $color) { + function parseFile($dataFile, $color) { $lineSet = new Image_GIS_LineSet($color); if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; - $lineNum = 0; + $ln = 0; while(0 || $line = fgets($fp, 1024)) { - $lineNum++; + $ln ++; if ($numRecords == 0 && preg_match("#^\s+([0-9]+)\s+([-0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)#", $line, $a)) { @@ -101,13 +101,13 @@ $numRecords--; } - else if ($lineNum > 2) { - if ($this->debug) { - printf( - 'Died at: %s<br />', - $lineNum - ); - } + else if ($ln > 2) { + if ($this->debug) { + printf( + 'Died at: %s<br />', + $ln + ); + } break; } http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Renderer/GD.php?r1=1.6&r2=1.7&ty=u Index: pear/Image_GIS/GIS/Renderer/GD.php diff -u pear/Image_GIS/GIS/Renderer/GD.php:1.6 pear/Image_GIS/GIS/Renderer/GD.php:1.7 --- pear/Image_GIS/GIS/Renderer/GD.php:1.6 Sat Apr 17 06:13:18 2004 +++ pear/Image_GIS/GIS/Renderer/GD.php Sat Apr 17 06:21:26 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: GD.php,v 1.6 2004/04/17 10:13:18 sebastian Exp $ +// $Id: GD.php,v 1.7 2004/04/17 10:21:26 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; @@ -30,18 +30,18 @@ */ class Image_GIS_Renderer_GD extends Image_GIS_Renderer { /** - * GD Image Ressource. + * GD Image Palette. * - * @var ressource $image + * @var array $palette */ - private $image; + var $palette = array(); /** - * GD Image Palette. + * GD Image Ressource. * - * @var array $palette + * @var ressource $img */ - private $palette = array(); + var $img; /** * Constructor. @@ -51,19 +51,19 @@ * @param boolean $debug * @access public */ - public function __construct($width, $height, $debug) { + function Image_GIS_Renderer_GD($width, $height, $debug) { if (is_file($width)) { - $this->image = imagecreatefrompng($width); + $this->img = imagecreatefrompng($width); + $width = imagesx($this->img); + $height = imagesy($this->img); - $width = imagesx($this->image); - $height = imagesy($this->image); + $this->Image_GIS_Renderer($width, $height, $debug); } else { - $this->image = imagecreate($this->width, $this->height); + $this->Image_GIS_Renderer($width, $height, $debug); - imagecolorallocate($this->image, 255, 255, 255); + $this->img = imagecreate($this->width, $this->height); + imagecolorallocate($this->img, 255, 255, 255); } - - $this->Image_GIS_Renderer($width, $height, $debug); } /** @@ -79,13 +79,13 @@ * @param float $b * @access public */ - public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { + function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { - $this->palette[$r][$g][$b] = imagecolorallocate($this->image, $r, $g, $b); + $this->palette[$r][$g][$b] = imagecolorallocate($this->img, $r, $g, $b); } imageline( - $this->image, + $this->img, $x1, $y1, $x2, @@ -101,8 +101,8 @@ * @return boolean * @access public */ - public function saveImage($filename) { - return imagepng($this->image, $filename); + function saveImage($filename) { + return imagepng($this->img, $filename); } /** @@ -110,9 +110,9 @@ * * @access public */ - public function showImage() { + function showImage() { header('Content-Type: image/png'); - imagepng($this->image); + imagepng($this->img); } } ?> http://cvs.php.net/diff.php/pear/Image_GIS/GIS/Renderer/SVG.php?r1=1.7&r2=1.8&ty=u Index: pear/Image_GIS/GIS/Renderer/SVG.php diff -u pear/Image_GIS/GIS/Renderer/SVG.php:1.7 pear/Image_GIS/GIS/Renderer/SVG.php:1.8 --- pear/Image_GIS/GIS/Renderer/SVG.php:1.7 Sat Apr 17 06:13:18 2004 +++ pear/Image_GIS/GIS/Renderer/SVG.php Sat Apr 17 06:21:26 2004 @@ -13,7 +13,7 @@ // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // -// $Id: SVG.php,v 1.7 2004/04/17 10:13:18 sebastian Exp $ +// $Id: SVG.php,v 1.8 2004/04/17 10:21:26 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; @@ -34,14 +34,14 @@ * * @var XML_SVG $svg */ - private $svg; + var $svg; /** * SVG Groups. * * @var XML_SVG_Group[] */ - private $svgGroups = array(); + var $svgGroups = array(); /** * Constructor. @@ -51,7 +51,7 @@ * @param boolean $debug * @access public */ - public function __construct($width, $height, $debug) { + function Image_GIS_Renderer_SVG($width, $height, $debug) { $this->Image_GIS_Renderer($width, $height, $debug); $this->svg = new XML_SVG_Document( @@ -75,7 +75,7 @@ * @param float $b * @access public */ - public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { + function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $group = md5($r . $g . $b); if (!isset($this->svgGroups[$group])) { @@ -113,7 +113,7 @@ * @return boolean * @access public */ - public function saveImage($filename) { + function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->svg->bufferObject()); @fclose($fp); @@ -129,7 +129,7 @@ * * @access public */ - public function showImage() { + function showImage() { $this->svg->printElement(); } } http://cvs.php.net/co.php/pear/Image_GIS2/GIS.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS.php +++ pear/Image_GIS2/GIS.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: GIS.php,v 1.1 2004/04/17 10:21:26 sebastian Exp $ // require_once 'Image/Color.php'; require_once 'Image/GIS/Parser.php'; require_once 'Image/GIS/Renderer.php'; /** * The following example draws the region around the * German city of Kiel which is Jan's home town: * * <code> * <?php * require_once 'Image/GIS.php'; * * // Create new map. * $map = new Image_GIS( * array( * 'width' => 960, * 'height' => 1280, * 'range' => array( * 'x1' => 9.7, * 'x2' => 10.5, * 'y1' => 54.2, * 'y2' => 54.7 * ) * ) * ); * * // Political * $map->addDataFile('germany_ponet.e00', 'black'); * * // Roads * $map->addDataFile('germany_rdline.e00', 'gray'); * * // Populated Places * $map->addDataFile('germany_pppoly.e00', 'green'); * * // Drainage * $map->addDataFile('germany_dnnet.e00', 'blue'); * * $map->saveImage('kiel.png'); * ?> * </code> * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ private $debug; /** * Image_GIS_Parser sub-class object. * * @var Image_GIS_Parser $parser */ private $parser; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ private $renderer; /** * Constructor. * * @param array $parameters * @access public */ public function Image_GIS($parameters = array()) { $this->debug = isset($parameters['debug']) ? $parameters['debug'] : false; $this->setParser( isset($parameters['parser']) ? $parameters['parser'] : 'E00', isset($parameters['cache']) ? $parameters['cache'] : false, isset($parameters['cacheDir']) ? $parameters['cacheDir'] : '/tmp' ); $this->setRenderer( isset($parameters['renderer']) ? $parameters['renderer'] : 'GD', isset($parameters['width']) ? $parameters['width'] : 640, isset($parameters['height']) ? $parameters['height'] : 480 ); if (isset($parameters['range']['x1']) && isset($parameters['range']['x2']) && isset($parameters['range']['y1']) && isset($parameters['range']['y2'])) { $this->setRange( $parameters['range']['x1'], $parameters['range']['x2'], $parameters['range']['y1'], $parameters['range']['y2'] ); } } /** * Adds a datafile to the map. * * @param string $dataFile * @param mixed $color * @return boolean * @access public */ public function addDataFile($dataFile, $color) { return $this->parser->addDataFile($dataFile, $color); } /** * Returns the range of the data to be rendered. * * @return array * @access public * @since Image_GIS 1.0.1 */ public function getRange() { return $this->renderer->getRange(); } /** * Renders the image. * * @access public */ public function render() { $this->renderer->render($this->parser->parse()); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { $this->render(); return $this->renderer->saveImage($filename); } /** * Sets the Image_GIS_Parser sub-class to be used * to parse a data file. * * @param string $parser * @param boolean $cache * @access public */ public function setParser($parser, $cache) { $this->parser = Image_GIS_Parser::factory($parser, $cache, $this->debug); } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access public */ public function setRange($x1, $x2, $y1, $y2) { $this->renderer->setRange($x1, $x2, $y1, $y2); } /** * Sets the Image_GIS_Renderer sub-class to be used * to render an image. * * @param string $renderer * @access public */ public function setRenderer($renderer, $width, $height) { $this->renderer = Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); } /** * Shows the rendered image. * * @access public */ public function showImage() { $this->render(); $this->renderer->showImage(); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/package.xml?r=1.1&p=1 Index: pear/Image_GIS2/package.xml +++ pear/Image_GIS2/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "http://pear.php.net/dtd/package-1.0"> <package version="1.0"> <name>Image_GIS2</name> <summary>Visualization of GIS data.</summary> <description> Generating maps on demand can be a hard job as most often you don't have the maps you need in digital form. But you can generate your own maps based on raw, digital data files which are available for free on the net. This package provides a parser for the most common format for geographical data, the Arcinfo/E00 format as well as renderers to produce images using GD or Scalable Vector Graphics (SVG). </description> <maintainers> <maintainer> <user>sebastian</user> <role>lead</role> <name>Sebastian Bergmann</name> <email>sb@sebastian-bergmann.de</email> </maintainer> <maintainer> <user>ostborn</user> <role>lead</role> <name>Jan Kneschke</name> <email>jan@kneschke.de</email> </maintainer> </maintainers> <license>PHP License</license> <release> <version>2.0.0</version> <state>stable</state> <date>2004-MM-DD</date> <notes> <![CDATA[ * Refactored using PHP 5 syntax. ! PHP 5.0.0 (or higher) is now required. ]]> </notes> <filelist> <dir name="/" baseinstalldir="Image"> <dir name="GIS"> <dir name="Parser"> <file role="php" name="E00.php"/> </dir> <dir name="Renderer"> <file role="php" name="GD.php"/> <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> <file role="php" name="GIS.php"/> </dir> </filelist> <deps> <dep type="ext" rel="has">gd</dep> <dep type="pkg" rel="has">Cache_Lite</dep> <dep type="pkg" rel="has">Image_Color</dep> <dep type="pkg" rel="has">XML_SVG</dep> </deps> </release> <changelog> <release> <version>1.1.0</version> <state>stable</state> <date>2004-01-06</date> <notes> <![CDATA[ + Added caching of parsed data files. + Added getRange() method to the Image_GIS and Image_GIS_Renderer classes. * Changed the Image_GIS constructor to accept an associative parameter array as its only argument. Note: This breaks backwards compatibility. * The SVG renderer now uses the XML_SVG package instead of the XML_Tree package. * Factored the handling of Line Sets out into a separate class. * Fixed handling of negative coordinates. * Fixed a bug that kept a debugging message from beeing printed. * Fixed incompatibilities with PHP 5. ]]> </notes> </release> <release> <version>1.0.0</version> <state>stable</state> <date>2002-12-30</date> <notes> <![CDATA[ * Initial release. ]]> </notes> </release> </changelog> </package> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/LineSet.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/LineSet.php +++ pear/Image_GIS2/GIS/LineSet.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Line Set | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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 2004/04/17 10:21:27 sebastian Exp $ // /** * A Set of Lines. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_LineSet { /** * @var array $color */ public $color = 'black'; /** * @var array $lines */ public $lines = array(); /** * @var array $min */ public $min = array( 'x' => 0, 'y' => 0 ); /** * @var array $max */ public $max = array( 'x' => 0, 'y' => 0 ); /** * Constructor. * * @param string $color * @access public */ 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 */ 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); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Parser.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Parser.php +++ pear/Image_GIS2/GIS/Parser.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Parser Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: Parser.php,v 1.1 2004/04/17 10:21:27 sebastian Exp $ // require_once 'Cache/Lite.php'; require_once 'Image/GIS/LineSet.php'; /** * Parser Base Class. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ abstract class Image_GIS_Parser { /** * Cache. * * @var Cache_Lite $cache */ protected $cache = NULL; /** * Data Files. * * @var array $dataFiles */ protected $dataFiles = array(); /** * Set to TRUE to enable debugging. * * @var boolean $debug */ protected $debug; /** * Line Set. * * @var array $lineSets */ protected $lineSets = array(); /** * Constructor. * * @param boolean $cache * @param boolean $debug * @access public */ public function Image_GIS_Parser($cache, $debug) { if ($cache) { $this->cache = new Cache_Lite; } $this->debug = $debug; } /** * Factory. * * @param string $parser * @param boolean $cache * @param boolean $debug * @return object * @access public */ public static function factory($parser, $cache, $debug) { include_once 'Image/GIS/Parser/' . $parser . '.php'; $class = 'Image_GIS_Parser_' . $parser; $object = new $class($cache, $debug); return $object; } /** * Adds a datafile to the map. * * @param string $dataFile * @param mixed $color * @access public */ public function addDataFile($dataFile, $color) { $this->dataFiles[$dataFile] = $color; } /** * Parses the data files of the map. * * @access public * @return array */ public function parse() { foreach ($this->dataFiles as $dataFile => $color) { $cacheID = md5($dataFile . '_' . $color); $lineSet = false; if (is_object($this->cache) && $lineSet = $this->cache->get($cacheID, 'Image_GIS')) { $lineSet = unserialize($lineSet); } if ($lineSet === false) { $lineSet = $this->parseFile($dataFile, $color); if (is_object($this->cache)) { $this->cache->save(serialize($lineSet), $cacheID, 'Image_GIS'); } } $this->lineSets[] = $lineSet; } return $this->lineSets; } /** * Parses a data file. * * @param string $dataFile * @param mixed $color * @return mixed * @access public * @abstract */ public abstract function parseFile($dataFile, $color); } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Renderer.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Renderer.php +++ pear/Image_GIS2/GIS/Renderer.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Renderer Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: Renderer.php,v 1.1 2004/04/17 10:21:27 sebastian Exp $ // require_once 'Image/Color.php'; /** * Renderer Base Class. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS * @abstract */ abstract class Image_GIS_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ protected $debug; /** * @var array $min */ protected $min = false; /** * @var array $max */ protected $max = false; /** * Width of the image. * * @var integer $width */ protected $width; /** * Height of the image. * * @var integer $height */ protected $height; /** * Constructor. * * @param mixed $width * @param integer $height * @param boolean $debug * @access public */ public function Image_GIS_Renderer($width, $height, $debug) { $this->debug = $debug; if ($width < 0 || $width > 2048) { $width = 640; } if ($height < 0 || $height > 2048) { $height = 480; } $this->width = $width; $this->height = $height; } /** * Factory. * * @param string $renderer * @param mixed $width * @param integer $height * @param boolean $debug * @return object * @access public */ public static function factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS_Renderer_' . $renderer; $object = new $class($width, $height, $debug); return $object; } } /** * Draws a clipped line from ($x1, $y1) to ($x2, $y2) * using $color. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param mixed $color * @access public */ public function drawClippedLine($x1, $y1, $x2, $y2, $color) { if (($x1 > $this->max['x'] || $x1 < $this->min['x'] || $y1 > $this->max['y'] || $y1 < $this->min['y']) && ($x2 > $this->max['x'] || $x2 < $this->min['x'] || $y2 > $this->max['y'] || $y2 < $this->min['y'])) { if ($this->debug) { printf('clipped x1: %d %d %d<br />', $x1, $this->min['x'], $this->max['x']); printf('clipped y1: %d %d %d<br />', $y1, $this->min['y'], $this->max['y']); printf('clipped x2: %d %d %d<br />', $x2, $this->min['x'], $this->max['x']); printf('clipped y2: %d %d %d<br />', $y2, $this->min['y'], $this->max['y']); } } else { if (!is_array($color)) { $color = Image_Color::namedColor2RGB($color); } $x1 = $this->polar2image($x1, 'x'); $y1 = $this->polar2image($y1, 'y'); $x2 = $this->polar2image($x2, 'x'); $y2 = $this->polar2image($y2, 'y'); if ($this->debug) { printf('Drawing line (%s, %s) -> (%s, %s)<br />', $x1, $y1, $x2, $y2); } $this->drawLine($x1, $y1, $x2, $y2, $color[0], $color[1], $color[2]); } } /** * Returns the range of the data to be rendered. * * @return array * @access public * @since Image_GIS 1.0.1 */ public function getRange() { return array( $this->min['x'], $this->max['x'], $this->min['y'], $this->max['y'] ); } /** * Converts a polar coordinate to an image coordinate. * * @param float $polarCoordinate * @param string $direction * @access public */ public function polar2image($polarCoordinate, $direction) { switch ($direction) { case 'x': { return ($polarCoordinate - $this->min[$direction]) * ($this->width / ($this->max[$direction] - $this->min[$direction])); } break; case 'y': { return ($polarCoordinate - $this->max[$direction]) * ($this->height / ($this->min[$direction] - $this->max[$direction])); } break; } } /** * Renders the image. * * @param array $lineSets * @access public */ public 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); } } } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access public */ public function setRange($x1, $x2, $y1, $y2) { $this->min = array('x' => $x1, 'y' => $y1); $this->max = array('x' => $x2, 'y' => $y2); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public * @abstract */ public abstract function drawLine($x1, $y1, $x2, $y2, $r, $g, $b); /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public * @abstract */ public abstract function saveImage($filename); /** * Shows the rendered image. * * @access public * @abstract */ public abstract function showImage(); } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Parser/E00.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Parser/E00.php +++ pear/Image_GIS2/GIS/Parser/E00.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: E00 Parser | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: E00.php,v 1.1 2004/04/17 10:21:28 sebastian Exp $ // require_once 'Image/GIS/LineSet.php'; require_once 'Image/GIS/Parser.php'; /** * E00 Parser. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_Parser_E00 extends Image_GIS_Parser { /** * Constructor. * * @param boolean $cache * @param boolean $debug * @access public */ public function Image_GIS_Parser_E00($cache, $debug) { $this->Image_GIS_Parser($cache, $debug); } /** * Parses a data file. * * @param string $dataFile * @param mixed $color * @return mixed * @access public */ public function parseFile($dataFile, $color) { $lineSet = new Image_GIS_LineSet($color); if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $lineNum = 0; while(0 || $line = fgets($fp, 1024)) { $lineNum++; if ($numRecords == 0 && preg_match("#^\s+([0-9]+)\s+([-0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+([0-9]+)#", $line, $a)) { $numRecords = $a[7]; $pl['x'] = -1; $pl['y'] = -1; } else if ($numRecords && preg_match("#^[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})[ -]([0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) { if ($this->debug) { echo $a[0] . '<br />'; } if ($pl['x'] != -1 && $pl['y'] != -1) { $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); } $numRecords--; $lineSet->addLine($a[1], $a[2], $a[3], $a[4]); $pl['x'] = $a[3]; $pl['y'] = $a[4]; $numRecords--; } else if ($numRecords && 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) { $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]); $pl['x'] = $a[1]; $pl['y'] = $a[2]; } $numRecords--; } else if ($lineNum > 2) { if ($this->debug) { printf( 'Died at: %s<br />', $lineNum ); } break; } else if ($this->debug) { echo $line . '<br />'; } } @fclose($fp); return $lineSet; } return false; } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Renderer/GD.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Renderer/GD.php +++ pear/Image_GIS2/GIS/Renderer/GD.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: GD Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: GD.php,v 1.1 2004/04/17 10:21:28 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; /** * GD Renderer. * * @author Jan Kneschke <jan@kneschke.de> * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_Renderer_GD extends Image_GIS_Renderer { /** * GD Image Ressource. * * @var ressource $image */ private $image; /** * GD Image Palette. * * @var array $palette */ private $palette = array(); /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ public function __construct($width, $height, $debug) { if (is_file($width)) { $this->image = imagecreatefrompng($width); $width = imagesx($this->image); $height = imagesy($this->image); } else { $this->image = imagecreate($this->width, $this->height); imagecolorallocate($this->image, 255, 255, 255); } $this->Image_GIS_Renderer($width, $height, $debug); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public */ public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { $this->palette[$r][$g][$b] = imagecolorallocate($this->image, $r, $g, $b); } imageline( $this->image, $x1, $y1, $x2, $y2, $this->palette[$r][$g][$b] ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { return imagepng($this->image, $filename); } /** * Shows the rendered image. * * @access public */ public function showImage() { header('Content-Type: image/png'); imagepng($this->image); } } ?> http://cvs.php.net/co.php/pear/Image_GIS2/GIS/Renderer/SVG.php?r=1.1&p=1 Index: pear/Image_GIS2/GIS/Renderer/SVG.php +++ pear/Image_GIS2/GIS/Renderer/SVG.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: SVG Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2004 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: SVG.php,v 1.1 2004/04/17 10:21:28 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; require_once 'XML/SVG.php'; /** * SVG Renderer. * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> * @copyright Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de> * @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0 * @category Image * @package Image_GIS */ class Image_GIS_Renderer_SVG extends Image_GIS_Renderer { /** * SVG Document. * * @var XML_SVG $svg */ private $svg; /** * SVG Groups. * * @var XML_SVG_Group[] */ private $svgGroups = array(); /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ public function __construct($width, $height, $debug) { $this->Image_GIS_Renderer($width, $height, $debug); $this->svg = new XML_SVG_Document( array( 'width' => $width, 'height' => $height ) ); } /** * Draws a line from ($x1, $y1) to ($x2, $y2) * using the color rgb($r, $g, $b). * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $r * @param float $g * @param float $b * @access public */ public function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $group = md5($r . $g . $b); if (!isset($this->svgGroups[$group])) { $this->svgGroups[$group] = new XML_SVG_Group( array( 'style' => sprintf( 'stroke:rgb(%s, %s, %s)', $r, $g, $b ) ) ); $this->svgGroups[$group]->addParent($this->svg); } $line = new XML_SVG_Line( array( 'x1' => $x1, 'y1' => $y1, 'x2' => $x2, 'y2' => $y2, ) ); $this->svgGroups[$group]->addChild($line); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ public function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->svg->bufferObject()); @fclose($fp); return true; } return false; } /** * Shows the rendered image. * * @access public */ public function showImage() { $this->svg->printElement(); } } ?>