home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / Image / GIS / Parser / E00.php
Encoding:
PHP Script  |  2008-07-02  |  4.1 KB  |  129 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: Image :: GIS :: E00 Parser                                     |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Jan Kneschke <jan@kneschke.de> and             |
  7. // |                         Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  8. // +------------------------------------------------------------------------+
  9. // | This source file is subject to version 3.00 of the PHP License,        |
  10. // | that is available at http://www.php.net/license/3_0.txt.               |
  11. // | If you did not receive a copy of the PHP license and are unable to     |
  12. // | obtain it through the world-wide-web, please send a note to            |
  13. // | license@php.net so we can mail you a copy immediately.                 |
  14. // +------------------------------------------------------------------------+
  15. //
  16. // $Id: E00.php,v 1.14 2004/07/25 13:56:29 sebastian Exp $
  17. //
  18.  
  19. require_once 'Image/GIS/LineSet.php';
  20. require_once 'Image/GIS/Parser.php';
  21.  
  22. /**
  23.  * E00 Parser.
  24.  *
  25.  * @author      Jan Kneschke <jan@kneschke.de>
  26.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @copyright   Copyright © 2002-2004 Jan Kneschke <jan@kneschke.de> and Sebastian Bergmann <sb@sebastian-bergmann.de>
  28.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  29.  * @category    Image
  30.  * @package     Image_GIS
  31.  */
  32. class Image_GIS_Parser_E00 extends Image_GIS_Parser {
  33.     /**
  34.     * Constructor.
  35.     *
  36.     * @param  boolean $cache
  37.     * @param  boolean $debug
  38.     * @access public
  39.     */
  40.     function Image_GIS_Parser_E00($cache, $debug) {
  41.         $this->Image_GIS_Parser($cache, $debug);
  42.     }
  43.  
  44.     /**
  45.     * Parses a data file.
  46.     *
  47.     * @param  string  $dataFile
  48.     * @param  mixed   $color
  49.     * @return mixed
  50.     * @access public
  51.     */
  52.     function parseFile($dataFile, $color) {
  53.         $lineSet = new Image_GIS_LineSet($color);
  54.  
  55.         if ($fp = @fopen($dataFile, 'r')) {
  56.             $numRecords = 0;
  57.             $ln         = 0;
  58.  
  59.             while(0 || $line = fgets($fp, 1024)) {
  60.                 $ln ++;
  61.  
  62.                 if ($numRecords == 0 && 
  63.                     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)) {
  64.                     $numRecords = $a[7];
  65.  
  66.                     $pl['x'] = -1;
  67.                     $pl['y'] = -1;
  68.                 }
  69.  
  70.                 else if ($numRecords &&
  71.                          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)) {
  72.                     if ($this->debug) {
  73.                         echo $a[0] . '<br />';
  74.                     }
  75.  
  76.                     if ($pl['x'] != -1 &&
  77.                         $pl['y'] != -1) {
  78.                         $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]);
  79.                     }
  80.  
  81.                     $numRecords--;
  82.  
  83.                     $lineSet->addLine($a[1], $a[2], $a[3], $a[4]);
  84.  
  85.                     $pl['x'] = $a[3];
  86.                     $pl['y'] = $a[4];
  87.  
  88.                     $numRecords--;
  89.                 }
  90.  
  91.                 else if ($numRecords &&
  92.                          preg_match("#^([ -][0-9]\.[0-9]{7}E[-+][0-9]{2})([ -][0-9]\.[0-9]{7}E[-+][0-9]{2})#", $line, $a)) {
  93.                     if ($pl['x'] != -1 &&
  94.                         $pl['y'] != -1) {
  95.                         $lineSet->addLine($pl['x'], $pl['y'], $a[1], $a[2]);
  96.  
  97.                         $pl['x'] = $a[1];
  98.                         $pl['y'] = $a[2];
  99.                     }
  100.  
  101.                     $numRecords--;
  102.                 }
  103.  
  104.                 else if ($ln > 2) {
  105.                     if ($this->debug) {
  106.                         printf(
  107.                           'Died at: %s<br />',
  108.                           $ln
  109.                         );
  110.                     }
  111.  
  112.                     break;
  113.                 }
  114.  
  115.                 else if ($this->debug) {
  116.                     echo $line . '<br />';
  117.                 }
  118.             }
  119.  
  120.             @fclose($fp);
  121.  
  122.             return $lineSet;
  123.         }
  124.  
  125.         return false;
  126.     }
  127. }
  128. ?>
  129.