You are here

static function geoPHP::load in geoPHP 7

Same name and namespace in other branches
  1. 8 geoPHP/geoPHP.inc \geoPHP::load()
12 calls to geoPHP::load()
AdaptersTests::testAdapters in geoPHP/tests/tests/adaptersTest.php
geoPHP::geosToGeometry in geoPHP/geoPHP.inc
GeosTests::testGeos in geoPHP/tests/tests/geosTest.php
MethodsTests::testMethods in geoPHP/tests/tests/methodsTest.php
MethodsTests::_methods_tester_with_geos in geoPHP/tests/tests/methodsTest.php

... See full list

File

geoPHP/geoPHP.inc, line 43

Class

geoPHP

Code

static function load() {
  $args = func_get_args();
  $data = array_shift($args);
  $type = array_shift($args);
  if (empty($data)) {
    return null;
  }
  $type_map = geoPHP::getAdapterMap();

  // Auto-detect type if needed
  if (!$type) {

    // If the user is trying to load a Geometry from a Geometry... Just pass it back
    if (is_object($data)) {
      if ($data instanceof Geometry) {
        return $data;
      }
    }
    $detected = geoPHP::detectFormat($data);
    if (!$detected) {
      return FALSE;
    }
    $format = explode(':', $detected);
    $type = array_shift($format);
    $args = $format;
  }
  $processor_type = $type_map[$type];
  if (!$processor_type) {
    throw new exception('geoPHP could not find an adapter of type ' . htmlentities($type));
    exit;
  }
  $processor = new $processor_type();

  // Data is not an array, just pass it normally
  if (!is_array($data)) {
    $result = call_user_func_array(array(
      $processor,
      "read",
    ), array_merge(array(
      $data,
    ), $args));
  }
  else {
    $geoms = array();
    foreach ($data as $item) {
      $geoms[] = call_user_func_array(array(
        $processor,
        "read",
      ), array_merge(array(
        $item,
      ), $args));
    }
    $result = geoPHP::geometryReduce($geoms);
  }
  return $result;
}