You are here

public function WKB::read in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/adapters/WKB.class.php \WKB::read()

Read WKB into geometry objects

Parameters

string $wkb: Well-known-binary string

bool $is_hex_string: If this is a hexedecimal string that is in need of packing

Return value

Geometry

Overrides GeoAdapter::read

1 method overrides WKB::read()
EWKB::read in geoPHP/lib/adapters/EWKB.class.php
Read WKB binary string into geometry objects

File

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

Class

WKB
PHP Geometry/WKB encoder/decoder

Code

public function read($wkb, $is_hex_string = FALSE) {
  if ($is_hex_string) {
    $wkb = pack('H*', $wkb);
  }
  if (empty($wkb)) {
    throw new Exception('Cannot read empty WKB geometry. Found ' . gettype($wkb));
  }
  $mem = fopen('php://memory', 'r+');
  fwrite($mem, $wkb);
  fseek($mem, 0);
  $geometry = $this
    ->getGeometry($mem);
  fclose($mem);
  return $geometry;
}