cvs: pear /Image_GIS Map.php Parser.php Renderer.php package.xml /Image_GIS/Parser E00.php /Image_GIS/Renderer GD.php SVG.php
| From: | Sebastian Bergmann | Date: | Mon, 30 Dec 2002 09:11:44 +0000 |
| Subject: | cvs: pear /Image_GIS Map.php Parser.php Renderer.php package.xml /Image_GIS/Parser E00.php /Image_GIS/Renderer GD.php SVG.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-7987@lists.php.net to get a copy of this message | ||
sebastian Mon Dec 30 04:11:44 2002 EDT
Added files:
/pear/Image_GIS Map.php Parser.php Renderer.php package.xml
/pear/Image_GIS/Parser E00.php
/pear/Image_GIS/Renderer GD.php SVG.php
Log:
Initial import of Image_GIS package per discussion on pear-dev (3 +1 votes ought to be enough :-).
Index: pear/Image_GIS/Map.php +++ pear/Image_GIS/Map.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Map.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/Color.php'; require_once 'Image/GIS/Parser.php'; require_once 'Image/GIS/Renderer.php'; /** * ... * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Map { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ var $debug; /** * Image_GIS_Parser sub-class object. * * @var Image_GIS_Parser $parser */ var $parser; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ var $renderer; /** * Constructor. * * @param mixed $width * @param integer $height * @param string $parser * @param string $renderer * @param boolean $debug * @access public */ function Image_GIS_Map($width, $height = -1, $parser = 'E00', $renderer = 'GD', $debug = false) { $this->debug = $debug; $this->setRenderer($renderer, $width, $height); $this->setParser($parser); $this->setRange(9, 11, 55, 54); } /** * Draws a datafile. * * @param string $dataFile * @param mixed $color * @return boolean * @access public */ function draw($dataFile, $color) { return $this->parser->draw($dataFile, $color); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ function saveImage($filename) { return $this->renderer->saveImage($filename); } /** * Sets the Image_GIS_Parser sub-class to be used * to parse a data file. * * @param string $parser * @access public */ function setParser($parser) { $this->parser = &Image_GIS_Parser::factory($parser, $this->renderer, $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 */ 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 */ function setRenderer($renderer, $width, $height) { $this->renderer = &Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); } /** * Shows the rendered image. * * @access public */ function showImage() { $this->renderer->showImage(); } } ?> Index: pear/Image_GIS/Parser.php +++ pear/Image_GIS/Parser.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Parser Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Parser.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // /** * Parser Base Class. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ var $debug; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ var $renderer; /** * Constructor. * * @param Image_GIS_Renderer $renderer * @param boolean $debug * @access public */ function Image_GIS_Parser(&$renderer, $debug) { $this->renderer = &$renderer; $this->debug = $debug; } /** * Factory. * * @param string $parser * @param Image_GIS_Renderer $renderer * @param boolean $debug * @return object * @access public */ function &factory($parser, &$renderer, $debug) { include_once 'Image/GIS/Parser/' . $parser . '.php'; $class = 'Image_GIS_Parser_' . $parser; return new $class($renderer, $debug); } } ?> Index: pear/Image_GIS/Renderer.php +++ pear/Image_GIS/Renderer.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Renderer Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Renderer.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/Color.php'; /** * Renderer Base Class. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ var $debug; /** * @var array $min */ var $min; /** * @var array $max */ var $max; /** * Width of the image. * * @var integer $width */ var $width; /** * Height of the image. * * @var integer $height */ var $height; /** * Constructor. * * @param mixed $width * @param integer $height * @param boolean $debug * @access public */ function Image_GIS_Renderer($width, $height, $debug) { if ($width < 0 || $width > 2048) { $width = 640; } if ($height < 0 || $height > 2048) { $height = 480; } $this->width = $width; $this->height = $height; $this->debug = $debug; } /** * Factory. * * @param string $renderer * @param mixed $width * @param integer $height * @param boolean $debug * @return object * @access public */ function &factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS_Renderer_' . $renderer; return new $class($width, $height, $debug); } } /** * 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 */ 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]); } } /** * Converts a polar coordinate to an image coordinate. * * @param float $polarCoordinate * @param string $direction * @access public */ function polar2image($polarCoordinate, $direction) { if ($direction == 'y') { return ($polarCoordinate - $this->max[$direction]) * ($this->height / ($this->min[$direction] - $this->max[$direction])); } else { return ($polarCoordinate - $this->min[$direction]) * ($this->width / ($this->max[$direction] - $this->min[$direction])); } } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access 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 */ function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { /* abstract */ } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public * @abstract */ function saveImage($filename) { /* abstract */ } /** * Shows the rendered image. * * @access public * @abstract */ function showImage() { /* abstract */ } } ?> Index: pear/Image_GIS/package.xml +++ pear/Image_GIS/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../package.dtd"> <package version="1.0"> <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 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>1.0.0</version> <state>stable</state> <date>2002-XX-XX</date> <notes> <![CDATA[ * Initial release. ]]> </notes> <filelist> <dir name="/" baseinstalldir="Image/GIS"> <dir name="Parser"> <file role="php" name="GD.php"/> <file role="php" name="SVG.php"/> </dir> <dir name="Renderer"> <file role="php" name="E00.php"/> </dir> <file role="php" name="Map.php"/> <file role="php" name="Parser.php"/> <file role="php" name="Renderer.php"/> </dir> </filelist> <deps> <dep type="ext" rel="has">gd</dep> <dep type="pkg" rel="has">Image_Color</dep> <dep type="pkg" rel="has">XML_Tree</dep> </deps> </release> </package> Index: pear/Image_GIS/Parser/E00.php +++ pear/Image_GIS/Parser/E00.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: E00 Parser | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: E00.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/GIS/Parser.php'; /** * E00 Parser. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser_E00 extends Image_GIS_Parser { /** * Constructor. * * @param Image_GIS_Renderer $renderer * @param boolean $debug * @access public */ function Image_GIS_Parser_E00(&$renderer, $debug) { $this->Image_GIS_Parser($renderer, $debug); } /** * Draws a datafile. * * @param string $dataFile * @param mixed $color * @return boolean * @access public */ function draw($dataFile, $color) { if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $ln = 0; while(0 || $line = fgets($fp, 1024)) { $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)) { $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) { $this->renderer->drawClippedLine($pl['x'], $pl['y'], $a[1], $a[2], $color); } $numRecords--; $this->renderer->drawClippedLine($a[1], $a[2], $a[3], $a[4], $color); $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) { $this->renderer->drawClippedLine($pl['x'], $pl['y'], $a[1], $a[2], $color); $pl['x'] = $a[1]; $pl['y'] = $a[2]; } $numRecords--; } else if ($this->debug && $ln > 2) { sprintf( 'Died at: %s<br />', $ln ); break; } else if ($this->debug) { echo $line . '<br />'; } } @fclose($fp); return true; } return false; } } ?> Index: pear/Image_GIS/Renderer/GD.php +++ pear/Image_GIS/Renderer/GD.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: GD Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: GD.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; /** * GD Renderer. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer_GD extends Image_GIS_Renderer { /** * GD Image Palette. * * @var array $palette */ var $palette = array(); /** * GD Image Ressource. * * @var ressource $img */ var $img; /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ function Image_GIS_Renderer_GD($width, $height, $debug) { if (is_file($width)) { $this->img = imagecreatefrompng($width); $width = imagesx($this->img); $height = imagesy($this->img); $this->Image_GIS_Renderer($width, $height, $debug); } else { $this->Image_GIS_Renderer($width, $height, $debug); $this->img = imagecreate($this->width, $this->height); imagecolorallocate($this->img, 255, 255, 255); } } /** * 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 */ function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { $this->palette[$r][$g][$b] = imagecolorallocate($this->img, $r, $g, $b); } imageline( $this->img, $x1, $y1, $x2, $y2, $this->palette[$r][$g][$b] ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ function saveImage($filename) { return imagepng($this->img, $filename); } /** * Shows the rendered image. * * @access public */ function showImage() { header('Content-Type: image/png'); imagepng($this->img); } } ?> Index: pear/Image_GIS/Renderer/SVG.php +++ pear/Image_GIS/Renderer/SVG.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: SVG Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: SVG.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; require_once 'XML/Tree.php'; /** * SVG Renderer. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer_SVG extends Image_GIS_Renderer { /** * SVG Document. * * @var XML_Tree $svg */ var $svg; /** * SVG Document Root. * * @var XML_Tree_Node $root */ var $root; /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ function Image_GIS_Renderer_SVG($width, $height, $debug) { $this->Image_GIS_Renderer($width, $height, $debug); $this->svg = new XML_Tree; $this->root = &$this->svg->addRoot( 'svg', '', array( 'width' => $this->width, 'height' => $this->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 */ function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $line = &$this->root->addChild( 'line', '', array( 'x1' => $x1, 'y1' => $y1, 'x2' => $x2, 'y2' => $y2, 'style' => sprintf( 'stroke:rgb(%s, %s, %s)', $r, $g, $b ) ) ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->root->get()); @fclose($fp); return true; } return false; } /** * Shows the rendered image. * * @access public */ function showImage() { header('Content-Type: image/svg+xml'); echo $this->root->get(); } } ?>
Index: pear/Image_GIS/Map.php +++ pear/Image_GIS/Map.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Map.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/Color.php'; require_once 'Image/GIS/Parser.php'; require_once 'Image/GIS/Renderer.php'; /** * ... * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Map { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ var $debug; /** * Image_GIS_Parser sub-class object. * * @var Image_GIS_Parser $parser */ var $parser; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ var $renderer; /** * Constructor. * * @param mixed $width * @param integer $height * @param string $parser * @param string $renderer * @param boolean $debug * @access public */ function Image_GIS_Map($width, $height = -1, $parser = 'E00', $renderer = 'GD', $debug = false) { $this->debug = $debug; $this->setRenderer($renderer, $width, $height); $this->setParser($parser); $this->setRange(9, 11, 55, 54); } /** * Draws a datafile. * * @param string $dataFile * @param mixed $color * @return boolean * @access public */ function draw($dataFile, $color) { return $this->parser->draw($dataFile, $color); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ function saveImage($filename) { return $this->renderer->saveImage($filename); } /** * Sets the Image_GIS_Parser sub-class to be used * to parse a data file. * * @param string $parser * @access public */ function setParser($parser) { $this->parser = &Image_GIS_Parser::factory($parser, $this->renderer, $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 */ 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 */ function setRenderer($renderer, $width, $height) { $this->renderer = &Image_GIS_Renderer::factory($renderer, $width, $height, $this->debug); } /** * Shows the rendered image. * * @access public */ function showImage() { $this->renderer->showImage(); } } ?> Index: pear/Image_GIS/Parser.php +++ pear/Image_GIS/Parser.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Parser Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Parser.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // /** * Parser Base Class. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ var $debug; /** * Image_GIS_Renderer sub-class object. * * @var Image_GIS_Renderer $renderer */ var $renderer; /** * Constructor. * * @param Image_GIS_Renderer $renderer * @param boolean $debug * @access public */ function Image_GIS_Parser(&$renderer, $debug) { $this->renderer = &$renderer; $this->debug = $debug; } /** * Factory. * * @param string $parser * @param Image_GIS_Renderer $renderer * @param boolean $debug * @return object * @access public */ function &factory($parser, &$renderer, $debug) { include_once 'Image/GIS/Parser/' . $parser . '.php'; $class = 'Image_GIS_Parser_' . $parser; return new $class($renderer, $debug); } } ?> Index: pear/Image_GIS/Renderer.php +++ pear/Image_GIS/Renderer.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: Renderer Base Class | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: Renderer.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/Color.php'; /** * Renderer Base Class. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer { /** * Set to TRUE to enable debugging. * * @var boolean $debug */ var $debug; /** * @var array $min */ var $min; /** * @var array $max */ var $max; /** * Width of the image. * * @var integer $width */ var $width; /** * Height of the image. * * @var integer $height */ var $height; /** * Constructor. * * @param mixed $width * @param integer $height * @param boolean $debug * @access public */ function Image_GIS_Renderer($width, $height, $debug) { if ($width < 0 || $width > 2048) { $width = 640; } if ($height < 0 || $height > 2048) { $height = 480; } $this->width = $width; $this->height = $height; $this->debug = $debug; } /** * Factory. * * @param string $renderer * @param mixed $width * @param integer $height * @param boolean $debug * @return object * @access public */ function &factory($renderer, $width, $height, $debug) { if (@include_once('Image/GIS/Renderer/' . $renderer . '.php')) { $class = 'Image_GIS_Renderer_' . $renderer; return new $class($width, $height, $debug); } } /** * 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 */ 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]); } } /** * Converts a polar coordinate to an image coordinate. * * @param float $polarCoordinate * @param string $direction * @access public */ function polar2image($polarCoordinate, $direction) { if ($direction == 'y') { return ($polarCoordinate - $this->max[$direction]) * ($this->height / ($this->min[$direction] - $this->max[$direction])); } else { return ($polarCoordinate - $this->min[$direction]) * ($this->width / ($this->max[$direction] - $this->min[$direction])); } } /** * Sets the range of the data to be rendered. * * @param float $x1 * @param float $x2 * @param float $y1 * @param float $y2 * @access 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 */ function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { /* abstract */ } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public * @abstract */ function saveImage($filename) { /* abstract */ } /** * Shows the rendered image. * * @access public * @abstract */ function showImage() { /* abstract */ } } ?> Index: pear/Image_GIS/package.xml +++ pear/Image_GIS/package.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE package SYSTEM "../package.dtd"> <package version="1.0"> <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 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>1.0.0</version> <state>stable</state> <date>2002-XX-XX</date> <notes> <![CDATA[ * Initial release. ]]> </notes> <filelist> <dir name="/" baseinstalldir="Image/GIS"> <dir name="Parser"> <file role="php" name="GD.php"/> <file role="php" name="SVG.php"/> </dir> <dir name="Renderer"> <file role="php" name="E00.php"/> </dir> <file role="php" name="Map.php"/> <file role="php" name="Parser.php"/> <file role="php" name="Renderer.php"/> </dir> </filelist> <deps> <dep type="ext" rel="has">gd</dep> <dep type="pkg" rel="has">Image_Color</dep> <dep type="pkg" rel="has">XML_Tree</dep> </deps> </release> </package> Index: pear/Image_GIS/Parser/E00.php +++ pear/Image_GIS/Parser/E00.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: E00 Parser | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: E00.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/GIS/Parser.php'; /** * E00 Parser. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Parser_E00 extends Image_GIS_Parser { /** * Constructor. * * @param Image_GIS_Renderer $renderer * @param boolean $debug * @access public */ function Image_GIS_Parser_E00(&$renderer, $debug) { $this->Image_GIS_Parser($renderer, $debug); } /** * Draws a datafile. * * @param string $dataFile * @param mixed $color * @return boolean * @access public */ function draw($dataFile, $color) { if ($fp = @fopen($dataFile, 'r')) { $numRecords = 0; $ln = 0; while(0 || $line = fgets($fp, 1024)) { $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)) { $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) { $this->renderer->drawClippedLine($pl['x'], $pl['y'], $a[1], $a[2], $color); } $numRecords--; $this->renderer->drawClippedLine($a[1], $a[2], $a[3], $a[4], $color); $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) { $this->renderer->drawClippedLine($pl['x'], $pl['y'], $a[1], $a[2], $color); $pl['x'] = $a[1]; $pl['y'] = $a[2]; } $numRecords--; } else if ($this->debug && $ln > 2) { sprintf( 'Died at: %s<br />', $ln ); break; } else if ($this->debug) { echo $line . '<br />'; } } @fclose($fp); return true; } return false; } } ?> Index: pear/Image_GIS/Renderer/GD.php +++ pear/Image_GIS/Renderer/GD.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: GD Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: GD.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; /** * GD Renderer. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer_GD extends Image_GIS_Renderer { /** * GD Image Palette. * * @var array $palette */ var $palette = array(); /** * GD Image Ressource. * * @var ressource $img */ var $img; /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ function Image_GIS_Renderer_GD($width, $height, $debug) { if (is_file($width)) { $this->img = imagecreatefrompng($width); $width = imagesx($this->img); $height = imagesy($this->img); $this->Image_GIS_Renderer($width, $height, $debug); } else { $this->Image_GIS_Renderer($width, $height, $debug); $this->img = imagecreate($this->width, $this->height); imagecolorallocate($this->img, 255, 255, 255); } } /** * 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 */ function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { if (!isset($this->palette[$r][$g][$b])) { $this->palette[$r][$g][$b] = imagecolorallocate($this->img, $r, $g, $b); } imageline( $this->img, $x1, $y1, $x2, $y2, $this->palette[$r][$g][$b] ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ function saveImage($filename) { return imagepng($this->img, $filename); } /** * Shows the rendered image. * * @access public */ function showImage() { header('Content-Type: image/png'); imagepng($this->img); } } ?> Index: pear/Image_GIS/Renderer/SVG.php +++ pear/Image_GIS/Renderer/SVG.php <?php // // +------------------------------------------------------------------------+ // | PEAR :: Image :: GIS :: SVG Renderer | // +------------------------------------------------------------------------+ // | Copyright (c) 2002-2003 Jan Kneschke <jan@kneschke.de> and | // | Sebastian Bergmann <sb@sebastian-bergmann.de>. | // +------------------------------------------------------------------------+ // | This source file is subject to version 3.00 of the PHP License, | // | that is available at http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +------------------------------------------------------------------------+ // // $Id: SVG.php,v 1.1 2002/12/30 09:11:44 sebastian Exp $ // require_once 'Image/GIS/Renderer.php'; require_once 'XML/Tree.php'; /** * SVG Renderer. * * @version $Revision: 1.1 $ * @since Image_GIS 1.0.0 */ class Image_GIS_Renderer_SVG extends Image_GIS_Renderer { /** * SVG Document. * * @var XML_Tree $svg */ var $svg; /** * SVG Document Root. * * @var XML_Tree_Node $root */ var $root; /** * Constructor. * * @param mixed $width * @param integer $sizyY * @param boolean $debug * @access public */ function Image_GIS_Renderer_SVG($width, $height, $debug) { $this->Image_GIS_Renderer($width, $height, $debug); $this->svg = new XML_Tree; $this->root = &$this->svg->addRoot( 'svg', '', array( 'width' => $this->width, 'height' => $this->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 */ function drawLine($x1, $y1, $x2, $y2, $r, $g, $b) { $line = &$this->root->addChild( 'line', '', array( 'x1' => $x1, 'y1' => $y1, 'x2' => $x2, 'y2' => $y2, 'style' => sprintf( 'stroke:rgb(%s, %s, %s)', $r, $g, $b ) ) ); } /** * Saves the rendered image to a given file. * * @param string $filename * @return boolean * @access public */ function saveImage($filename) { if ($fp = @fopen($filename, 'w')) { @fputs($fp, $this->root->get()); @fclose($fp); return true; } return false; } /** * Shows the rendered image. * * @access public */ function showImage() { header('Content-Type: image/svg+xml'); echo $this->root->get(); } } ?>