/[drupal]/contributions/modules/geo/includes/geo.wkb.inc
ViewVC logotype

Diff of /contributions/modules/geo/includes/geo.wkb.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.10, Thu Jun 18 01:24:11 2009 UTC revision 1.11, Wed Aug 5 02:57:39 2009 UTC
# Line 1  Line 1 
1  <?php // $Id: geo.wkb.inc,v 1.9 2009/06/01 17:17:54 vauxia Exp $  <?php // $Id: geo.wkb.inc,v 1.10 2009/06/18 01:24:11 vauxia Exp $
2    
3  function geo_wkb_types($key = NULL) {  function geo_wkb_types($key = NULL) {
4    $geo_types = array(    $geo_types = array(
# Line 14  function geo_wkb_types($key = NULL) { Line 14  function geo_wkb_types($key = NULL) {
14    return $geo_types;    return $geo_types;
15  }  }
16    
17  function _geo_wkb_get_data($wkb = NULL, $format = 'text', $fp = NULL, $type = NULL) {  function _geo_wkb_get_data($wkb = NULL, $format = 'text', $fp = NULL, $type = NULL, $byte_order = NULL) {
18      static $local_byte_order;
19      if (!isset($local_byte_order)) {
20        $local_byte_order = current(unpack('c', pack('S', 1)));
21      }
22    
23    $data = array();    $data = array();
24    
25    if (!$fp) {    if (!$fp) {
# Line 25  function _geo_wkb_get_data($wkb = NULL, Line 30  function _geo_wkb_get_data($wkb = NULL,
30      fseek($fp, 0);      fseek($fp, 0);
31    
32      // Fetch the byte order (0 = Big Endian, 1 = Little Endian) and geo type.      // Fetch the byte order (0 = Big Endian, 1 = Little Endian) and geo type.
33      $data = unpack('cbyte_order/Ltype', fread($fp, 5));      $data = unpack('cbyte_order', fread($fp, 1));
34        $byte_order = $data['byte_order'];
35        $data = array_merge($data, unpack(($byte_order ? 'Vtype' : 'Ntype'), fread($fp, 4)));
36    
37      // Set the geometry type      // Set the geometry type
38      $data['type'] = geo_wkb_types($data['type']);      $data['type'] = geo_wkb_types($data['type']);
# Line 38  function _geo_wkb_get_data($wkb = NULL, Line 45  function _geo_wkb_get_data($wkb = NULL,
45    switch($type) {    switch($type) {
46    
47      case 'point': // Contains x, y decimal values.      case 'point': // Contains x, y decimal values.
48        $data = array_merge($data, unpack('dx/dy', fread($fp, 16)));        $tmp = fread($fp, 16);
49          // Check whether the data's byte order matches the machine's byte order.
50          // If not, we need to reverse the data before PHP can unpack it.
51          if ($byte_order != $local_byte_order) {
52            $tmp = strrev(substr($tmp, 0, 8)) . strrev(substr($tmp, 8));
53          }
54          $data = array_merge($data, unpack('dx/dy', $tmp));
55        $data['value'] = $func($data);        $data['value'] = $func($data);
56        if (function_exists($post = $func .'_post')) $data = $post($data);        if (function_exists($post = $func .'_post')) $data = $post($data);
57        return $data;        return $data;
58    
59      case 'linestring': // Contains count * (point) values.      case 'linestring': // Contains count * (point) values.
60        $data['count'] = current(unpack('L', fread($fp, 4)));        $data['count'] = current(unpack(($byte_order ? 'V' : 'N'), fread($fp, 4)));
61        for ($i = 1; $i <= $data['count']; $i++) {        for ($i = 1; $i <= $data['count']; $i++) {
62          $point = geo_wkb_get_data(NULL, $format, $fp, 'point');          $point = _geo_wkb_get_data(NULL, $format, $fp, 'point', $byte_order);
63          $data['value'] = $func($point, $data['value']);          $data['value'] = $func($point, $data['value']);
64        }        }
65        if (function_exists($post = $func .'_post')) $data = $post($data);        if (function_exists($post = $func .'_post')) $data = $post($data);
66        return $data;        return $data;
67    
68      case 'polygon': // Contains count * (linestring) items.      case 'polygon': // Contains count * (linestring) items.
69        $data['count'] = current(unpack('L', fread($fp, 4)));        $data['count'] = current(unpack(($byte_order ? 'V' : 'N'), fread($fp, 4)));
70        for ($i = 1; $i <= $data['count']; $i++) {        for ($i = 1; $i <= $data['count']; $i++) {
71          $line = geo_wkb_get_data(NULL, $format, $fp, 'linestring');          $line = _geo_wkb_get_data(NULL, $format, $fp, 'linestring', $byte_order);
72          $data['value'] = $func($line, $data['value']);          $data['value'] = $func($line, $data['value']);
73        }        }
74        if (function_exists($post = $func .'_post')) $data = $post($data);        if (function_exists($post = $func .'_post')) $data = $post($data);

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

  ViewVC Help
Powered by ViewVC 1.1.2