static function geoPHP::load in geoPHP 8
Same name and namespace in other branches
- 7 geoPHP/geoPHP.inc \geoPHP::load()
11 calls to geoPHP::load()
- AdaptersTests::testAdapters in geoPHP/
tests/ tests/ adaptersTest.php - AliasesTests::testAliases in geoPHP/
tests/ tests/ aliasesTest.php - geoPHP::geosToGeometry in geoPHP/
geoPHP.inc - GeosTests::testGeos in geoPHP/
tests/ tests/ geosTest.php - MethodsTests::testMethods in geoPHP/
tests/ tests/ methodsTest.php
File
- geoPHP/
geoPHP.inc, line 43
Class
Code
static function load() {
$args = func_get_args();
$data = array_shift($args);
$type = array_shift($args);
$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;
}