You are here

public function WKT::extractData in geoPHP 7

Same name and namespace in other branches
  1. 8 geoPHP/lib/adapters/WKT.class.php \WKT::extractData()

Extract geometry to a WKT string

Parameters

Geometry $geometry A Geometry object:

Return value

string

1 call to WKT::extractData()
WKT::write in geoPHP/lib/adapters/WKT.class.php
Serialize geometries into a WKT string.

File

geoPHP/lib/adapters/WKT.class.php, line 233

Class

WKT
WKT (Well Known Text) Adapter

Code

public function extractData($geometry) {
  $parts = array();
  switch ($geometry
    ->geometryType()) {
    case 'Point':
      return $geometry
        ->getX() . ' ' . $geometry
        ->getY();
    case 'LineString':
      foreach ($geometry
        ->getComponents() as $component) {
        $parts[] = $this
          ->extractData($component);
      }
      return implode(', ', $parts);
    case 'Polygon':
    case 'MultiPoint':
    case 'MultiLineString':
    case 'MultiPolygon':
      foreach ($geometry
        ->getComponents() as $component) {
        $parts[] = '(' . $this
          ->extractData($component) . ')';
      }
      return implode(', ', $parts);
    case 'GeometryCollection':
      foreach ($geometry
        ->getComponents() as $component) {
        $parts[] = strtoupper($component
          ->geometryType()) . ' (' . $this
          ->extractData($component) . ')';
      }
      return implode(', ', $parts);
  }
}