You are here

protected function WktGenerator::generateLinestring in Geofield 8

Generates a linestring components array.

Parameters

array $start: The starting point. If not provided, will be randomly generated.

int $segments: Number of segments. If not provided, will be randomly generated.

Return value

array The linestring components coordinates.

3 calls to WktGenerator::generateLinestring()
WktGenerator::generateMultilinestring in src/WktGenerator.php
Generates a multilinestring coordinates.
WktGenerator::generatePolygon in src/WktGenerator.php
Generates a polygon components array.
WktGenerator::wktGenerateLinestring in src/WktGenerator.php
Returns a WKT format linestring feature.

File

src/WktGenerator.php, line 163

Class

WktGenerator
Helper class that generates WKT format geometries.

Namespace

Drupal\geofield

Code

protected function generateLinestring(array $start = NULL, $segments = NULL) {
  $start = $start ? $start : $this
    ->randomPoint();
  $segments = $segments ? $segments : $this
    ->ddGenerate(2, 5, TRUE);
  $points[] = [
    $start[0],
    $start[1],
  ];

  // Points are at most 1km away from each other.
  for ($i = 1; $i < $segments; $i += 1) {
    $diff = $this
      ->randomPoint();
    $start[0] += $diff[0] / 100;
    $start[1] += $diff[1] / 100;
    $points[] = [
      $start[0],
      $start[1],
    ];
  }
  return $points;
}