You are here

public function GeoJSON::getArray in geoPHP 8

Same name and namespace in other branches
  1. 7 geoPHP/lib/adapters/GeoJSON.class.php \GeoJSON::getArray()
1 call to GeoJSON::getArray()
GeoJSON::write in geoPHP/lib/adapters/GeoJSON.class.php
Serializes an object into a geojson string

File

geoPHP/lib/adapters/GeoJSON.class.php, line 129

Class

GeoJSON
GeoJSON class : a geojson reader/writer.

Code

public function getArray($geometry) {
  if ($geometry
    ->getGeomType() == 'GeometryCollection') {
    $component_array = array();
    foreach ($geometry->components as $component) {
      $component_array[] = array(
        'type' => $component
          ->geometryType(),
        'coordinates' => $component
          ->asArray(),
      );
    }
    return array(
      'type' => 'GeometryCollection',
      'geometries' => $component_array,
    );
  }
  else {
    return array(
      'type' => $geometry
        ->getGeomType(),
      'coordinates' => $geometry
        ->asArray(),
    );
  }
}