You are here

function WKB::getLinstring in geoPHP 7

Same name and namespace in other branches
  1. 8 geoPHP/lib/adapters/WKB.class.php \WKB::getLinstring()
2 calls to WKB::getLinstring()
WKB::getGeometry in geoPHP/lib/adapters/WKB.class.php
WKB::getPolygon in geoPHP/lib/adapters/WKB.class.php

File

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

Class

WKB
PHP Geometry/WKB encoder/decoder

Code

function getLinstring(&$mem) {

  // Get the number of points expected in this string out of the first 4 bytes
  $line_length = unpack('L', fread($mem, 4));

  // Return an empty linestring if there is no line-length
  if (!$line_length[1]) {
    return new LineString();
  }

  // Read the nubmer of points x2 (each point is two coords) into decimal-floats
  $line_coords = unpack('d*', fread($mem, $line_length[1] * $this->dimension * 8));

  // We have our coords, build up the linestring
  $components = array();
  $i = 1;
  $num_coords = count($line_coords);
  while ($i <= $num_coords) {
    $components[] = new Point($line_coords[$i], $line_coords[$i + 1]);
    $i += 2;
  }
  return new LineString($components);
}