You are here

function GeoGenerator::wkt_generate_linestring in Geofield 7.2

2 calls to GeoGenerator::wkt_generate_linestring()
GeoGenerator::wkt_generate_multilinestring in includes/GeoGenerator.php
GeoGenerator::wkt_generate_polygon in includes/GeoGenerator.php

File

includes/GeoGenerator.php, line 76
Helper class for generating random WKT/Geospatial data.

Class

GeoGenerator
@file Helper class for generating random WKT/Geospatial data.

Code

function wkt_generate_linestring($start = FALSE, $segments = FALSE) {
  $start = $start ? $start : $this
    ->random_point();
  $segments = $segments ? $segments : $this
    ->dd_generate(1, 5, TRUE);
  $points[] = $start[0] . ' ' . $start[1];

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