You are here

function WKB::getGeometry in geoPHP 7

Same name and namespace in other branches
  1. 8 geoPHP/lib/adapters/WKB.class.php \WKB::getGeometry()
2 calls to WKB::getGeometry()
WKB::getMulti in geoPHP/lib/adapters/WKB.class.php
WKB::read in geoPHP/lib/adapters/WKB.class.php
Read WKB into geometry objects

File

geoPHP/lib/adapters/WKB.class.php, line 49

Class

WKB
PHP Geometry/WKB encoder/decoder

Code

function getGeometry(&$mem) {
  $base_info = unpack("corder/ctype/cz/cm/cs", fread($mem, 5));
  if ($base_info['order'] !== 1) {
    throw new Exception('Only NDR (little endian) SKB format is supported at the moment');
  }
  if ($base_info['z']) {
    $this->dimension++;
    $this->z = TRUE;
  }
  if ($base_info['m']) {
    $this->dimension++;
    $this->m = TRUE;
  }

  // If there is SRID information, ignore it - use EWKB Adapter to get SRID support
  if ($base_info['s']) {
    fread($mem, 4);
  }
  switch ($base_info['type']) {
    case 1:
      return $this
        ->getPoint($mem);
    case 2:
      return $this
        ->getLinstring($mem);
    case 3:
      return $this
        ->getPolygon($mem);
    case 4:
      return $this
        ->getMulti($mem, 'point');
    case 5:
      return $this
        ->getMulti($mem, 'line');
    case 6:
      return $this
        ->getMulti($mem, 'polygon');
    case 7:
      return $this
        ->getMulti($mem, 'geometry');
  }
}