You are here

public function WktGenerator::wktGenerateGeometry in Geofield 8

Helper to generate a random WKT string.

Try to keeps values sane, no shape is more than 100km across.

Return value

string The random WKT value.

Overrides WktGeneratorInterface::wktGenerateGeometry

File

src/WktGenerator.php, line 39

Class

WktGenerator
Helper class that generates WKT format geometries.

Namespace

Drupal\geofield

Code

public function wktGenerateGeometry() {
  $types = [
    GEOFIELD_TYPE_POINT,
    GEOFIELD_TYPE_MULTIPOINT,
    GEOFIELD_TYPE_LINESTRING,
    GEOFIELD_TYPE_MULTILINESTRING,
    GEOFIELD_TYPE_POLYGON,
    GEOFIELD_TYPE_MULTIPOLYGON,
  ];

  // Don't always generate the same type.
  shuffle($types);
  $type = $types[0];
  $func = 'WktGenerate' . ucfirst($type);
  if (method_exists($this, $func)) {
    return $this
      ->{$func}();
  }
  return 'POINT (0 0)';
}